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.
This commit is contained in:
Joshua Harlow 2014-11-22 12:36:46 -08:00
commit c537fa2dcd
2 changed files with 17 additions and 2 deletions

View File

@ -11,6 +11,9 @@
- Increase the usefulness, robustness, configurability of the chef module - Increase the usefulness, robustness, configurability of the chef module
so that it is more useful, more documented and better for users so that it is more useful, more documented and better for users
- Fix how '=' signs are not handled that well in ssh_utils (LP: #1391303) - Fix how '=' signs are not handled that well in ssh_utils (LP: #1391303)
- Be more tolerant of ssh keys passed into 'ssh_authorized_keys'; allowing
for list, tuple, set, dict, string types and warning on other unexpected
types
0.7.6: 0.7.6:
- open 0.7.6 - open 0.7.6
- Enable vendordata on CloudSigma datasource (LP: #1303986) - Enable vendordata on CloudSigma datasource (LP: #1303986)

View File

@ -387,8 +387,20 @@ class Distro(object):
# Import SSH keys # Import SSH keys
if 'ssh_authorized_keys' in kwargs: if 'ssh_authorized_keys' in kwargs:
keys = set(kwargs['ssh_authorized_keys']) or [] # Try to handle this in a smart manner.
ssh_util.setup_user_keys(keys, name, options=None) 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 return True