diff options
author | Steve Weber <steverweber@gmail.com> | 2022-01-28 13:24:55 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 12:24:55 -0600 |
commit | c4e21c7278e839de6bb7fb9c5e34ea5a6114029f (patch) | |
tree | b5dd76f4e5e9734eb31c8ad5d31c201b1a99c9f8 /cloudinit | |
parent | 823a83bad1df0c13c02cf83b1e0dfd97c1913c69 (diff) | |
download | vyos-cloud-init-c4e21c7278e839de6bb7fb9c5e34ea5a6114029f.tar.gz vyos-cloud-init-c4e21c7278e839de6bb7fb9c5e34ea5a6114029f.zip |
update ssh logs to show ssh private key gens pub and simplify code (#1221)
Diffstat (limited to 'cloudinit')
-rwxr-xr-x | cloudinit/config/cc_ssh.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/cloudinit/config/cc_ssh.py b/cloudinit/config/cc_ssh.py index a1f05176..64486b9c 100755 --- a/cloudinit/config/cc_ssh.py +++ b/cloudinit/config/cc_ssh.py @@ -212,22 +212,29 @@ def handle(_name, cfg, cloud, log, _args): cert_config = {"HostCertificate": tgt_fn} ssh_util.update_ssh_config(cert_config) - for (priv, pub) in PRIV_TO_PUB.items(): - if pub in cfg["ssh_keys"] or priv not in cfg["ssh_keys"]: + for private_type, public_type in PRIV_TO_PUB.items(): + if ( + public_type in cfg["ssh_keys"] + or private_type not in cfg["ssh_keys"] + ): continue - pair = (CONFIG_KEY_TO_FILE[priv][0], CONFIG_KEY_TO_FILE[pub][0]) - cmd = ["sh", "-xc", KEY_GEN_TPL % pair] + private_file, public_file = ( + CONFIG_KEY_TO_FILE[private_type][0], + CONFIG_KEY_TO_FILE[public_type][0], + ) + cmd = ["sh", "-xc", KEY_GEN_TPL % (private_file, public_file)] try: # TODO(harlowja): Is this guard needed? with util.SeLinuxGuard("/etc/ssh", recursive=True): subp.subp(cmd, capture=False) - log.debug("Generated a key for %s from %s", pair[0], pair[1]) + log.debug( + f"Generated a key for {public_file} from {private_file}" + ) except Exception: util.logexc( log, - "Failed generated a key for %s from %s", - pair[0], - pair[1], + "Failed generating a key for " + f"{public_file} from {private_file}", ) else: # if not, generate them |