Log more information about FS events while reloading keys

This commit is contained in:
Piotr F. Mieszkowski 2023-04-13 20:40:10 +02:00
parent 682de14630
commit fdd11dba14
2 changed files with 12 additions and 7 deletions

View File

@ -62,7 +62,7 @@ class KeyCache:
def __repr__(self):
"""Return text representation of this object."""
details = ' '.join(self._keys.keys())
return f'<KeyCache {details}>'
return '<KeyCache %s>' % (details)
class KeyRing:
@ -122,7 +122,7 @@ class KeyRing:
LOG.info(f'Storing {len(keys)} keys')
self._keys = keys
def _read_mod_time(self):
def _read_mod_time(self) -> int:
# (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)
# 0 1 2 3 4 5 6 7 8 9
MTIME = 8
@ -140,6 +140,10 @@ class KeyRing:
LOG.debug('Keyring not modified ')
return False
def __repr__(self) -> str:
"""Return text representation of this keyring."""
return '<KeyRing path=%s last_mod=%d>' % (self._path, self._last_mod)
class KeyringModificationListener(FileSystemEventHandler):
"""A filesystem event listener that triggers key cache reload."""
@ -150,8 +154,9 @@ class KeyringModificationListener(FileSystemEventHandler):
def handle(self, event: FileSystemEvent):
"""Reload keys upon FS event."""
LOG.debug('FS event: %s, %s', event.event_type, event.src_path)
if 'pubring.kbx' in event.src_path:
LOG.debug(f'Reloading on event {event!r}')
LOG.info('Reloading %s on event: %s', self._keyring, event)
self._keyring.reload()
# All methods should do the same: reload the key cache.

View File

@ -143,7 +143,7 @@ def identify_gpg_recipients(recipients, keys: kcache.KeyCache):
return gpg_recipients, cleartext_recipients
def _find_key(recipient, keys, strict_mode):
def _find_key(recipient, keys: kcache.KeyCache, strict_mode):
own_key = _try_configured_key(recipient, keys)
if own_key is not None:
return GpgRecipient(own_key[0], own_key[1])
@ -159,7 +159,7 @@ def _find_key(recipient, keys, strict_mode):
return None
def _try_configured_key(recipient, keys):
def _try_configured_key(recipient, keys: kcache.KeyCache):
if conf.config_item_set('enc_keymap', recipient):
key = conf.get_item('enc_keymap', recipient)
if key in keys:
@ -170,7 +170,7 @@ def _try_configured_key(recipient, keys):
return None
def _try_direct_key_lookup(recipient, keys, strict_mode):
def _try_direct_key_lookup(recipient, keys: kcache.KeyCache, strict_mode):
if strict_mode:
return None
@ -186,7 +186,7 @@ def _try_direct_key_lookup(recipient, keys, strict_mode):
return None
def _try_configured_domain_key(recipient, keys):
def _try_configured_domain_key(recipient, keys: kcache.KeyCache):
parts = recipient.split('@')
if len(parts) != 2:
return None