From 9dd3e79bac19166db46b34036882df41b6c55e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 12 Jul 2019 16:00:18 +0200 Subject: [PATCH] daemon: Catch a RuntimeError for the keyring. If the keyring doesn't manage to find a sensible and secure keyring backend it will raise a RuntimeError. Catch this error and log the error message. The keyring can be disabled in the config if the system cannot provide a sensible keyring backend. --- pantalaimon/daemon.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index a422018..f30f379 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -99,9 +99,12 @@ class ProxyDaemon: for user_id, device_id in accounts: if self.conf.keyring: - token = keyring.get_password( - "pantalaimon", f"{user_id}-{device_id}-token" - ) + try: + token = keyring.get_password( + "pantalaimon", f"{user_id}-{device_id}-token" + ) + except RuntimeError as e: + logger.error(e) else: token = self.store.load_access_token(user_id, device_id) @@ -559,11 +562,14 @@ class ProxyDaemon: self.pan_clients[user_id] = pan_client if self.conf.keyring: - keyring.set_password( - "pantalaimon", - f"{user_id}-{pan_client.device_id}-token", - pan_client.access_token, - ) + try: + keyring.set_password( + "pantalaimon", + f"{user_id}-{pan_client.device_id}-token", + pan_client.access_token, + ) + except RuntimeError as e: + logger.error(e) else: self.store.save_access_token( user_id, pan_client.device_id, pan_client.access_token