libkas: Remove config/context parameters from ssh functions
We can obtain the global context now. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
52fdc4f4ae
commit
448107781e
@ -124,8 +124,8 @@ class SetupSSHAgent(Command):
|
|||||||
return 'setup_ssh_agent'
|
return 'setup_ssh_agent'
|
||||||
|
|
||||||
def execute(self, ctx):
|
def execute(self, ctx):
|
||||||
ssh_setup_agent(ctx)
|
ssh_setup_agent()
|
||||||
ssh_no_host_key_check(ctx)
|
ssh_no_host_key_check()
|
||||||
|
|
||||||
|
|
||||||
class CleanupSSHAgent(Command):
|
class CleanupSSHAgent(Command):
|
||||||
@ -137,7 +137,7 @@ class CleanupSSHAgent(Command):
|
|||||||
return 'cleanup_ssh_agent'
|
return 'cleanup_ssh_agent'
|
||||||
|
|
||||||
def execute(self, ctx):
|
def execute(self, ctx):
|
||||||
ssh_cleanup_agent(ctx)
|
ssh_cleanup_agent()
|
||||||
|
|
||||||
|
|
||||||
class SetupEnviron(Command):
|
class SetupEnviron(Command):
|
||||||
|
@ -294,44 +294,46 @@ def ssh_add_key(env, key):
|
|||||||
logging.error('failed to add ssh key: %s', error)
|
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
|
Removes the identities and stop the ssh-agent instance
|
||||||
"""
|
"""
|
||||||
|
env = get_context().environ
|
||||||
# remove the identities
|
# remove the identities
|
||||||
process = Popen(['ssh-add', '-D'], env=config.environ)
|
process = Popen(['ssh-add', '-D'], env=env)
|
||||||
process.wait()
|
process.wait()
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
logging.error('failed to delete SSH identities')
|
logging.error('failed to delete SSH identities')
|
||||||
|
|
||||||
# stop the ssh-agent
|
# stop the ssh-agent
|
||||||
process = Popen(['ssh-agent', '-k'], env=config.environ)
|
process = Popen(['ssh-agent', '-k'], env=env)
|
||||||
process.wait()
|
process.wait()
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
logging.error('failed to stop SSH agent')
|
logging.error('failed to stop SSH agent')
|
||||||
|
|
||||||
|
|
||||||
def ssh_setup_agent(config, envkeys=None):
|
def ssh_setup_agent(envkeys=None):
|
||||||
"""
|
"""
|
||||||
Starts the ssh-agent
|
Starts the ssh-agent
|
||||||
"""
|
"""
|
||||||
|
env = get_context().environ
|
||||||
envkeys = envkeys or ['SSH_PRIVATE_KEY']
|
envkeys = envkeys or ['SSH_PRIVATE_KEY']
|
||||||
output = os.popen('ssh-agent -s').readlines()
|
output = os.popen('ssh-agent -s').readlines()
|
||||||
for line in output:
|
for line in output:
|
||||||
matches = re.search(r"(\S+)\=(\S+)\;", line)
|
matches = re.search(r"(\S+)\=(\S+)\;", line)
|
||||||
if matches:
|
if matches:
|
||||||
config.environ[matches.group(1)] = matches.group(2)
|
env[matches.group(1)] = matches.group(2)
|
||||||
|
|
||||||
for envkey in envkeys:
|
for envkey in envkeys:
|
||||||
key = os.environ.get(envkey)
|
key = os.environ.get(envkey)
|
||||||
if key:
|
if key:
|
||||||
logging.info("adding SSH key")
|
logging.info("adding SSH key")
|
||||||
ssh_add_key(config.environ, key)
|
ssh_add_key(env, key)
|
||||||
else:
|
else:
|
||||||
logging.warning('%s is missing', envkey)
|
logging.warning('%s is missing', envkey)
|
||||||
|
|
||||||
|
|
||||||
def ssh_no_host_key_check(_):
|
def ssh_no_host_key_check():
|
||||||
"""
|
"""
|
||||||
Disables ssh host key check
|
Disables ssh host key check
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user