monkeysphere: Make sure show keys output is robust

This commit is contained in:
Sunil Mohan Adapa 2016-08-29 20:39:19 +05:30 committed by James Valleroy
parent 9b89fac9e1
commit 4f9b271824
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -125,7 +125,8 @@ def get_monkeysphere_keys(key_id=None):
return {}
# parse output
keys = [dict()]
default_dict = {'imported_domains': [], 'available_domains': []}
keys = [default_dict.copy()]
lines = output.decode().strip().split('\n')
for line in lines:
if line.startswith('pub'):
@ -140,8 +141,7 @@ def get_monkeysphere_keys(key_id=None):
keys[-1].setdefault('uids', []).append(uid)
matches = re.match('([a-zA-Z]*)://(.*)(:\d*)?', uid)
keys[-1]['service'] = matches.group(1)
keys[-1].setdefault('imported_domains', []) \
.append(matches.group(2))
keys[-1]['imported_domains'].append(matches.group(2))
elif line.startswith('OpenPGP fingerprint:'):
keys[-1]['openpgp_fingerprint'] = \
line.lstrip('OpenPGP fingerprint:')
@ -151,7 +151,7 @@ def get_monkeysphere_keys(key_id=None):
keys[-1]['ssh_fingerprint'] = data[1]
keys[-1]['ssh_key_type'] = data[2].strip('()')
elif line == '':
keys.append(dict())
keys.append(default_dict.copy())
return {key['ssh_fingerprint']: key for key in keys}