mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
monkeysphere: Fix handling of multiple domains and keys
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
722fa39c2a
commit
49640fdfce
@ -21,6 +21,7 @@ Configuration helper for monkeysphere.
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@ -138,7 +139,7 @@ def get_monkeysphere_keys(key_id=None):
|
||||
|
||||
# parse output
|
||||
default_dict = {'imported_domains': [], 'available_domains': []}
|
||||
keys = [default_dict.copy()]
|
||||
keys = [copy.deepcopy(default_dict)]
|
||||
lines = output.decode().strip().split('\n')
|
||||
for line in lines:
|
||||
if line.startswith('pub'):
|
||||
@ -163,7 +164,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(default_dict.copy())
|
||||
keys.append(copy.deepcopy(default_dict))
|
||||
|
||||
return {key['ssh_fingerprint']: key for key in keys}
|
||||
|
||||
|
||||
@ -50,13 +50,12 @@ def index(request):
|
||||
@require_POST
|
||||
def import_key(request, ssh_fingerprint):
|
||||
"""Import a key into monkeysphere."""
|
||||
available_domains = [
|
||||
domain for domains in names.domains.values() for domain in domains
|
||||
]
|
||||
keys = get_keys()
|
||||
available_domains = keys[ssh_fingerprint]['available_domains']
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'monkeysphere',
|
||||
['host-import-key', ssh_fingerprint] + available_domains)
|
||||
['host-import-key', ssh_fingerprint] + list(available_domains))
|
||||
messages.success(request, _('Imported key.'))
|
||||
except actions.ActionError as exception:
|
||||
messages.error(request, str(exception))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user