Skip to content

Commit

Permalink
[WIP] Multi key type support
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahbx authored and lukas-bednar committed May 25, 2022
1 parent 0314e8b commit db72e06
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions rrmngmnt/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def __init__(self, executor, timeout=None):
self._ssh = paramiko.SSHClient()
self._ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
if isinstance(self._executor.user, UserWithPKey):
self.pkey = paramiko.RSAKey.from_private_key_file(
self._executor.user.private_key
self.pkey = self._get_pkey(
filename=self._executor.user.private_key
)
elif self._executor.use_pkey:
self.pkey = paramiko.RSAKey.from_private_key_file(
os.getenv(
self.pkey = self._get_pkey(
filename=os.getenv(
"HOST_SSH_KEY", ID_RSA_PRV % os.path.expanduser('~')
)
)
Expand Down Expand Up @@ -148,6 +148,21 @@ def open_file(self, path, mode='r', bufsize=-1):
) as fh:
yield fh

@staticmethod
def _get_pkey(filename):
errors = []
for key_type in (
paramiko.RSAKey,
paramiko.ECDSAKey,
paramiko.Ed25519Key,
):
try:
return key_type.from_private_key_file(filename=filename)
except paramiko.ssh_exception.SSHException as exp:
errors.append(str(exp))
continue
raise paramiko.ssh_exception.SSHException(f"Invalid Key {errors}")

class Command(Executor.Command):
"""
This class holds all data related to command execution.
Expand Down

0 comments on commit db72e06

Please sign in to comment.