Unverified Commit 34411693 authored by meskio's avatar meskio
Browse files

[feat] use SubCommand for the keys dispatcher

- Related: #7965
parent 803a0219
......@@ -136,11 +136,9 @@ GENERAL COMMANDS:
parser = argparse.ArgumentParser(
description='Bitmask Keymanager management service',
prog='bitmask_cli keys')
parser.add_argument('--status', action='store_true',
help='Display status about service')
parser.add_argument('--list-keys', action='store_true',
parser.add_argument('--list', action='store_true',
help='List all known keys')
parser.add_argument('--export-key', action='store_true',
parser.add_argument('--export', action='store_true',
help='Export the given key')
args = parser.parse_args(sys.argv[2:])
self.subargs = args
......@@ -311,14 +309,11 @@ def send_command(cli):
elif cmd == 'keys':
data = ['keys']
if subargs.status:
data += ['status']
elif subargs.list_keys:
data += ['list_keys']
if subargs.list:
data += ['list']
elif subargs.export_key:
data += ['export_keys']
elif subargs.export:
data += ['export']
else:
error('Use bitmask_cli keys --help to see available subcommands',
......
......@@ -149,6 +149,23 @@ class MailCmd(SubCommand):
return d
class KeysCmd(SubCommand):
label = 'keys'
@register_method("[[str, str]]")
def do_LIST(self, service, *parts, **kw):
bonafide = kw['bonafide']
d = bonafide.do_get_active_user()
d.addCallback(service.do_list_keys)
return d
@register_method('str')
def do_EXPORT(self, service, *parts, **kw):
# TODO
return defer.succeed("")
class CommandDispatcher(object):
__metaclass__ = APICommand
......@@ -161,6 +178,7 @@ class CommandDispatcher(object):
self.subcommand_user = UserCmd()
self.subcommand_eip = EIPCmd()
self.subcommand_mail = MailCmd()
self.subcommand_keys = KeysCmd()
# XXX --------------------------------------------
# TODO move general services to another subclass
......@@ -227,20 +245,19 @@ class CommandDispatcher(object):
return d
def do_KEYS(self, *parts):
subcmd = parts[1]
dispatch = self.subcommand_keys.dispatch
keymanager_label = 'keymanager'
km = self._get_service(keymanager_label)
bf = self._get_service('bonafide')
keymanager = self._get_service(keymanager_label)
bonafide = self._get_service('bonafide')
kw = {'bonafide': bonafide}
if not km:
if not keymanager:
return _format_result('keymanager: disabled')
if subcmd == 'list_keys':
d = bf.do_get_active_user()
d.addCallback(km.do_list_keys)
d.addCallbacks(_format_result, _format_error)
return d
d = dispatch(keymanager, *parts, **kw)
d.addCallbacks(_format_result, _format_error)
return d
def dispatch(self, msg):
cmd = msg[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment