mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
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:
+3
-4
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user