From 2cd69aa400c922aa26ee92e680913f7386e356d2 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Fri, 19 Apr 2024 11:03:05 +0200 Subject: [PATCH] Move prepending '~/.ssh' to the ssh key path from SignatureAuthHandler.ssh_sign() to __init__() --- osc/connection.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osc/connection.py b/osc/connection.py index 8d2f9d1c..6a844b4c 100644 --- a/osc/connection.py +++ b/osc/connection.py @@ -568,6 +568,12 @@ class SignatureAuthHandler(AuthHandlerBase): self.user = user self.sshkey = sshkey + if self.sshkey: + # if only a file name is provided, prepend ~/.ssh + if "/" not in self.sshkey: + self.sshkey = os.path.join("~", ".ssh", self.sshkey) + self.sshkey = os.path.expanduser(self.sshkey) + self.ssh_keygen_path = shutil.which("ssh-keygen") self.ssh_add_path = shutil.which("ssh-add") @@ -612,11 +618,6 @@ class SignatureAuthHandler(AuthHandlerBase): def ssh_sign(self, data, namespace, keyfile=None): if not keyfile: keyfile = self.guess_keyfile() - else: - if '/' not in keyfile: - keyfile = f"~/.ssh/{keyfile}" - keyfile = os.path.expanduser(keyfile) - cmd = [self.ssh_keygen_path, '-Y', 'sign', '-f', keyfile, '-n', namespace, '-q'] proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding="utf-8") signature, _ = proc.communicate(data)