From 169e787c32a408f917d4890e29db066841b3a711 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Sun, 18 Jan 2015 20:13:28 +0100 Subject: [PATCH] Patching identity for gateway in sshfuncs. Patch provided by Damien Saucez --- src/nepi/util/sshfuncs.py | 41 ++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/nepi/util/sshfuncs.py b/src/nepi/util/sshfuncs.py index 451a7b4f..33e1e108 100644 --- a/src/nepi/util/sshfuncs.py +++ b/src/nepi/util/sshfuncs.py @@ -251,10 +251,7 @@ def rexec(command, host, user, args.extend(['-o', 'StrictHostKeyChecking=no']) if gw: - if gwuser: - proxycommand = 'ProxyCommand=ssh -q %s@%s -W %%h:%%p' % (gwuser, gw) - else: - proxycommand = 'ProxyCommand=ssh -q %%r@%s -W %%h:%%p' % gw + proxycommand = _proxy_command(gw, gwuser, identity) args.extend(['-o', proxycommand]) if agent: @@ -346,10 +343,7 @@ def rcopy(source, dest, args.append('-P%d' % port) if gw: - if gwuser: - proxycommand = 'ProxyCommand=ssh -q %s@%s -W %%h:%%p' % (gwuser, gw) - else: - proxycommand = 'ProxyCommand=ssh -q %%r@%s -W %%h:%%p' % gw + proxycommand = _proxy_command(gw, gwuser, identity) args.extend(['-o', proxycommand]) if recursive: @@ -440,7 +434,7 @@ def rspawn(command, pidfile, :param sudo: Flag forcing execution with sudo user :type sudo: bool - :rtype: touple + :rtype: tuple (stdout, stderr), process @@ -856,4 +850,33 @@ def _communicate(proc, input, timeout=None, err_on_timeout=True): proc.wait() return (stdout, stderr) +def _proxy_command(gw, gwuser, gwidentity): + """ + Constructs the SSH ProxyCommand option to add to the SSH command to connect + via a proxy + :param gw: SSH proxy hostname + :type gw: str + + :param gwuser: SSH proxy username + :type gwuser: str + + :param gwidentity: SSH proxy identity file + :type gwidentity: str + + + :rtype: str + + returns the SSH ProxyCommand option. + """ + + proxycommand = 'ProxyCommand=ssh -q ' + if gwidentity: + proxycommand += '-i %s ' % os.path.expanduser(gwidentity) + if gwuser: + proxycommand += '%s' % gwuser + else: + proxycommand += '%r' + proxycommand += '@%s -W %%h:%%p' % gw + + return proxycommand -- 2.43.0