From ce9633458768511177f1d5b762ffaba0b673425a Mon Sep 17 00:00:00 2001 From: khamutov Date: Sun, 5 May 2019 13:20:28 +0300 Subject: [PATCH] extract ssh config parsing --- dvc/remote/ssh/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index 0a827160a..e58fec2a9 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -40,14 +40,7 @@ class RemoteSSH(RemoteBase): parsed = urlparse(self.url) self.host = parsed.hostname - user_config_file = os.path.expanduser("~/.ssh/config") - user_ssh_config = dict() - if self.host: - if os.path.exists(user_config_file): - with open(user_config_file) as f: - ssh_config = paramiko.SSHConfig() - ssh_config.parse(f) - user_ssh_config = ssh_config.lookup(self.host) + user_ssh_config = self._load_user_ssh_config(self.host) self.user = ( config.get(Config.SECTION_REMOTE_USER) @@ -76,6 +69,17 @@ class RemoteSSH(RemoteBase): "port": self.port, } + @staticmethod + def _load_user_ssh_config(hostname): + user_config_file = os.path.expanduser("~/.ssh/config") + user_ssh_config = dict() + if hostname and os.path.exists(user_config_file): + with open(user_config_file) as f: + ssh_config = paramiko.SSHConfig() + ssh_config.parse(f) + user_ssh_config = ssh_config.lookup(hostname) + return user_ssh_config + def ssh(self, host=None, user=None, port=None, **kwargs): logger.debug( "Establishing ssh connection with '{host}' "