ssh: change order of user configuration

Unfortunately this breaks backward compatibility, but we have to do it,
because current order is totally wrong. Configuring user with `dvc
remote modify myssh user` is an explicit action and should have higher
priority than implicit url. This is also important, since in the next
patch in this PR we will introduce support for `port` configuration,
that should also follow the same logic.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2019-01-08 10:12:43 +02:00
parent 3e8fa8014d
commit 5d381da5d9
2 changed files with 27 additions and 4 deletions
+3 -4
View File
@@ -60,10 +60,9 @@ class RemoteSSH(RemoteBase):
super(RemoteSSH, self).__init__(project, config)
self.url = config.get(Config.SECTION_REMOTE_URL, '/')
self.host = self.group('host')
self.user = self.group('user')
if not self.user:
self.user = config.get(Config.SECTION_REMOTE_USER,
getpass.getuser())
self.user = (config.get(Config.SECTION_REMOTE_USER)
or self.group('user')
or getpass.getuser())
self.prefix = self.group('path')
self.port = config.get(Config.SECTION_REMOTE_PORT, self.DEFAULT_PORT)
self.keyfile = config.get(Config.SECTION_REMOTE_KEY_FILE, None)
+24
View File
@@ -0,0 +1,24 @@
import getpass
from unittest import TestCase
from dvc.remote.ssh import RemoteSSH
class TestRemoteSSH(TestCase):
def test_user(self):
url = 'ssh://127.0.0.1:/path/to/dir'
config = {'url': url}
remote = RemoteSSH(None, config)
self.assertEqual(remote.user, getpass.getuser())
user = 'test1'
url = 'ssh://{}@127.0.0.1:/path/to/dir'.format(user)
config = {'url': url}
remote = RemoteSSH(None, config)
self.assertEqual(remote.user, user)
user = 'test2'
config['user'] = user
remote = RemoteSSH(None, config)
self.assertEqual(remote.user, user)