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.
This commit is contained in:
Damir Jelić 2019-07-12 16:00:18 +02:00
parent 1a8f28b90a
commit 9dd3e79bac

View File

@ -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