Make key-loading async, remove unused parameter

This commit is contained in:
Piotr F. Mieszkowski 2022-10-17 23:25:51 +02:00 committed by Gitea
parent 9696b7e997
commit 641253b3ec
3 changed files with 6 additions and 14 deletions

View File

@ -51,14 +51,6 @@ dec_regex = None
# i.e. have mode 700.
keyhome = /var/gpgmailgate/.gnupg
# Number of minutes between key cache refreshes.
#
# Lacre daemon keeps a cache of known keys to reduce number of OS processes
# needed to perform a single email. Keyring is going to be modified during
# daemon's lifetime, so with this simple mechanism we ensure that new keys
# will eventually be recognised and loaded.
cache_refresh_minutes = 5
[smime]
# the directory for the S/MIME certificate files
cert_path = /var/gpgmailgate/smime

View File

@ -80,16 +80,14 @@ def _full_param_name(tup):
return f"[{tup[0]}]{tup[1]}"
async def _sleep(minutes):
async def _sleep():
while True:
await asyncio.sleep(minutes * 60)
await asyncio.sleep(360)
def _main():
_validate_config()
refresh_min = float(conf.get_item('gpg', 'cache_refresh_minutes', 2))
keyring_path = conf.get_item('gpg', 'keyhome')
keyring = kcache.KeyRing(keyring_path)
controller = _init_controller(keyring)
@ -102,7 +100,7 @@ def _main():
controller.start()
try:
asyncio.run(_sleep(refresh_min))
asyncio.run(_sleep())
except KeyboardInterrupt:
LOG.info("Finishing...")
finally:

View File

@ -8,7 +8,7 @@ import lacre.text as text
import logging
from os import stat
from watchdog.events import FileSystemEventHandler
from asyncio import Semaphore
from asyncio import Semaphore, run
import copy
import GnuPG
@ -92,7 +92,9 @@ class KeyRing:
def load(self):
"""Load keyring, replacing any previous contents of the cache."""
LOG.debug('Reloading keys...')
run(self._load())
async def _load(self):
last_mod = self._read_mod_time()
if self._is_modified(last_mod):
async with self._sema: