bb974cc
Index: trunk/cloudinit/config/cc_ssh_authkey_fingerprints.py
bb974cc
===================================================================
bb974cc
--- trunk.orig/cloudinit/config/cc_ssh_authkey_fingerprints.py
bb974cc
+++ trunk/cloudinit/config/cc_ssh_authkey_fingerprints.py
bb974cc
@@ -21,7 +21,8 @@ import hashlib
bb974cc
 
bb974cc
 from prettytable import PrettyTable
bb974cc
 
bb974cc
-from cloudinit import ssh_util
bb974cc
+from cloudinit.ssh_util import extract_authorized_keys as eak
bb974cc
+
bb974cc
 from cloudinit import util
bb974cc
 
bb974cc
 
bb974cc
@@ -40,8 +41,9 @@ def _gen_fingerprint(b64_text, hash_meth
bb974cc
         hasher = hashlib.new(hash_meth)
bb974cc
         hasher.update(base64.b64decode(b64_text))
bb974cc
         return ":".join(_split_hash(hasher.hexdigest()))
bb974cc
-    except TypeError:
bb974cc
-        # Raised when b64 not really b64...
bb974cc
+    except (TypeError, ValueError):
bb974cc
+        # Raised when b64 not really b64... or
bb974cc
+        # when the hash type isn't valid
bb974cc
         return '?'
bb974cc
 
bb974cc
 
bb974cc
@@ -84,13 +86,48 @@ def _pprint_key_entries(user, key_fn, ke
bb974cc
                        stderr=False, console=True)
bb974cc
 
bb974cc
 
bb974cc
+def translate_user_name(uname, distro, log):
bb974cc
+    if not uname:
bb974cc
+        uname = ''
bb974cc
+    uname = uname.strip()
bb974cc
+    real_name = None
bb974cc
+    if uname.lower() == 'default':
bb974cc
+        try:
bb974cc
+            real_name = distro.get_default_user()
bb974cc
+        except NotImplementedError:
bb974cc
+            log.warn("Distro has not implemented default user "
bb974cc
+                     "creation. No default user will be translated.")
bb974cc
+    else:
bb974cc
+        real_name = uname
bb974cc
+    return real_name
bb974cc
+
bb974cc
+
bb974cc
 def handle(name, cfg, cloud, log, _args):
bb974cc
     if 'no_ssh_fingerprints' in cfg:
bb974cc
         log.debug(("Skipping module named %s, "
bb974cc
                    "logging of ssh fingerprints disabled"), name)
bb974cc
+        return
bb974cc
+
bb974cc
+    if not 'users' in cfg:
bb974cc
+        log.debug(("Skipping module named %s, "
bb974cc
+                   "logging of ssh fingerprints disabled "
bb974cc
+                   "since no user/s provided"), name)
bb974cc
+        return
bb974cc
+
bb974cc
+    users_to_hash = []
bb974cc
+    for user_config in cfg['users']:
bb974cc
+        user_name = None
bb974cc
+        if isinstance(user_config, (basestring, str)):
bb974cc
+            user_name = translate_user_name(user_config, cloud.distro, log)
bb974cc
+        elif isinstance(user_config, (dict)):
bb974cc
+            if 'name' in user_config:
bb974cc
+                user_name = translate_user_name(user_config['name'],
bb974cc
+                                                cloud.distro, log)
bb974cc
+        if user_name:
bb974cc
+            users_to_hash.append(user_name)
bb974cc
 
bb974cc
-    user_name = util.get_cfg_option_str(cfg, "user", "ubuntu")
bb974cc
     hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "md5")
bb974cc
-    extract = ssh_util.extract_authorized_keys
bb974cc
-    (auth_key_fn, auth_key_entries) = extract(user_name, cloud.paths)
bb974cc
-    _pprint_key_entries(user_name, auth_key_fn, auth_key_entries, hash_meth)
bb974cc
+    for user_name in users_to_hash:
bb974cc
+        (auth_key_fn, auth_key_entries) = eak(user_name, cloud.paths)
bb974cc
+        _pprint_key_entries(user_name, auth_key_fn,
bb974cc
+                            auth_key_entries, hash_meth)