Add more logging, add --delete option to admin queue sub-command
This commit is contained in:
parent
9b5d578985
commit
41b7535412
5 changed files with 23 additions and 7 deletions
|
@ -18,7 +18,7 @@ lacre.init_logging(conf.get_item('logging', 'config'))
|
|||
import lacre.repositories as repo
|
||||
import lacre.dbschema as db
|
||||
|
||||
LOG = logging.getLogger('lacre.admin')
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _no_database():
|
||||
|
@ -33,12 +33,14 @@ def sub_queue(args):
|
|||
eng = repo.init_engine(conf.get_item('database', 'url'))
|
||||
queue = repo.KeyConfirmationQueue(engine=eng)
|
||||
|
||||
cnt = queue.count_keys()
|
||||
if args.delete:
|
||||
queue.delete_key_by_email(args.delete)
|
||||
else:
|
||||
cnt = queue.count_keys()
|
||||
if cnt is None:
|
||||
_no_database()
|
||||
|
||||
if cnt is None:
|
||||
_no_database()
|
||||
|
||||
print(f'Keys in the queue: {cnt}')
|
||||
print(f'Keys in the queue: {cnt}')
|
||||
|
||||
|
||||
def sub_identities(args):
|
||||
|
@ -110,6 +112,8 @@ def main():
|
|||
help='Inspect key queue',
|
||||
aliases=['q']
|
||||
)
|
||||
cmd_queue.add_argument('-D', '--delete',
|
||||
help='delete specified email from the queue')
|
||||
cmd_queue.set_defaults(operation=sub_queue)
|
||||
|
||||
cmd_identities = sub_commands.add_parser('identities',
|
||||
|
|
|
@ -50,6 +50,7 @@ def notify(mailsubject, messagefile, recipients = None):
|
|||
(host, port) = conf.relay_params()
|
||||
smtp = smtplib.SMTP(host, port)
|
||||
_authenticate_maybe(smtp)
|
||||
LOG.info('Delivering notification: %s', recipients)
|
||||
smtp.sendmail(conf.get_item('cron', 'notification_email'), recipients, msg.as_string())
|
||||
else:
|
||||
LOG.info("Could not send mail due to wrong configuration")
|
||||
LOG.warning("Could not send mail due to wrong configuration")
|
||||
|
|
|
@ -174,6 +174,14 @@ class KeyConfirmationQueue:
|
|||
with self._engine.connect() as conn:
|
||||
conn.execute(delq)
|
||||
|
||||
def delete_key_by_email(self, email):
|
||||
"""Remove keys linked to the given email from the database."""
|
||||
delq = delete(self._keys).where(self._keys.c.email == email)
|
||||
|
||||
LOG.debug('Deleting email for: %s', email)
|
||||
with self._engine.connect() as conn:
|
||||
conn.execute(delq)
|
||||
|
||||
def mark_accepted(self, row_id):
|
||||
modq = self._keys.update().where(self._keys.c.id == row_id).values(status=db.ST_IMPORTED)
|
||||
LOG.debug("Key imported, updating key: %s", modq)
|
||||
|
|
|
@ -13,6 +13,7 @@ class ExecutionTimeLogger:
|
|||
|
||||
def __enter__(self):
|
||||
self._start = time.process_time()
|
||||
self._log.info('Start: %s', self._message)
|
||||
|
||||
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
|
||||
end = time.process_time()
|
||||
|
|
|
@ -80,6 +80,8 @@ if conf.flag_enabled('database', 'enabled') and conf.config_item_set('database',
|
|||
notify("PGP key registration failed", "registrationError.md", email)
|
||||
else:
|
||||
# delete key so we don't continue processing it
|
||||
LOG.debug('Empty key received, just deleting')
|
||||
|
||||
key_queue.delete_keys(row_id)
|
||||
if conf.flag_enabled('cron', 'send_email'):
|
||||
notify("PGP key deleted", "keyDeleted.md", email)
|
||||
|
|
Loading…
Reference in a new issue