diff options
author | Joshua Harlow <harlowja@gmail.com> | 2014-11-22 12:36:46 -0800 |
---|---|---|
committer | Joshua Harlow <harlowja@gmail.com> | 2014-11-22 12:36:46 -0800 |
commit | e4d3fdb65bb31c2c3ed02ffdc14c0437379f64d8 (patch) | |
tree | a9b6b3881cc6f7cd532034f37c688c0e8ca29e98 /cloudinit | |
parent | ad492708076e20c20f7c8ee96b1b2250bcad7d8f (diff) | |
parent | 477a5418d55d45ddad55fcaa16ab3ac53652fdb9 (diff) | |
download | vyos-cloud-init-e4d3fdb65bb31c2c3ed02ffdc14c0437379f64d8.tar.gz vyos-cloud-init-e4d3fdb65bb31c2c3ed02ffdc14c0437379f64d8.zip |
Be more tolerant of 'ssh_authorized_keys' types
Instead of only expected a list, tuple, or set type
allow for a string type and dict to be passed in for 'ssh_authorized_keys',
and add log message that occurs if some other type is used that
can not be correctly processed.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/distros/__init__.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 2599d9f2..83c2eebf 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -387,8 +387,20 @@ class Distro(object): # Import SSH keys if 'ssh_authorized_keys' in kwargs: - keys = set(kwargs['ssh_authorized_keys']) or [] - ssh_util.setup_user_keys(keys, name, options=None) + # Try to handle this in a smart manner. + keys = kwargs['ssh_authorized_keys'] + if isinstance(keys, (basestring, str)): + keys = [keys] + if isinstance(keys, dict): + keys = list(keys.values()) + if keys is not None: + if not isinstance(keys, (tuple, list, set)): + LOG.warn("Invalid type '%s' detected for" + " 'ssh_authorized_keys', expected list," + " string, dict, or set.", type(keys)) + else: + keys = set(keys) or [] + ssh_util.setup_user_keys(keys, name, options=None) return True |