From 0c1984f2f5d840077213084250bf810adca6f8c2 Mon Sep 17 00:00:00 2001 From: Kevin Griffin Date: Wed, 21 Aug 2024 20:06:04 -0400 Subject: [PATCH] update Signed-off-by: Kevin Griffin --- src/keria/app/cli/commands/sig-fix.py | 99 +++++++++++++++++---------- 1 file changed, 62 insertions(+), 37 deletions(-) diff --git a/src/keria/app/cli/commands/sig-fix.py b/src/keria/app/cli/commands/sig-fix.py index ce951de5..73770e77 100644 --- a/src/keria/app/cli/commands/sig-fix.py +++ b/src/keria/app/cli/commands/sig-fix.py @@ -5,7 +5,6 @@ """ import argparse -from collections import defaultdict from hio import help from hio.base import doing @@ -23,22 +22,11 @@ transferable=True) parser.add_argument('--base', '-b', help='additional optional prefix to file location of KERI keystore', required=False, default="") -parser.add_argument('--force', action="store_true", required=False, - help='True means perform fix without prompting the user') +parser.add_argument('--force', action="store_true", required=False, default=False, + help='Perform update') def handler(args): - if not args.force: - print() - print("This command will copy data from existing HabitatRecords to the corresponding SignifyGroupHab.") - print("This action cannot be undone.") - print() - yn = input("Are you sure you want to continue? [y|N]: ") - - if yn not in ("y", "Y"): - print("...exiting") - return [] - kwa = dict(args=args) return [doing.doify(fix, **kwa)] @@ -47,10 +35,24 @@ def fix(tymth, tock=0.0, **opts): _ = (yield tock) args = opts["args"] + prefix_by_public_key = dict() + prefix_by_next_key_digest = dict() + adb = abase.AgencyBaser(name="TheAgency", base=args.base, reopen=True, temp=False) + caids = [] for ((caid,), _) in adb.agnt.getItemIter(): - print(f"{caid}") + caids.append(caid) + + signify_group_habs = dict() + for caid in caids: + with existing.existingHby(name=caid, base=args.base) as hby: + for pre, hab in hby.habs.items(): + if type(hab) is habbing.SignifyGroupHab: + signify_group_habs[pre] = hab.name + + # create caches of existing public keys and next key digests and the associated prefixes + for caid in caids: db = basing.Baser(name=caid, base=args.base, temp=False, @@ -60,9 +62,6 @@ def fix(tymth, tock=0.0, **opts): except kering.DatabaseError: return -1 - prefix_by_public_key = dict() - prefix_by_next_key_digest = dict() - for pre, fn, dig in db.getFelItemAllPreIter(key=b''): dgkey = dbing.dgKey(pre, dig) if not (raw := db.getEvt(key=dgkey)): @@ -73,17 +72,41 @@ def fix(tymth, tock=0.0, **opts): verfers = serder.verfers or [] ndigers = serder.ndigers or [] + if val[0].qb64 in signify_group_habs: + continue + for verfer in verfers: prefix_by_public_key[verfer.qb64] = val for diger in ndigers: prefix_by_next_key_digest[diger.qb64] = val + # pretty + pre_name_cache = dict() + for caid in caids: with existing.existingHby(name=caid, base=args.base) as hby: for pre, hab in hby.habs.items(): - print(f"checking {pre}") + pre_name_cache[pre] = hab.name + + # Arby's + # update existing hab records with the correct smids and rmids + for caid in caids: + with existing.existingHby(name=caid, base=args.base) as hby: + print() + print(f"Hby {hby.name}") - if not hasattr(hab, "smids") and not hasattr(hab, "rmids"): + for pre, hab in hby.habs.items(): + if type(hab) is not habbing.SignifyGroupHab: + print(f"\t skipping {pre} - {type(hab)}") + continue + + print() + print(f"\t {hab.name} - {pre} - {type(hab)}") + print() + + if not hasattr(hab, "smids") and not hasattr(hab, "rmids") or \ + hab.smids is None and hab.rmids is None: + print() smids = set() rmids = set() for v in hab.kever.verfers: @@ -94,20 +117,22 @@ def fix(tymth, tock=0.0, **opts): if v.qb64 in prefix_by_next_key_digest: rmids.add(prefix_by_next_key_digest[v.qb64][0].qb64) - hab.smids = list(smids) - hab.rmids = list(rmids) - else: - print("already has smids and rmids") - print(f"{hab.smids} {hab.rmids}") - - print("done with hab") - print() - print() - - with existing.existingHby(name=caid, base=args.base) as hby: - for pre, hab in hby.habs.items(): - print(f"post update {pre} {type(hab)}") - if isinstance(hab, habbing.SignifyHab): - continue - print(hab.smids) - print(hab.rmids) \ No newline at end of file + print(f"\t Proposed smids and rmids updates for {hab.name} - {pre}:") + print(f"\t\t smids: {smids}") + for smid in smids: + print(f"\t\t\t -> {smid} {pre_name_cache.get(smid)}") + print(f"\t\t rmids: {rmids}") + for rmid in rmids: + print(f"\t\t\t -> {rmid} {pre_name_cache.get(rmid)}") + + if args.force: + habr = hab.db.habs.get(keys=(hab.pre,)) + habr.smids = list(smids) + habr.rmids = list(rmids) + print(f"\t Updating {habr}") + hab.db.habs.pin(keys=(hab.pre,), val=habr) + print() + else: + print() + print("no updates performed, use --force to apply changes") + print()