From e43b8c750c3cf02fa708c138390c30a4273b9486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 18 Apr 2019 16:56:53 +0200 Subject: [PATCH] ui: Expose key imports from the dbus API. --- pantalaimon/daemon.py | 19 ++++++++++++++++--- pantalaimon/ui.py | 13 +++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 28c5c4d..ae75078 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -156,12 +156,25 @@ class ProxyDaemon: try: client.export_keys(path, message.passphrase) except OSError as e: - logger.warn(f"Error exporint keys for {client.user_id} to " - f"{path} {e}") + logger.warn(f"Error exporting keys for {client.user_id} to" + f" {path} {e}") pass elif isinstance(message, ImportKeysMessage): - pass + client = self.pan_clients.get(message.pan_user, None) + + if not client: + return + + path = os.path.abspath(message.file_path) + logger.info(f"Importing keys from {path}") + + try: + client.import_keys(path, message.passphrase) + except (OSError, EncryptionError) as e: + logger.warn(f"Error importing keys for {client.user_id} " + f"from {path} {e}") + pass def get_access_token(self, request): # type: (aiohttp.web.BaseRequest) -> str diff --git a/pantalaimon/ui.py b/pantalaimon/ui.py index ba0f923..a309708 100644 --- a/pantalaimon/ui.py +++ b/pantalaimon/ui.py @@ -150,6 +150,19 @@ class Control(dbus.service.Object): return + @dbus.service.method("org.pantalaimon.control.import_keys", + in_signature="sss") + def import_keys(self, pan_user, filepath, passphrase): + message = ImportKeysMessage( + pan_user, + filepath, + passphrase + ) + self.queue.put(message) + + return + + def glib_loop(receive_queue, send_queue, data_dir): DBusGMainLoop(set_as_default=True)