PGP Keyring: Display expiry dates in ISO format

This commit is contained in:
David Duque 2020-11-21 03:26:27 +00:00
parent 570a22903a
commit e519cea350
No known key found for this signature in database
GPG key ID: 2F327738A3C0AE3A
2 changed files with 8 additions and 8 deletions

View file

@ -31,7 +31,7 @@ def key_representation(key):
"auth": skey.can_authenticate == 1,
"fpr": skey.fpr,
"expires": skey.expires if skey.expires != 0 else None,
"expires_date": datetime.datetime.utcfromtimestamp(skey.expires).strftime("%x") if skey.expires != 0 else None,
"expires_date": datetime.datetime.utcfromtimestamp(skey.expires).date().isoformat() if skey.expires != 0 else None,
"expires_days": (datetime.datetime.utcfromtimestamp(skey.expires) - now).days if skey.expires != 0 else None,
"expired": skey.expired == 1,
"algorithm": gpg.core.pubkey_algo_name(skey.pubkey_algo),
@ -101,9 +101,9 @@ def create_signature(data, detached=False):
if __name__ == "__main__":
import sys, utils
# Check if we should renew the key
daemon_key = get_daemon_key()
exp = daemon_key.subkeys[0].expires
now = datetime.datetime.utcnow()
days_left = (datetime.datetime.utcfromtimestamp(exp) - now).days

View file

@ -290,10 +290,10 @@ def run_pgp_checks(env, output):
else:
exp = datetime.datetime.utcfromtimestamp(sk.expires) # Our daemon key only has one subkey
if (exp - now).days < 10 and sk.expires != 0:
output.print_warning(f"The daemon's key ({k.fpr}) will expire soon, in {(exp - now).days} days on {exp.strftime('%x')}.")
output.print_warning(f"The daemon's key ({k.fpr}) will expire soon, in {(exp - now).days} days on {exp.date().soformat()}.")
else:
output.print_ok(f"The daemon's key ({k.fpr}) is good. It expires in {(exp - now).days} days on {exp.strftime('%x')}.")
output.print_ok(f"The daemon's key ({k.fpr}) is good. It expires in {(exp - now).days} days on {exp.date().isoformat()}.")
# Check imported keys
keys = get_imported_keys()
if len(keys) == 0:
@ -313,7 +313,7 @@ def run_pgp_checks(env, output):
expired.append((key, skey))
elif (exp - now).days < 10 and skey.expires != 0:
about_to_expire.append((key, skey))
all_good = True
def printpair(keytuple):
key, skey = keytuple
@ -333,7 +333,7 @@ def run_pgp_checks(env, output):
all_good = False
output.print_error(f"There {'is 1 revoked key' if len(revoked) == 1 else f'are {len(revoked)} revoked keys'}.")
list(map(lambda k: output.print_line(k.fpr), revoked))
if all_good:
output.print_ok("All imported keys are good.")