From 444cf64fb50d4f4baa3a6631fc6ed60e8d51a595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 17 Apr 2019 13:30:54 +0200 Subject: [PATCH] daemon: Use the system keyring to store access tokens. --- pantalaimon/daemon.py | 14 ++++++++++---- setup.py | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 7233d42..677d739 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -11,6 +11,7 @@ from urllib.parse import urlparse import aiohttp import attr import click +import keyring import logbook from aiohttp import ClientSession, web from aiohttp.client_exceptions import ContentTypeError @@ -51,7 +52,10 @@ class ProxyDaemon: self.client_info = self.store.load_clients(self.hostname) for user_id, device_id in accounts: - token = self.store.load_access_token(user_id, device_id) + token = keyring.get_password( + "pantalaimon", + f"{user_id}-{device_id}-token" + ) if not token: logger.warn(f"Not restoring client for {user_id} {device_id}, " @@ -186,9 +190,10 @@ class ProxyDaemon: f"{user_id}") self.pan_clients[user_id] = pan_client - self.store.save_access_token( - user_id, - pan_client.device_id, + + keyring.set_password( + "pantalaimon", + f"{user_id}-{pan_client.device_id}-token", pan_client.access_token ) @@ -405,6 +410,7 @@ class ProxyDaemon: This method is called when we shut the whole app down """ + for client in self.pan_clients.values(): await client.loop_stop() await client.close() diff --git a/setup.py b/setup.py index c7168b4..c9441f7 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ setup( "aiohttp", "appdirs", "click", + "keyring", "logbook", "peewee", "typing;python_version<'3.5'",