summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2016-06-27 18:30:24 +0200
committerRuben Pollan <meskio@sindominio.net>2016-07-03 16:04:41 +0200
commit34411693fb3f43080b98c51575e244c6d403399c (patch)
tree7972344b97b0f99ac5a2cd6ad06acc0201012957 /src/leap
parent803a0219da0445fba0c5eb4d3be8e7a4ab62b06e (diff)
[feat] use SubCommand for the keys dispatcher
- Related: #7965
Diffstat (limited to 'src/leap')
-rwxr-xr-xsrc/leap/bitmask/cli/bitmask_cli.py17
-rw-r--r--src/leap/bitmask/core/dispatcher.py35
2 files changed, 32 insertions, 20 deletions
diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py
index fd70c680..9110f88a 100755
--- a/src/leap/bitmask/cli/bitmask_cli.py
+++ b/src/leap/bitmask/cli/bitmask_cli.py
@@ -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',
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index ec3593e8..47e1c2c2 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -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]