refactor load_pgp_public_keys
This commit is contained in:
parent
16df2acb29
commit
f4beb81195
|
@ -1076,7 +1076,7 @@ if __name__ == "__main__":
|
||||||
LOG.warning("LOAD PGP keys")
|
LOG.warning("LOAD PGP keys")
|
||||||
app = create_app()
|
app = create_app()
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
load_pgp_public_keys(app)
|
load_pgp_public_keys()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
23
init_app.py
23
init_app.py
|
@ -6,21 +6,18 @@ from app.pgp_utils import load_public_key
|
||||||
from server import create_app
|
from server import create_app
|
||||||
|
|
||||||
|
|
||||||
def load_pgp_public_keys(app):
|
def load_pgp_public_keys():
|
||||||
"""Load PGP public key to keyring"""
|
"""Load PGP public key to keyring"""
|
||||||
with app.app_context():
|
for mailbox in Mailbox.query.filter(Mailbox.pgp_public_key != None).all():
|
||||||
for mailbox in Mailbox.query.filter(Mailbox.pgp_public_key != None).all():
|
LOG.d("Load PGP key for mailbox %s", mailbox)
|
||||||
LOG.d("Load PGP key for mailbox %s", mailbox)
|
fingerprint = load_public_key(mailbox.pgp_public_key)
|
||||||
fingerprint = load_public_key(mailbox.pgp_public_key)
|
|
||||||
|
|
||||||
# sanity check
|
# sanity check
|
||||||
if fingerprint != mailbox.pgp_finger_print:
|
if fingerprint != mailbox.pgp_finger_print:
|
||||||
LOG.error(
|
LOG.error("fingerprint %s different for mailbox %s", fingerprint, mailbox)
|
||||||
"fingerprint %s different for mailbox %s", fingerprint, mailbox
|
mailbox.pgp_finger_print = fingerprint
|
||||||
)
|
|
||||||
mailbox.pgp_finger_print = fingerprint
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
LOG.d("Finish load_pgp_public_keys")
|
LOG.d("Finish load_pgp_public_keys")
|
||||||
|
|
||||||
|
@ -29,4 +26,4 @@ if __name__ == "__main__":
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
load_pgp_public_keys(app)
|
load_pgp_public_keys()
|
||||||
|
|
Loading…
Reference in New Issue