From f07da432a21a7a643b879938c35dd304dbf12285 Mon Sep 17 00:00:00 2001 From: 2byrds <2byrds@gmail.com> Date: Mon, 12 Aug 2024 15:31:32 -0400 Subject: [PATCH] remove formatting from diff of agenting.py Signed-off-by: 2byrds <2byrds@gmail.com> --- src/keria/app/agenting.py | 659 +++++++++++++------------------------- 1 file changed, 227 insertions(+), 432 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 1e121931..c30ef017 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -21,19 +21,8 @@ from keri.app.notifying import Notifier from keri.app.storing import Mailboxer -from keri.app import ( - configing, - keeping, - habbing, - storing, - signaling, - oobiing, - agenting, - forwarding, - querying, - connecting, - grouping, -) +from keri.app import configing, keeping, habbing, storing, signaling, oobiing, agenting, \ + forwarding, querying, connecting, grouping from keri.app.grouping import Counselor from keri.app.keeping import Algos from keri.core import coring, parsing, eventing, routing, serdering @@ -62,39 +51,15 @@ logger = ogler.getLogger() -def setup( - name, - bran, - adminPort, - bootPort, - base="", - httpPort=None, - configFile=None, - configDir=None, - keypath=None, - certpath=None, - cafilepath=None, -): - """Set up an ahab in Signify mode""" - - agency = Agency( - name=name, base=base, bran=bran, configFile=configFile, configDir=configDir - ) - bootApp = falcon.App( - middleware=falcon.CORSMiddleware( - allow_origins="*", - allow_credentials="*", - expose_headers=[ - "cesr-attachment", - "cesr-date", - "content-type", - "signature", - "signature-input", - "signify-resource", - "signify-timestamp", - ], - ) - ) +def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=None, configDir=None, + keypath=None, certpath=None, cafilepath=None): + """ Set up an ahab in Signify mode """ + + agency = Agency(name=name, base=base, bran=bran, configFile=configFile, configDir=configDir) + bootApp = falcon.App(middleware=falcon.CORSMiddleware( + allow_origins='*', allow_credentials='*', + expose_headers=['cesr-attachment', 'cesr-date', 'content-type', 'signature', 'signature-input', + 'signify-resource', 'signify-timestamp'])) bootServer = createHttpServer(bootPort, bootApp, keypath, certpath, cafilepath) if not bootServer.reopen(): @@ -107,28 +72,13 @@ def setup( # Create Authenticater for verifying signatures on all requests authn = Authenticater(agency=agency) - app = falcon.App( - middleware=falcon.CORSMiddleware( - allow_origins="*", - allow_credentials="*", - expose_headers=[ - "cesr-attachment", - "cesr-date", - "content-type", - "signature", - "signature-input", - "signify-resource", - "signify-timestamp", - ], - ) - ) + app = falcon.App(middleware=falcon.CORSMiddleware( + allow_origins='*', allow_credentials='*', + expose_headers=['cesr-attachment', 'cesr-date', 'content-type', 'signature', 'signature-input', + 'signify-resource', 'signify-timestamp'])) if os.getenv("KERI_AGENT_CORS", "false").lower() in ("true", "1"): app.add_middleware(middleware=httping.HandleCORS()) - app.add_middleware( - authing.SignatureValidationComponent( - agency=agency, authn=authn, allowed=["/agent"] - ) - ) + app.add_middleware(authing.SignatureValidationComponent(agency=agency, authn=authn, allowed=["/agent"])) app.req_options.media_handlers.update(media.Handlers()) app.resp_options.media_handlers.update(media.Handlers()) @@ -148,21 +98,10 @@ def setup( ipexing.loadEnds(app=app) if httpPort: - happ = falcon.App( - middleware=falcon.CORSMiddleware( - allow_origins="*", - allow_credentials="*", - expose_headers=[ - "cesr-attachment", - "cesr-date", - "content-type", - "signature", - "signature-input", - "signify-resource", - "signify-timestamp", - ], - ) - ) + happ = falcon.App(middleware=falcon.CORSMiddleware( + allow_origins='*', allow_credentials='*', + expose_headers=['cesr-attachment', 'cesr-date', 'content-type', 'signature', 'signature-input', + 'signify-resource', 'signify-timestamp'])) happ.req_options.media_handlers.update(media.Handlers()) happ.resp_options.media_handlers.update(media.Handlers()) @@ -178,9 +117,7 @@ def setup( swagsink = http.serving.StaticSink(staticDirPath="./static") happ.add_sink(swagsink, prefix="/swaggerui") - specEnd = AgentSpecResource( - app=app, title="KERIA Interactive Web Interface API" - ) + specEnd = AgentSpecResource(app=app, title='KERIA Interactive Web Interface API') specEnd.addRoutes(happ) happ.add_route("/spec.yaml", specEnd) @@ -202,13 +139,11 @@ def createHttpServer(port, app, keypath=None, certpath=None, cafilepath=None): hio.core.http.Server """ if keypath is not None and certpath is not None and cafilepath is not None: - servant = tcp.ServerTls( - certify=False, - keypath=keypath, - certpath=certpath, - cafilepath=cafilepath, - port=port, - ) + servant = tcp.ServerTls(certify=False, + keypath=keypath, + certpath=certpath, + cafilepath=cafilepath, + port=port) server = http.Server(port=port, app=app, servant=servant) else: server = http.Server(port=port, app=app) @@ -221,9 +156,7 @@ class Agency(doing.DoDoer): """ - def __init__( - self, name, bran, base="", configFile=None, configDir=None, adb=None, temp=False - ): + def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=None, temp=False): self.name = name self.base = base self.bran = bran @@ -232,26 +165,23 @@ def __init__( self.configDir = configDir self.cf = None if self.configFile is not None: # Load config file if creating database - self.cf = configing.Configer( - name=self.configFile, - base="", - headDirPath=self.configDir, - temp=False, - reopen=True, - clear=False, - ) + self.cf = configing.Configer(name=self.configFile, + base="", + headDirPath=self.configDir, + temp=False, + reopen=True, + clear=False) self.agents = dict() - self.adb = ( - adb - if adb is not None - else basing.AgencyBaser(name="TheAgency", base=base, reopen=True, temp=temp) - ) + self.adb = adb if adb is not None else basing.AgencyBaser(name="TheAgency", base=base, reopen=True, temp=temp) super(Agency, self).__init__(doers=[], always=True) def create(self, caid, salt=None): - ks = keeping.Keeper(name=caid, base=self.base, temp=self.temp, reopen=True) + ks = keeping.Keeper(name=caid, + base=self.base, + temp=self.temp, + reopen=True) cf = None if self.cf is not None: # Load config file if creating database @@ -261,46 +191,30 @@ def create(self, caid, salt=None): data[f"agent-{caid}"] = curls del data["keria"] - cf = configing.Configer( - name=f"{caid}", - base="", - human=False, - temp=self.temp, - reopen=True, - clear=False, - ) + cf = configing.Configer(name=f"{caid}", + base="", + human=False, + temp=self.temp, + reopen=True, + clear=False) cf.put(data) # Create the Hab for the Agent with only 2 AIDs - agentHby = habbing.Habery( - name=caid, - base=self.base, - bran=self.bran, - ks=ks, - cf=cf, - temp=self.temp, - salt=salt, - ) - agentHab = agentHby.makeHab( - f"agent-{caid}", ns="agent", transferable=True, delpre=caid - ) - agentRgy = Regery( - hby=agentHby, name=agentHab.name, base=self.base, temp=self.temp - ) - - agent = Agent( - agentHby, - agentRgy, - agentHab, - caid=caid, - agency=self, - configDir=self.configDir, - configFile=self.configFile, - ) - - self.adb.agnt.pin(keys=(caid,), val=coring.Prefixer(qb64=agent.pre)) - - self.adb.ctrl.pin(keys=(agent.pre,), val=coring.Prefixer(qb64=caid)) + agentHby = habbing.Habery(name=caid, base=self.base, bran=self.bran, ks=ks, cf=cf, temp=self.temp, salt=salt) + agentHab = agentHby.makeHab(f"agent-{caid}", ns="agent", transferable=True, delpre=caid) + agentRgy = Regery(hby=agentHby, name=agentHab.name, base=self.base, temp=self.temp) + + agent = Agent(agentHby, agentRgy, agentHab, + caid=caid, + agency=self, + configDir=self.configDir, + configFile=self.configFile) + + self.adb.agnt.pin(keys=(caid,), + val=coring.Prefixer(qb64=agent.pre)) + + self.adb.ctrl.pin(keys=(agent.pre,), + val=coring.Prefixer(qb64=caid)) # add agent to cache self.agents[caid] = agent @@ -325,24 +239,19 @@ def get(self, caid): if aaid is None: return None - ks = keeping.Keeper(name=caid, base=self.base, temp=self.temp, reopen=True) + ks = keeping.Keeper(name=caid, + base=self.base, + temp=self.temp, + reopen=True) - agentHby = habbing.Habery( - name=caid, base=self.base, bran=self.bran, ks=ks, temp=self.temp - ) + agentHby = habbing.Habery(name=caid, base=self.base, bran=self.bran, ks=ks, temp=self.temp) agentHab = agentHby.habByName(f"agent-{caid}", ns="agent") if aaid.qb64 != agentHab.pre: - raise kering.ConfigurationError( - f"invalid agent aid={aaid.qb64}/{agentHab.pre} to controller aid={caid}" - ) + raise kering.ConfigurationError(f"invalid agent aid={aaid.qb64}/{agentHab.pre} to controller aid={caid}") - agentRgy = Regery( - hby=agentHby, name=agentHab.name, base=self.base, temp=self.temp - ) - agent = Agent( - hby=agentHby, rgy=agentRgy, agentHab=agentHab, agency=self, caid=caid - ) + agentRgy = Regery(hby=agentHby, name=agentHab.name, base=self.base, temp=self.temp) + agent = Agent(hby=agentHby, rgy=agentRgy, agentHab=agentHab, agency=self, caid=caid) self.agents[caid] = agent self.extend([agent]) @@ -406,24 +315,12 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): self.witq = agenting.WitnessInquisitor(hby=self.hby) self.witPub = agenting.WitnessPublisher(hby=self.hby) self.witDoer = agenting.WitnessReceiptor(hby=self.hby) + self.witSubmitDoer = agenting.WitnessReceiptor(hby=self.hby, force=True) - self.rep = storing.Respondant( - hby=hby, - cues=self.cues, - mbx=Mailboxer(name=self.hby.name, temp=self.hby.temp), - ) - - doers = [ - habbing.HaberyDoer(habery=hby), - receiptor, - self.witq, - self.witPub, - self.rep, - self.swain, - self.counselor, - self.witDoer, - *oobiery.doers, - ] + self.rep = storing.Respondant(hby=hby, cues=self.cues, mbx=Mailboxer(name=self.hby.name, temp=self.hby.temp)) + + doers = [habbing.HaberyDoer(habery=hby), receiptor, self.witq, self.witPub, self.rep, self.swain, + self.counselor, self.witDoer, *oobiery.doers] signaler = signaling.Signaler() self.notifier = Notifier(hby=hby, signaler=signaler) @@ -431,34 +328,14 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): # Initialize all the credential processors self.verifier = verifying.Verifier(hby=hby, reger=rgy.reger) - self.registrar = credentialing.Registrar( - agentHab=agentHab, - hby=hby, - rgy=rgy, - counselor=self.counselor, - witPub=self.witPub, - witDoer=self.witDoer, - verifier=self.verifier, - ) - self.credentialer = credentialing.Credentialer( - agentHab=agentHab, - hby=self.hby, - rgy=self.rgy, - registrar=self.registrar, - verifier=self.verifier, - notifier=self.notifier, - ) - - self.seeker = basing.Seeker( - name=hby.name, - db=hby.db, - reger=self.rgy.reger, - reopen=True, - temp=self.hby.temp, - ) - self.exnseeker = basing.ExnSeeker( - name=hby.name, db=hby.db, reopen=True, temp=self.hby.temp - ) + self.registrar = credentialing.Registrar(agentHab=agentHab, hby=hby, rgy=rgy, counselor=self.counselor, + witPub=self.witPub, witDoer=self.witDoer, verifier=self.verifier) + self.credentialer = credentialing.Credentialer(agentHab=agentHab, hby=self.hby, rgy=self.rgy, + registrar=self.registrar, verifier=self.verifier, + notifier=self.notifier) + + self.seeker = basing.Seeker(name=hby.name, db=hby.db, reger=self.rgy.reger, reopen=True, temp=self.hby.temp) + self.exnseeker = basing.ExnSeeker(name=hby.name, db=hby.db, reopen=True, temp=self.hby.temp) challengeHandler = challenging.ChallengeHandler(db=hby.db, signaler=signaler) @@ -466,38 +343,31 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): self.exc = exchanging.Exchanger(hby=hby, handlers=handlers) grouping.loadHandlers(exc=self.exc, mux=self.mux) protocoling.loadHandlers(hby=self.hby, exc=self.exc, notifier=self.notifier) - self.submitter = Submitter(hby=hby, submits=self.submits, witRec=self.witDoer) - self.monitor = longrunning.Monitor( - hby=hby, - swain=self.swain, - counselor=self.counselor, - temp=hby.temp, - registrar=self.registrar, - credentialer=self.credentialer, - submitter=self.submitter, - exchanger=self.exc, - ) + self.submitter = Submitter(hby=hby, submits=self.submits, witRec=self.witSubmitDoer) + self.monitor = longrunning.Monitor(hby=hby, swain=self.swain, counselor=self.counselor, temp=hby.temp, + registrar=self.registrar, credentialer=self.credentialer, submitter=self.submitter, exchanger=self.exc) self.rvy = routing.Revery(db=hby.db, cues=self.cues) - self.kvy = eventing.Kevery( - db=hby.db, lax=True, local=False, rvy=self.rvy, cues=self.cues - ) + self.kvy = eventing.Kevery(db=hby.db, + lax=True, + local=False, + rvy=self.rvy, + cues=self.cues) self.kvy.registerReplyRoutes(router=self.rvy.rtr) - self.tvy = Tevery( - reger=self.verifier.reger, db=hby.db, local=False, cues=self.cues - ) + self.tvy = Tevery(reger=self.verifier.reger, + db=hby.db, + local=False, + cues=self.cues) self.tvy.registerReplyRoutes(router=self.rvy.rtr) - self.parser = parsing.Parser( - framed=True, - kvy=self.kvy, - tvy=self.tvy, - exc=self.exc, - rvy=self.rvy, - vry=self.verifier, - local=True, - ) # disable misfit escrow until we can add another parser for remote. + self.parser = parsing.Parser(framed=True, + kvy=self.kvy, + tvy=self.tvy, + exc=self.exc, + rvy=self.rvy, + vry=self.verifier, + local=True) # disable misfit escrow until we can add another parser for remote. doers.extend([ Initer(agentHab=agentHab, caid=caid, tock=self.tocks.get("initer", 0.0)), @@ -505,9 +375,9 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): tock=self.tocks.get("querier", 0.0)), Escrower(kvy=self.kvy, rgy=self.rgy, rvy=self.rvy, tvy=self.tvy, exc=self.exc, vry=self.verifier, registrar=self.registrar, credentialer=self.credentialer, tock=self.tocks.get("escrower", 0.0)), - ParserDoer(kvy=self.kvy, parser=self.parser), - Witnesser(receiptor=receiptor, witners=self.witners), - Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors), + ParserDoer(kvy=self.kvy, parser=self.parser, tock=self.tocks.get("parser", 0.0)), + Witnesser(receiptor=receiptor, witners=self.witners, tock=self.tocks.get("witnesser", 0.0)), + Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, tock=self.tocks.get("delegator", 0.0)), ExchangeSender(hby=hby, agentHab=agentHab, exc=self.exc, exchanges=self.exchanges, tock=self.tocks.get("exchangeSender", 0.0)), Granter(hby=hby, rgy=rgy, agentHab=agentHab, exc=self.exc, grants=self.grants, @@ -563,9 +433,7 @@ def __init__(self, kvy, parser, tock=0.0): def recur(self, tyme=None): if self.parser.ims: - logger.info( - "Agent %s received:\n%s\n...\n", self.kvy, self.parser.ims[:1024] - ) + logger.info("Agent %s received:\n%s\n...\n", self.kvy, self.parser.ims[:1024]) done = yield from self.parser.parsator() # process messages continuously return done # should never get here except forced close @@ -585,7 +453,7 @@ def recur(self, tyme=None): serder = msg["serder"] # If we are a rotation event, may need to catch new witnesses up to current key state - if serder.ked["t"] in (Ilks.rot, Ilks.drt): + if serder.ked['t'] in (Ilks.rot, Ilks.drt): adds = serder.ked["ba"] for wit in adds: yield from self.receiptor.catchup(serder.pre, wit) @@ -626,7 +494,7 @@ def __init__(self, hby, agentHab, exc, exchanges, tock=0.0): def recur(self, tyme, deeds=None): if self.exchanges: msg = self.exchanges.popleft() - said = msg["said"] + said = msg['said'] if not self.exc.complete(said=said): self.exchanges.append(msg) return super(ExchangeSender, self).recur(tyme, deeds) @@ -635,17 +503,16 @@ def recur(self, tyme, deeds=None): pre = msg["pre"] rec = msg["rec"] - topic = msg["topic"] + topic = msg['topic'] hab = self.hby.habs[pre] if self.exc.lead(hab, said=said): atc = exchanging.serializeMessage(self.hby, said) - del atc[: serder.size] + del atc[:serder.size] for recp in rec: - postman = forwarding.StreamPoster( - hby=self.hby, hab=self.agentHab, recp=recp, topic=topic - ) + postman = forwarding.StreamPoster(hby=self.hby, hab=self.agentHab, recp=recp, topic=topic) try: - postman.send(serder=serder, attachment=atc) + postman.send(serder=serder, + attachment=atc) except kering.ValidationError: logger.info(f"unable to send to recipient={recp}") else: @@ -669,7 +536,7 @@ def __init__(self, hby, rgy, agentHab, exc, grants, tock=0.0): def recur(self, tyme, deeds=None): if self.grants: msg = self.grants.popleft() - said = msg["said"] + said = msg['said'] if not self.exc.complete(said=said): self.grants.append(msg) return super(Granter, self).recur(tyme, deeds) @@ -681,18 +548,14 @@ def recur(self, tyme, deeds=None): hab = self.hby.habs[pre] if self.exc.lead(hab, said=said): for recp in rec: - postman = forwarding.StreamPoster( - hby=self.hby, hab=self.agentHab, recp=recp, topic="credential" - ) + postman = forwarding.StreamPoster(hby=self.hby, hab=self.agentHab, recp=recp, topic="credential") try: - credSaid = serder.ked["e"]["acdc"]["d"] + credSaid = serder.ked['e']['acdc']['d'] creder = self.rgy.reger.creds.get(keys=(credSaid,)) sendArtifacts(self.hby, self.rgy.reger, postman, creder, recp) sources = self.rgy.reger.sources(self.hby.db, creder) for source, atc in sources: - sendArtifacts( - self.hby, self.rgy.reger, postman, source, recp - ) + sendArtifacts(self.hby, self.rgy.reger, postman, source, recp) postman.send(serder=source, attachment=atc) except kering.ValidationError: @@ -721,29 +584,27 @@ def __init__(self, hby, witq, psr, agentHab, exc, admits, tock=0.0): def recur(self, tyme): if self.admits: msg = self.admits.popleft() - said = msg["said"] + said = msg['said'] if not self.exc.complete(said=said): self.admits.append(msg) return False admit, _ = exchanging.cloneMessage(self.hby, said) - if "p" not in admit.ked or not admit.ked["p"]: + if 'p' not in admit.ked or not admit.ked['p']: print(f"Invalid admit message={admit.ked}, no grant listed") return False - grant, pathed = exchanging.cloneMessage(self.hby, admit.ked["p"]) + grant, pathed = exchanging.cloneMessage(self.hby, admit.ked['p']) - embeds = grant.ked["e"] + embeds = grant.ked['e'] acdc = embeds["acdc"] - issr = acdc["i"] + issr = acdc['i'] # Lets get the latest KEL and Registry if needed self.witq.query(hab=self.agentHab, pre=issr) if "ri" in acdc: - self.witq.telquery( - hab=self.agentHab, pre=issr, ri=acdc["ri"], i=acdc["d"] - ) + self.witq.telquery(hab=self.agentHab, pre=issr, ri=acdc["ri"], i=acdc["d"]) for label in ("anc", "iss", "acdc"): ked = embeds[label] @@ -799,7 +660,7 @@ def recur(self, tyme=None): self.cues.append(cue) return False elif cue["kin"] == "query": - self.queries.append(cue["q"]) + self.queries.append(cue['q']) return False else: self.cues.append(cue) @@ -814,7 +675,7 @@ def __init__(self, agentHab, caid, tock=0.0): super(Initer, self).__init__(tock=self.tock) def recur(self, tyme): - """Prints Agent name and prefix""" + """ Prints Agent name and prefix """ if not self.agentHab.inited: return False @@ -833,7 +694,7 @@ def __init__(self, hby, agentHab, counselor, groups, tock=0.0): super(GroupRequester, self).__init__(tock=self.tock) def recur(self, tyme): - """Checks cue for group proceccing requests and processes any with Counselor""" + """ Checks cue for group proceccing requests and processes any with Counselor """ if self.groups: msg = self.groups.popleft() serder = msg["serder"] @@ -843,9 +704,7 @@ def recur(self, tyme): prefixer = coring.Prefixer(qb64=serder.pre) seqner = coring.Seqner(sn=serder.sn) saider = coring.Saider(qb64=serder.said) - self.counselor.start( - ghab=ghab, prefixer=prefixer, seqner=seqner, saider=saider - ) + self.counselor.start(ghab=ghab, prefixer=prefixer, seqner=seqner, saider=saider) return False @@ -861,7 +720,7 @@ def __init__(self, hby, agentHab, queries, kvy, tock=0.0): super(Querier, self).__init__(always=True, tock=self.tock) def recur(self, tyme, deeds=None): - """Processes query reqests submitting any on the cue""" + """ Processes query reqests submitting any on the cue""" if self.queries: msg = self.queries.popleft() if "pre" not in msg: @@ -870,21 +729,15 @@ def recur(self, tyme, deeds=None): pre = msg["pre"] if "sn" in msg: - sn = int(msg["sn"], 16) - seqNoDo = querying.SeqNoQuerier( - hby=self.hby, hab=self.agentHab, pre=pre, sn=sn - ) + sn = int(msg['sn'], 16) + seqNoDo = querying.SeqNoQuerier(hby=self.hby, hab=self.agentHab, pre=pre, sn=sn) self.extend([seqNoDo]) elif "anchor" in msg: - anchor = msg["anchor"] - anchorDo = querying.AnchorQuerier( - hby=self.hby, hab=self.agentHab, pre=pre, anchor=anchor - ) + anchor = msg['anchor'] + anchorDo = querying.AnchorQuerier(hby=self.hby, hab=self.agentHab, pre=pre, anchor=anchor) self.extend([anchorDo]) else: - qryDo = querying.QueryDoer( - hby=self.hby, hab=self.agentHab, pre=pre, kvy=self.kvy - ) + qryDo = querying.QueryDoer(hby=self.hby, hab=self.agentHab, pre=pre, kvy=self.kvy) self.extend([qryDo]) return super(Querier, self).recur(tyme, deeds) @@ -892,7 +745,7 @@ def recur(self, tyme, deeds=None): class Escrower(doing.Doer): def __init__(self, kvy, rgy, rvy, tvy, exc, vry, registrar, credentialer, tock=0.0): - """Recuring process or escrows for all components in an Agent + """ Recuring process or escrows for all components in an Agent Parameters: kvy (Kevery): @@ -917,7 +770,7 @@ def __init__(self, kvy, rgy, rvy, tvy, exc, vry, registrar, credentialer, tock=0 super(Escrower, self).__init__(tock=self.tock) def recur(self, tyme): - """Process all escrows once per loop.""" + """ Process all escrows once per loop. """ self.kvy.processEscrows() self.kvy.processEscrowDelegables() self.rgy.processEscrows() @@ -931,51 +784,6 @@ def recur(self, tyme): return False -class Submitter(doing.DoDoer): - def __init__(self, hby, submits, witRec): - """ - Process to re-submit the last event from the KEL to the witnesses for receipts and to propogate it to each witness - """ - self.hby = hby - self.submits = submits - self.witRec = witRec - self.origForce = witRec.force - - super(Submitter, self).__init__(always=True) - - def recur(self, tyme, deeds=None): - """Processes submit reqests submitting any on the cue""" - if self.submits: - msg = self.submits.popleft() - alias = msg["alias"] - hab = self.hby.habByName(name=alias) - sn = hab.kever.sn - if hab and hab.kever.wits: - auths = {} - if hasattr(msg, "code"): - code = msg["code"] - if code: - for wit in hab.kever.wits: - auths[wit] = f"{code}#{helping.nowIso8601()}" - witDoer = self.witRec - witDoer.force = True - self.extend([witDoer]) - print("Re-submit waiting for witness receipts...") - witDoer.msgs.append(dict(pre=hab.pre, sn=sn)) - - else: - for doer in self.doers: - if doer.cues: - cue = doer.cues.popleft() - - if len(doer.cues) == 0: - print("Re-submit received all witness receipts for", cue["pre"]) - doer.force = self.origForce - self.doers.remove(doer) - - return super(Submitter, self).recur(tyme, deeds) - - def loadEnds(app): opColEnd = longrunning.OperationCollectionEnd() app.add_route("/operations", opColEnd) @@ -998,10 +806,10 @@ def loadEnds(app): class BootEnd: - """Resource class for creating datastore in cloud ahab""" + """ Resource class for creating datastore in cloud ahab """ def __init__(self, agency): - """Provides endpoints for initializing and unlocking an agent + """ Provides endpoints for initializing and unlocking an agent Parameters: agency (Agency): Agency for managing agents @@ -1011,7 +819,7 @@ def __init__(self, agency): self.agency = agency def on_post(self, req, rep): - """Inception event POST endpoint + """ Inception event POST endpoint Give me a new Agent. Create Habery using ctrlPRE as database name, agentHab that anchors the caid and returns the KEL of agentHAB Stores ControllerPRE -> AgentPRE in database @@ -1024,46 +832,34 @@ def on_post(self, req, rep): body = req.get_media() if "icp" not in body: - raise falcon.HTTPBadRequest( - title="invalid inception", - description=f'required field "icp" missing from body', - ) + raise falcon.HTTPBadRequest(title="invalid inception", + description=f'required field "icp" missing from body') icp = serdering.SerderKERI(sad=body["icp"]) if "sig" not in body: - raise falcon.HTTPBadRequest( - title="invalid inception", - description=f'required field "sig" missing from body', - ) + raise falcon.HTTPBadRequest(title="invalid inception", + description=f'required field "sig" missing from body') siger = core.Siger(qb64=body["sig"]) caid = icp.pre if self.agency.get(caid=caid) is not None: - raise falcon.HTTPBadRequest( - title="agent already exists", - description=f"agent for controller {caid} already exists", - ) + raise falcon.HTTPBadRequest(title="agent already exists", + description=f"agent for controller {caid} already exists") agent = self.agency.create(caid=caid) try: - ctrlHab = agent.hby.makeSignifyHab( - name=agent.caid, ns="agent", serder=icp, sigers=[siger] - ) + ctrlHab = agent.hby.makeSignifyHab(name=agent.caid, ns="agent", serder=icp, sigers=[siger]) except Exception: self.agency.delete(agent) - raise falcon.HTTPBadRequest( - title="invalid inception", - description=f"invalid icp event for caid {agent.caid}", - ) + raise falcon.HTTPBadRequest(title="invalid inception", + description=f'invalid icp event for caid {agent.caid}') if ctrlHab.pre != agent.caid: self.agency.delete(agent) - raise falcon.HTTPBadRequest( - title="invalid inception", - description=f"invalid icp event for caid {agent.caid}", - ) + raise falcon.HTTPBadRequest(title="invalid inception", + description=f'invalid icp event for caid {agent.caid}') # Client is requesting that the Agent track the Salty parameters if Algos.salty in body: @@ -1076,47 +872,28 @@ def on_post(self, req, rep): ncodes = httping.getRequiredParam(salt, "ncodes") mgr = agent.mgr.get(algo=Algos.salty) - mgr.incept( - agent.caid, - icodes=icodes, - ncodes=ncodes, - sxlt=sxlt, - pidx=pidx, - kidx=0, - stem=stem, - tier=tier, - transferable=True, - ) + mgr.incept(agent.caid, icodes=icodes, ncodes=ncodes, sxlt=sxlt, pidx=pidx, kidx=0, stem=stem, tier=tier, + transferable=True) elif Algos.randy in body: rand = body[Algos.randy] if "pris" not in rand: - raise falcon.HTTPBadRequest( - title="invalid inception", - description=f'required field "pris" missing from body.rand', - ) + raise falcon.HTTPBadRequest(title="invalid inception", + description=f'required field "pris" missing from body.rand') pris = rand["pris"] if "nxts" not in rand: - raise falcon.HTTPBadRequest( - title="invalid inception", - description=f'required field "nxts" missing from body.rand', - ) + raise falcon.HTTPBadRequest(title="invalid inception", + description=f'required field "nxts" missing from body.rand') nxts = rand["nxts"] mgr = agent.mgr.get(algo=Algos.randy) - mgr.incept( - agent.caid, - verfers=ctrlHab.kever.verfers, - digers=ctrlHab.kever.digers, - prxs=pris, - nxts=nxts, - ) + mgr.incept(agent.caid, verfers=ctrlHab.kever.verfers, + digers=ctrlHab.kever.digers, + prxs=pris, nxts=nxts) elif Algos.group in body: - raise falcon.HTTPBadRequest( - description="multisig groups not supported as agent controller" - ) + raise falcon.HTTPBadRequest(description="multisig groups not supported as agent controller") rep.status = falcon.HTTP_202 rep.data = json.dumps(asdict(agent.agentHab.kever.state())).encode("utf-8") @@ -1224,7 +1001,7 @@ def on_get(req, rep): raise falcon.HTTPInternalServerError(f"Missing event for dig={dig}.") serder = serdering.SerderKERI(raw=bytes(raw)) - atc = raw[serder.size :] + atc = raw[serder.size:] events.append(dict(ked=serder.ked, atc=atc.decode("utf-8"))) rep.status = falcon.HTTP_200 @@ -1235,11 +1012,12 @@ def on_get(req, rep): class OOBICollectionEnd: def __init__(self): - """Create OOBI Collection endpoint instance""" + """ Create OOBI Collection endpoint instance + """ @staticmethod def on_post(req, rep): - """Resolve OOBI endpoint. + """ Resolve OOBI endpoint. Parameters: req: falcon.Request HTTP request @@ -1288,19 +1066,13 @@ def on_post(req, rep): agent.hby.db.oobis.pin(keys=(oobi,), val=obr) elif "rpy" in body: - raise falcon.HTTPNotImplemented( - description="'rpy' support not implemented yet" - ) + raise falcon.HTTPNotImplemented(description="'rpy' support not implemented yet") else: - raise falcon.HTTPBadRequest( - description="invalid OOBI request body, either 'rpy' or 'url' is required" - ) + raise falcon.HTTPBadRequest(description="invalid OOBI request body, either 'rpy' or 'url' is required") oid = Salter().qb64 - op = agent.monitor.submit( - oid, longrunning.OpTypes.oobi, metadata=dict(oobi=oobi) - ) + op = agent.monitor.submit(oid, longrunning.OpTypes.oobi, metadata=dict(oobi=oobi)) rep.status = falcon.HTTP_202 rep.content_type = "application/json" @@ -1311,7 +1083,7 @@ class OobiResourceEnd: @staticmethod def on_get(req, rep, alias): - """OOBI GET endpoint + """ OOBI GET endpoint Parameters: req: falcon.Request HTTP request @@ -1356,58 +1128,37 @@ def on_get(req, rep, alias): if role in (kering.Roles.witness,): # Fetch URL OOBIs for all witnesses oobis = [] for wit in hab.kever.wits: - urls = hab.fetchUrls( - eid=wit, scheme=kering.Schemes.http - ) or hab.fetchUrls(eid=wit, scheme=kering.Schemes.https) + urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http) or hab.fetchUrls(eid=wit, + scheme=kering.Schemes.https) if not urls: - raise falcon.HTTPNotFound( - description=f"unable to query witness {wit}, no http endpoint" - ) - - url = ( - urls[kering.Schemes.http] - if kering.Schemes.http in urls - else urls[kering.Schemes.https] - ) + raise falcon.HTTPNotFound(description=f"unable to query witness {wit}, no http endpoint") + + url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https] up = urlparse(url) oobis.append(urljoin(up.geturl(), f"/oobi/{hab.pre}/witness/{wit}")) res["oobis"] = oobis elif role in (kering.Roles.controller,): # Fetch any controller URL OOBIs oobis = [] - urls = hab.fetchUrls( - eid=hab.pre, scheme=kering.Schemes.http - ) or hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.https) + urls = hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.http) or hab.fetchUrls(eid=hab.pre, + scheme=kering.Schemes.https) if not urls: - raise falcon.HTTPNotFound( - description=f"unable to query controller {hab.pre}, no http endpoint" - ) - - url = ( - urls[kering.Schemes.http] - if kering.Schemes.http in urls - else urls[kering.Schemes.https] - ) + raise falcon.HTTPNotFound(description=f"unable to query controller {hab.pre}, no http endpoint") + + url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https] up = urlparse(url) oobis.append(urljoin(up.geturl(), f"/oobi/{hab.pre}/controller")) res["oobis"] = oobis elif role in (kering.Roles.agent,): oobis = [] - roleUrls = hab.fetchRoleUrls( - hab.pre, scheme=kering.Schemes.http, role=kering.Roles.agent - ) or hab.fetchRoleurls( - hab.pre, scheme=kering.Schemes.https, role=kering.Roles.agent - ) + roleUrls = hab.fetchRoleUrls(hab.pre, scheme=kering.Schemes.http, + role=kering.Roles.agent) or hab.fetchRoleurls(hab.pre, + scheme=kering.Schemes.https, + role=kering.Roles.agent) if not roleUrls: - raise falcon.HTTPNotFound( - description=f"unable to query controller {hab.pre}, no http endpoint" - ) - - for eid, urls in roleUrls["agent"].items(): - url = ( - urls[kering.Schemes.http] - if kering.Schemes.http in urls - else urls[kering.Schemes.https] - ) + raise falcon.HTTPNotFound(description=f"unable to query controller {hab.pre}, no http endpoint") + + for eid, urls in roleUrls['agent'].items(): + url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https] up = urlparse(url) oobis.append(urljoin(up.geturl(), f"/oobi/{hab.pre}/agent/{eid}")) res["oobis"] = oobis @@ -1473,7 +1224,7 @@ def on_post(req, rep): elif "sn" in body: meta["sn"] = body["sn"] else: # Must reset key state so we know when we have a new update. - for keys, saider in agent.hby.db.knas.getItemIter(keys=(pre,)): + for (keys, saider) in agent.hby.db.knas.getItemIter(keys=(pre,)): agent.hby.db.knas.rem(keys) agent.hby.db.ksns.rem((saider.qb64,)) agent.hby.db.ksns.rem((saider.qb64,)) @@ -1485,3 +1236,47 @@ def on_post(req, rep): rep.status = falcon.HTTP_202 rep.content_type = "application/json" rep.data = op.to_json().encode("utf-8") + +class Submitter(doing.DoDoer): + def __init__(self, hby, submits, witRec): + """ + Process to re-submit the last event from the KEL to the witnesses for receipts and to propogate it to each witness + """ + self.hby = hby + self.submits = submits + self.witRec = witRec + self.origForce = witRec.force + + super(Submitter, self).__init__(always=True) + + def recur(self, tyme, deeds=None): + """Processes submit reqests submitting any on the cue""" + if self.submits: + msg = self.submits.popleft() + alias = msg["alias"] + hab = self.hby.habByName(name=alias) + sn = hab.kever.sn + if hab and hab.kever.wits: + auths = {} + if hasattr(msg, "code"): + code = msg["code"] + if code: + for wit in hab.kever.wits: + auths[wit] = f"{code}#{helping.nowIso8601()}" + witDoer = self.witRec + witDoer.force = True + self.extend([witDoer]) + print("Re-submit waiting for witness receipts...") + witDoer.msgs.append(dict(pre=hab.pre, sn=sn)) + + else: + for doer in self.doers: + if doer.cues: + cue = doer.cues.popleft() + + if len(doer.cues) == 0: + print("Re-submit received all witness receipts for", cue["pre"]) + doer.force = self.origForce + self.doers.remove(doer) + + return super(Submitter, self).recur(tyme, deeds) \ No newline at end of file