summaryrefslogtreecommitdiff
path: root/cloudinit/ssh_util.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-15 18:24:04 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-15 18:24:04 -0700
commit7b3bf46487e599b375acfdf99176294810805ef0 (patch)
tree41b0b5e195e3fb6548f43bacc46555497961ceee /cloudinit/ssh_util.py
parent508168acb95aee070d493b45656f781a42bdd262 (diff)
downloadvyos-cloud-init-7b3bf46487e599b375acfdf99176294810805ef0.tar.gz
vyos-cloud-init-7b3bf46487e599b375acfdf99176294810805ef0.zip
Ensure when an exception is captured that we use the util.logexc helper.
Diffstat (limited to 'cloudinit/ssh_util.py')
-rw-r--r--cloudinit/ssh_util.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/cloudinit/ssh_util.py b/cloudinit/ssh_util.py
index c97b3819..f6941a29 100644
--- a/cloudinit/ssh_util.py
+++ b/cloudinit/ssh_util.py
@@ -144,13 +144,13 @@ class AuthKeyEntry(object):
return ' '.join(toks)
-def _update_authorized_keys(fname, keys):
+def update_authorized_keys(fname, keys):
lines = []
try:
if os.path.isfile(fname):
lines = util.load_file(fname).splitlines()
except (IOError, OSError):
- LOG.exception("Error reading lines from %s", fname)
+ util.logexc(LOG, "Error reading lines from %s", fname)
lines = []
to_add = list(keys)
@@ -199,7 +199,7 @@ def setup_user_keys(keys, user, key_prefix, sshd_config_fn=None):
# The following tokens are defined: %% is replaced by a literal
# '%', %h is replaced by the home directory of the user being
# authenticated and %u is replaced by the username of that user.
- ssh_cfg = _parse_ssh_config(sshd_config_fn)
+ ssh_cfg = parse_ssh_config(sshd_config_fn)
akeys = ssh_cfg.get("authorizedkeysfile", '')
akeys = akeys.strip()
if not akeys:
@@ -212,19 +212,19 @@ def setup_user_keys(keys, user, key_prefix, sshd_config_fn=None):
authorized_keys = akeys
except (IOError, OSError):
authorized_keys = os.path.join(ssh_dir, 'authorized_keys')
- LOG.exception(("Failed extracting 'AuthorizedKeysFile'"
- " in ssh config"
- " from %s, using 'AuthorizedKeysFile' file"
- " %s instead"),
- sshd_config_fn, authorized_keys)
+ util.logexc(LOG, ("Failed extracting 'AuthorizedKeysFile'"
+ " in ssh config"
+ " from %s, using 'AuthorizedKeysFile' file"
+ " %s instead"),
+ sshd_config_fn, authorized_keys)
- content = _update_authorized_keys(authorized_keys, key_entries)
+ content = update_authorized_keys(authorized_keys, key_entries)
util.ensure_dir(os.path.dirname(authorized_keys), mode=0700)
util.write_file(authorized_keys, content, mode=0600)
util.chownbyid(authorized_keys, pwent.pw_uid, pwent.pw_gid)
-def _parse_ssh_config(fname):
+def parse_ssh_config(fname):
# The file contains keyword-argument pairs, one per line.
# Lines starting with '#' and empty lines are interpreted as comments.
# Note: key-words are case-insensitive and arguments are case-sensitive