From 448107781e275b470f8d3d712f636bffc9323bd1 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Fri, 24 Aug 2018 19:18:04 +0200 Subject: [PATCH] libkas: Remove config/context parameters from ssh functions We can obtain the global context now. Signed-off-by: Jan Kiszka --- kas/libcmds.py | 6 +++--- kas/libkas.py | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/kas/libcmds.py b/kas/libcmds.py index 453bc49..3123c18 100644 --- a/kas/libcmds.py +++ b/kas/libcmds.py @@ -124,8 +124,8 @@ class SetupSSHAgent(Command): return 'setup_ssh_agent' def execute(self, ctx): - ssh_setup_agent(ctx) - ssh_no_host_key_check(ctx) + ssh_setup_agent() + ssh_no_host_key_check() class CleanupSSHAgent(Command): @@ -137,7 +137,7 @@ class CleanupSSHAgent(Command): return 'cleanup_ssh_agent' def execute(self, ctx): - ssh_cleanup_agent(ctx) + ssh_cleanup_agent() class SetupEnviron(Command): diff --git a/kas/libkas.py b/kas/libkas.py index b651d77..3b3733e 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -294,44 +294,46 @@ def ssh_add_key(env, key): logging.error('failed to add ssh key: %s', error) -def ssh_cleanup_agent(config): +def ssh_cleanup_agent(): """ Removes the identities and stop the ssh-agent instance """ + env = get_context().environ # remove the identities - process = Popen(['ssh-add', '-D'], env=config.environ) + process = Popen(['ssh-add', '-D'], env=env) process.wait() if process.returncode != 0: logging.error('failed to delete SSH identities') # stop the ssh-agent - process = Popen(['ssh-agent', '-k'], env=config.environ) + process = Popen(['ssh-agent', '-k'], env=env) process.wait() if process.returncode != 0: logging.error('failed to stop SSH agent') -def ssh_setup_agent(config, envkeys=None): +def ssh_setup_agent(envkeys=None): """ Starts the ssh-agent """ + env = get_context().environ envkeys = envkeys or ['SSH_PRIVATE_KEY'] output = os.popen('ssh-agent -s').readlines() for line in output: matches = re.search(r"(\S+)\=(\S+)\;", line) if matches: - config.environ[matches.group(1)] = matches.group(2) + env[matches.group(1)] = matches.group(2) for envkey in envkeys: key = os.environ.get(envkey) if key: logging.info("adding SSH key") - ssh_add_key(config.environ, key) + ssh_add_key(env, key) else: logging.warning('%s is missing', envkey) -def ssh_no_host_key_check(_): +def ssh_no_host_key_check(): """ Disables ssh host key check """