From f15673c6591036882bb6a277d5b9e73d3c7e348a Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 28 Jun 2016 18:39:12 +0200 Subject: [feat] add delete key command to the cli --- src/leap/bitmask/cli/bitmask_cli.py | 5 +++++ src/leap/bitmask/core/dispatcher.py | 11 +++++++++++ src/leap/bitmask/core/mail_services.py | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py index e51a41b7..60dc5176 100755 --- a/src/leap/bitmask/cli/bitmask_cli.py +++ b/src/leap/bitmask/cli/bitmask_cli.py @@ -140,6 +140,8 @@ GENERAL COMMANDS: help='List all known keys') parser.add_argument('--export', action='store_true', help='Export the given key') + parser.add_argument('--delete', action='store_true', + help='Delete the given key') parser.add_argument('address', nargs='?', help='email address of the key') args = parser.parse_args(sys.argv[2:]) @@ -353,6 +355,9 @@ def send_command(cli): data += ['export'] cb = do_print_key + elif subargs.delete: + data += ['delete'] + else: error('Use bitmask_cli keys --help to see available subcommands', stop=True) diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py index db40a675..785c60dc 100644 --- a/src/leap/bitmask/core/dispatcher.py +++ b/src/leap/bitmask/core/dispatcher.py @@ -171,6 +171,17 @@ class KeysCmd(SubCommand): d.addCallback(service.do_export, address) return d + @register_method('str') + def do_DELETE(self, service, *parts, **kw): + if len(parts) < 3: + return defer.fail("An email address is needed") + address = parts[2] + + bonafide = kw['bonafide'] + d = bonafide.do_get_active_user() + d.addCallback(service.do_delete, address) + return d + class CommandDispatcher(object): diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py index 0dd53189..8d205d92 100644 --- a/src/leap/bitmask/core/mail_services.py +++ b/src/leap/bitmask/core/mail_services.py @@ -358,6 +358,13 @@ class KeymanagerService(HookableService): d.addCallback(lambda key: dict(key)) return d + @defer.inlineCallbacks + def do_delete(self, userid, address): + km = self._container.get_instance(userid) + key = yield km.get_key(address, fetch_remote=False) + km.delete_key(key) + defer.returnValue(key.fingerprint) + class StandardMailService(service.MultiService, HookableService): """ -- cgit v1.2.3