mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +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 argparse
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import copy
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -138,7 +139,7 @@ def get_monkeysphere_keys(key_id=None):
|
|||||||
|
|
||||||
# parse output
|
# parse output
|
||||||
default_dict = {'imported_domains': [], 'available_domains': []}
|
default_dict = {'imported_domains': [], 'available_domains': []}
|
||||||
keys = [default_dict.copy()]
|
keys = [copy.deepcopy(default_dict)]
|
||||||
lines = output.decode().strip().split('\n')
|
lines = output.decode().strip().split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith('pub'):
|
if line.startswith('pub'):
|
||||||
@ -163,7 +164,7 @@ def get_monkeysphere_keys(key_id=None):
|
|||||||
keys[-1]['ssh_fingerprint'] = data[1]
|
keys[-1]['ssh_fingerprint'] = data[1]
|
||||||
keys[-1]['ssh_key_type'] = data[2].strip('()')
|
keys[-1]['ssh_key_type'] = data[2].strip('()')
|
||||||
elif line == '':
|
elif line == '':
|
||||||
keys.append(default_dict.copy())
|
keys.append(copy.deepcopy(default_dict))
|
||||||
|
|
||||||
return {key['ssh_fingerprint']: key for key in keys}
|
return {key['ssh_fingerprint']: key for key in keys}
|
||||||
|
|
||||||
|
|||||||
@ -50,13 +50,12 @@ def index(request):
|
|||||||
@require_POST
|
@require_POST
|
||||||
def import_key(request, ssh_fingerprint):
|
def import_key(request, ssh_fingerprint):
|
||||||
"""Import a key into monkeysphere."""
|
"""Import a key into monkeysphere."""
|
||||||
available_domains = [
|
keys = get_keys()
|
||||||
domain for domains in names.domains.values() for domain in domains
|
available_domains = keys[ssh_fingerprint]['available_domains']
|
||||||
]
|
|
||||||
try:
|
try:
|
||||||
actions.superuser_run(
|
actions.superuser_run(
|
||||||
'monkeysphere',
|
'monkeysphere',
|
||||||
['host-import-key', ssh_fingerprint] + available_domains)
|
['host-import-key', ssh_fingerprint] + list(available_domains))
|
||||||
messages.success(request, _('Imported key.'))
|
messages.success(request, _('Imported key.'))
|
||||||
except actions.ActionError as exception:
|
except actions.ActionError as exception:
|
||||||
messages.error(request, str(exception))
|
messages.error(request, str(exception))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user