From dbb56e960c98872bdf0b0fd2dffdca03ab96f317 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Fri, 7 Jul 2023 09:50:50 -0500 Subject: [PATCH 01/17] add interceptor --- setup.py | 1 + src/keria/app/agenting.py | 57 +++++++++++++++++++++++------ src/keria/app/cli/commands/start.py | 23 ++++++++++-- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 7c856d84..408ba659 100644 --- a/setup.py +++ b/setup.py @@ -83,6 +83,7 @@ 'http_sfv>=0.9.8', 'dataclasses_json>=0.5.7', 'apispec>=6.3.0', + 'requests>=2.25.1', ], extras_require={ # eg: diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 3bbccd87..e804f13a 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -15,6 +15,7 @@ from ordered_set import OrderedSet as oset import falcon +import requests from falcon import media from hio.base import doing from hio.core import http @@ -45,10 +46,10 @@ logger = ogler.getLogger() -def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=None, configDir=None): +def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=None, configDir=None,interceptor_webhook=None, interceptor_headers=None): """ Set up an ahab in Signify mode """ - agency = Agency(name=name, base=base, bran=bran, configFile=configFile, configDir=configDir) + agency = Agency(name=name, base=base, bran=bran, configFile=configFile, configDir=configDir,interceptor_webhook=None, interceptor_headers=None) bootApp = falcon.App(middleware=falcon.CORSMiddleware( allow_origins='*', allow_credentials='*', expose_headers=['cesr-attachment', 'cesr-date', 'content-type', 'signature', 'signature-input', @@ -107,7 +108,7 @@ def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=No 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,interceptor_webhook=None, interceptor_headers=None): self.name = name self.base = base self.bran = bran @@ -115,6 +116,8 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.configFile = configFile self.configDir = configDir self.cf = None + self.interceptor_webhook = interceptor_webhook + self.interceptor_headers = interceptor_headers if self.configFile is not None: # Load config file if creating database self.cf = configing.Configer(name=self.configFile, base="", @@ -159,7 +162,9 @@ def create(self, caid): caid=caid, agency=self, configDir=self.configDir, - configFile=self.configFile) + configFile=self.configFile, + interceptor_webhook, + interceptor_headers) self.adb.agnt.pin(keys=(caid,), val=coring.Prefixer(qb64=agent.pre)) @@ -232,12 +237,14 @@ class Agent(doing.DoDoer): """ - def __init__(self, hby, rgy, agentHab, agency, caid, **opts): + def __init__(self, hby, rgy, agentHab, agency, caid, interceptor_webhook=None, interceptor_headers=None, **opts): self.hby = hby self.rgy = rgy self.agentHab = agentHab self.agency = agency self.caid = caid + if interceptor_webhook is not None: + self.interceptor = Interceptor(interceptor_webhook, interceptor_headers) self.swain = delegating.Boatswain(hby=hby) self.counselor = Counselor(hby=hby) @@ -313,10 +320,10 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): 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), Messager(kvy=self.kvy, parser=self.parser), - Witnesser(receiptor=receiptor, witners=self.witners), - Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors), + Witnesser(receiptor=receiptor, witners=self.witners, interceptor=self.interceptor), + Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, interceptor=self.interceptor), GroupRequester(hby=hby, agentHab=agentHab, postman=self.postman, counselor=self.counselor, - groups=self.groups), + groups=self.groups, interceptor=self.interceptor), ]) super(Agent, self).__init__(doers=doers, always=True, **opts) @@ -349,6 +356,19 @@ def inceptExtern(self, pre, verfers, digers, **kwargs): self.agency.incept(self.caid, pre) +class Interceptor: + + def __init__(self, webhook, headers): + self.webhook = webhook + self.headers = headers + + def push(self, data): + try: + resp = requests.post(self.webhook, data=json.dumps(data), headers=self.headers) + if resp.status_code != 200: + logger.info('Error in pushing data to webhook') + except Exception as e: + logger.info('Error in pushing data to webhook') class Messager(doing.Doer): @@ -366,9 +386,10 @@ def recur(self, tyme=None): class Witnesser(doing.Doer): - def __init__(self, receiptor, witners): + def __init__(self, receiptor, witners, interceptor=None): self.receiptor = receiptor self.witners = witners + self.interceptor = interceptor super(Witnesser, self).__init__() def recur(self, tyme=None): @@ -376,7 +397,9 @@ def recur(self, tyme=None): if self.witners: msg = self.witners.popleft() serder = msg["serder"] - + if self.interceptor: + data = serder.pretty() + self.interceptor.push(data) # 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): adds = serder.ked["ba"] @@ -390,15 +413,18 @@ def recur(self, tyme=None): class Delegator(doing.Doer): - def __init__(self, agentHab, swain, anchors): + def __init__(self, agentHab, swain, anchors, interceptor=None): self.agentHab = agentHab self.swain = swain self.anchors = anchors + self.interceptor = interceptor super(Delegator, self).__init__() def recur(self, tyme=None): if self.anchors: msg = self.anchors.popleft() + if self.interceptor: + self.interceptor.push(msg) sn = msg["sn"] if "sn" in msg else None self.swain.delegation(pre=msg["pre"], sn=sn, proxy=self.agentHab) @@ -422,12 +448,13 @@ def recur(self, tyme): class GroupRequester(doing.Doer): - def __init__(self, hby, agentHab, postman, counselor, groups): + def __init__(self, hby, agentHab, postman, counselor, groups, interceptor=None): self.hby = hby self.agentHab = agentHab self.postman = postman self.counselor = counselor self.groups = groups + self.interceptor = interceptor super(GroupRequester, self).__init__() @@ -438,6 +465,12 @@ def recur(self, tyme): serder = msg["serder"] sigers = msg["sigers"] + if self.interceptor: + data = {} + if 'serder' in msg: + data['serder'] = serder.pretty() + self.interceptor.push(data) + ghab = self.hby.habs[serder.pre] if "smids" in msg: smids = msg['smids'] diff --git a/src/keria/app/cli/commands/start.py b/src/keria/app/cli/commands/start.py index 92fd3e30..b35bc787 100644 --- a/src/keria/app/cli/commands/start.py +++ b/src/keria/app/cli/commands/start.py @@ -7,6 +7,7 @@ """ import argparse import logging +import json from keri import __version__ from keri import help @@ -55,6 +56,18 @@ default=None, help="directory override for configuration data") +parser.add_argument("--interceptor-webhook", + dest="interceptor_webhook", + action="store", + default=None, + help="webhook to send intercepted messages to") + +parser.add_argument("--interceptor-headers", + dest="interceptor_headers", + action="store", + default=None, + help="headers to send with intercepted messages") + def launch(args): help.ogler.level = logging.CRITICAL @@ -72,14 +85,16 @@ def launch(args): http=int(args.http), boot=int(args.boot), configFile=args.configFile, - configDir=args.configDir) + configDir=args.configDir, + interceptor_webhook=args.interceptor_webhook, + interceptor_headers=json.loads(args.interceptor_headers)) logger.info("******* Ended Agent for %s listening: admin/%s, http/%s" ".******", args.name, args.admin, args.http) def runAgent(name="ahab", base="", bran="", admin=3901, http=3902, boot=3903, configFile=None, - configDir=None, expire=0.0): + configDir=None, expire=0.0, interceptor_webhook = None, interceptor_headers = None): """ Setup and run one witness """ @@ -90,6 +105,8 @@ def runAgent(name="ahab", base="", bran="", admin=3901, http=3902, boot=3903, co httpPort=http, bootPort=boot, configFile=configFile, - configDir=configDir)) + configDir=configDir, + interceptor_webhook=interceptor_webhook, + interceptor_headers=interceptor_headers)) directing.runController(doers=doers, expire=expire) From 2a68ce46e9115f4a734b1e148edc7f18b48d78e3 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Fri, 7 Jul 2023 17:20:45 -0500 Subject: [PATCH 02/17] fix typos --- src/keria/app/agenting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index e804f13a..3215fe75 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -49,7 +49,7 @@ def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=None, configDir=None,interceptor_webhook=None, interceptor_headers=None): """ Set up an ahab in Signify mode """ - agency = Agency(name=name, base=base, bran=bran, configFile=configFile, configDir=configDir,interceptor_webhook=None, interceptor_headers=None) + agency = Agency(name=name, base=base, bran=bran, configFile=configFile, configDir=configDir,interceptor_webhook=interceptor_webhook, interceptor_headers=interceptor_headers) bootApp = falcon.App(middleware=falcon.CORSMiddleware( allow_origins='*', allow_credentials='*', expose_headers=['cesr-attachment', 'cesr-date', 'content-type', 'signature', 'signature-input', @@ -163,8 +163,8 @@ def create(self, caid): agency=self, configDir=self.configDir, configFile=self.configFile, - interceptor_webhook, - interceptor_headers) + interceptor_webhook=self.interceptor_webhook, + interceptor_headers=self.interceptor_headers) self.adb.agnt.pin(keys=(caid,), val=coring.Prefixer(qb64=agent.pre)) From 840487f72ec16a7539ddd08fc824ee201adf92f2 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Fri, 7 Jul 2023 17:24:22 -0500 Subject: [PATCH 03/17] fix init error --- src/keria/app/agenting.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 3215fe75..d64b7dec 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -245,6 +245,8 @@ def __init__(self, hby, rgy, agentHab, agency, caid, interceptor_webhook=None, i self.caid = caid if interceptor_webhook is not None: self.interceptor = Interceptor(interceptor_webhook, interceptor_headers) + else: + self.interceptor = None self.swain = delegating.Boatswain(hby=hby) self.counselor = Counselor(hby=hby) From b57fe978cf28c8757d9947850b6ba5552640390f Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Fri, 7 Jul 2023 18:08:52 -0500 Subject: [PATCH 04/17] test interceptor --- src/keria/app/cli/commands/start.py | 6 ++---- tests/app/test_agenting.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/keria/app/cli/commands/start.py b/src/keria/app/cli/commands/start.py index b35bc787..0cd70eaa 100644 --- a/src/keria/app/cli/commands/start.py +++ b/src/keria/app/cli/commands/start.py @@ -55,13 +55,11 @@ action="store", default=None, help="directory override for configuration data") - parser.add_argument("--interceptor-webhook", dest="interceptor_webhook", action="store", default=None, - help="webhook to send intercepted messages to") - + help="webhook to send intercepted messages") parser.add_argument("--interceptor-headers", dest="interceptor_headers", action="store", @@ -87,7 +85,7 @@ def launch(args): configFile=args.configFile, configDir=args.configDir, interceptor_webhook=args.interceptor_webhook, - interceptor_headers=json.loads(args.interceptor_headers)) + interceptor_headers=json.loads(args.interceptor_headers) if args.interceptor_headers else {'Content-Type': 'application/json'}) logger.info("******* Ended Agent for %s listening: admin/%s, http/%s" ".******", args.name, args.admin, args.http) diff --git a/tests/app/test_agenting.py b/tests/app/test_agenting.py index c51e7cde..9b710cd4 100644 --- a/tests/app/test_agenting.py +++ b/tests/app/test_agenting.py @@ -8,6 +8,7 @@ import json import os import shutil +import requests import falcon from falcon import testing @@ -188,6 +189,26 @@ def test_witnesser(helpers): deeds = doist.enter(doers=[wr]) doist.recur(deeds) +def test_interceptor(monkeypatch): + def mock_post(*args, **kwargs): + class MockResponse: + def __init__(self, status_code): + self.status_code = status_code + + def json(self): + return {'key': 'value'} + + return MockResponse(200) + + monkeypatch.setattr(requests, 'post', mock_post) + interceptor = agenting.Interceptor('https://webhook.site/9a8d0e2b-8e4b-4334-9a6b-8f1a7c6b0c8c', {'content-type': 'application/json'}) + data = {'key': 'value'} + interceptor.push(data) + + assert interceptor.webhook == 'https://webhook.site/9a8d0e2b-8e4b-4334-9a6b-8f1a7c6b0c8c' + assert interceptor.headers == {'content-type': 'application/json'} + assert data == {'key': 'value'} + def test_keystate_ends(helpers): caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" From e212ef5f364a497d6054f7ed3524965e16f02f30 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Sat, 15 Jul 2023 19:12:52 -0500 Subject: [PATCH 05/17] refactor to use hio --- scripts/keri/cf/scripts.json | 0 src/keria/app/agenting.py | 75 +++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 35 deletions(-) create mode 100755 scripts/keri/cf/scripts.json diff --git a/scripts/keri/cf/scripts.json b/scripts/keri/cf/scripts.json new file mode 100755 index 00000000..e69de29b diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index d64b7dec..0df0442c 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -35,6 +35,7 @@ from keri.vdr import verifying from keri.vdr.credentialing import Regery from keri.vdr.eventing import Tevery +from keri.app import httping as khttping from . import aiding, notifying, indirecting, credentialing from .specing import AgentSpecResource @@ -116,8 +117,8 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.configFile = configFile self.configDir = configDir self.cf = None - self.interceptor_webhook = interceptor_webhook - self.interceptor_headers = interceptor_headers + self.metrics = decking.Deck() + self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.metrics) if self.configFile is not None: # Load config file if creating database self.cf = configing.Configer(name=self.configFile, base="", @@ -162,9 +163,7 @@ def create(self, caid): caid=caid, agency=self, configDir=self.configDir, - configFile=self.configFile, - interceptor_webhook=self.interceptor_webhook, - interceptor_headers=self.interceptor_headers) + configFile=self.configFile) self.adb.agnt.pin(keys=(caid,), val=coring.Prefixer(qb64=agent.pre)) @@ -237,16 +236,12 @@ class Agent(doing.DoDoer): """ - def __init__(self, hby, rgy, agentHab, agency, caid, interceptor_webhook=None, interceptor_headers=None, **opts): + def __init__(self, hby, rgy, agentHab, agency, caid, **opts): self.hby = hby self.rgy = rgy self.agentHab = agentHab self.agency = agency self.caid = caid - if interceptor_webhook is not None: - self.interceptor = Interceptor(interceptor_webhook, interceptor_headers) - else: - self.interceptor = None self.swain = delegating.Boatswain(hby=hby) self.counselor = Counselor(hby=hby) @@ -261,6 +256,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, interceptor_webhook=None, i self.anchors = decking.Deck() self.witners = decking.Deck() self.queries = decking.Deck() + self.metrics = self.agency.metrics receiptor = agenting.Receiptor(hby=hby) self.postman = forwarding.Poster(hby=hby) @@ -322,10 +318,10 @@ def __init__(self, hby, rgy, agentHab, agency, caid, interceptor_webhook=None, i 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), Messager(kvy=self.kvy, parser=self.parser), - Witnesser(receiptor=receiptor, witners=self.witners, interceptor=self.interceptor), - Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, interceptor=self.interceptor), + Witnesser(receiptor=receiptor, witners=self.witners, metrics=self.metrics), + Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, metrics=self.metrics), GroupRequester(hby=hby, agentHab=agentHab, postman=self.postman, counselor=self.counselor, - groups=self.groups, interceptor=self.interceptor), + groups=self.groups, metrics=self.metrics), ]) super(Agent, self).__init__(doers=doers, always=True, **opts) @@ -358,19 +354,31 @@ def inceptExtern(self, pre, verfers, digers, **kwargs): self.agency.incept(self.caid, pre) -class Interceptor: +class InterceptorDoer(doing.DoDoer): - def __init__(self, webhook, headers): + def __init__(self, webhook, headers, cues=None): self.webhook = webhook self.headers = headers + self.cues = cues if cues is not None else decking.Deck() + self.clienter = khttping.Clienter() + + super(InterceptorDoer, self).__init__(doers=[self.clienter], always=True) + + def recur(self, tyme, deeds=None): + if self.cues: + msg = self.cues.popleft() + # TODO: Sent the message somewhere + client = self.clienter.request("POST", self.webhook, body=msg, headers=self.headers) + while not client.responses: + yield self.tock + + rep = client.respond() + + self.clienter.remove(client) + return rep.status == 200 + + return super(InterceptorDoer, self).recur(tyme, deeds) - def push(self, data): - try: - resp = requests.post(self.webhook, data=json.dumps(data), headers=self.headers) - if resp.status_code != 200: - logger.info('Error in pushing data to webhook') - except Exception as e: - logger.info('Error in pushing data to webhook') class Messager(doing.Doer): @@ -388,10 +396,10 @@ def recur(self, tyme=None): class Witnesser(doing.Doer): - def __init__(self, receiptor, witners, interceptor=None): + def __init__(self, receiptor, witners, metrics): self.receiptor = receiptor self.witners = witners - self.interceptor = interceptor + self.metrics = metrics super(Witnesser, self).__init__() def recur(self, tyme=None): @@ -409,17 +417,18 @@ def recur(self, tyme=None): yield from self.receiptor.catchup(serder.pre, wit) yield from self.receiptor.receipt(serder.pre, serder.sn) + self.metrics.append(dict(evt="witnessing", data=dict(aid=serder.pre))) yield self.tock class Delegator(doing.Doer): - def __init__(self, agentHab, swain, anchors, interceptor=None): + def __init__(self, agentHab, swain, anchors, metrics): self.agentHab = agentHab self.swain = swain self.anchors = anchors - self.interceptor = interceptor + self.metrics = metrics super(Delegator, self).__init__() def recur(self, tyme=None): @@ -429,6 +438,7 @@ def recur(self, tyme=None): self.interceptor.push(msg) sn = msg["sn"] if "sn" in msg else None self.swain.delegation(pre=msg["pre"], sn=sn, proxy=self.agentHab) + self.metrics.append(dict(msg)) return False @@ -445,18 +455,19 @@ def recur(self, tyme): return False print(" Agent:", self.agentHab.pre, " Controller:", self.caid) + return True class GroupRequester(doing.Doer): - def __init__(self, hby, agentHab, postman, counselor, groups, interceptor=None): + def __init__(self, hby, agentHab, postman, counselor, groups, metrics): self.hby = hby self.agentHab = agentHab self.postman = postman self.counselor = counselor self.groups = groups - self.interceptor = interceptor + self.metrics = metrics super(GroupRequester, self).__init__() @@ -466,13 +477,7 @@ def recur(self, tyme): msg = self.groups.popleft() serder = msg["serder"] sigers = msg["sigers"] - - if self.interceptor: - data = {} - if 'serder' in msg: - data['serder'] = serder.pretty() - self.interceptor.push(data) - + self.metrics.append(dict(evt="group", data=dict(msg))) ghab = self.hby.habs[serder.pre] if "smids" in msg: smids = msg['smids'] From 47e9a072408a3eb44ec37fa299963d917e03ac8c Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Sat, 15 Jul 2023 19:13:43 -0500 Subject: [PATCH 06/17] remove requests dependecy --- setup.py | 1 - src/keria/app/agenting.py | 1 - 2 files changed, 2 deletions(-) diff --git a/setup.py b/setup.py index 408ba659..7c856d84 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,6 @@ 'http_sfv>=0.9.8', 'dataclasses_json>=0.5.7', 'apispec>=6.3.0', - 'requests>=2.25.1', ], extras_require={ # eg: diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 0df0442c..134f37a2 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -15,7 +15,6 @@ from ordered_set import OrderedSet as oset import falcon -import requests from falcon import media from hio.base import doing from hio.core import http From 2b6a66f54cd31fb075c7ce6bacc633f876421bb2 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Sat, 15 Jul 2023 19:14:51 -0500 Subject: [PATCH 07/17] Update test_agenting.py --- tests/app/test_agenting.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/app/test_agenting.py b/tests/app/test_agenting.py index 9b710cd4..797f72ac 100644 --- a/tests/app/test_agenting.py +++ b/tests/app/test_agenting.py @@ -8,7 +8,6 @@ import json import os import shutil -import requests import falcon from falcon import testing @@ -189,27 +188,6 @@ def test_witnesser(helpers): deeds = doist.enter(doers=[wr]) doist.recur(deeds) -def test_interceptor(monkeypatch): - def mock_post(*args, **kwargs): - class MockResponse: - def __init__(self, status_code): - self.status_code = status_code - - def json(self): - return {'key': 'value'} - - return MockResponse(200) - - monkeypatch.setattr(requests, 'post', mock_post) - interceptor = agenting.Interceptor('https://webhook.site/9a8d0e2b-8e4b-4334-9a6b-8f1a7c6b0c8c', {'content-type': 'application/json'}) - data = {'key': 'value'} - interceptor.push(data) - - assert interceptor.webhook == 'https://webhook.site/9a8d0e2b-8e4b-4334-9a6b-8f1a7c6b0c8c' - assert interceptor.headers == {'content-type': 'application/json'} - assert data == {'key': 'value'} - - def test_keystate_ends(helpers): caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" salt = b'0123456789abcdef' From 47b829f8bbb0c009112a0cc61331cef6bcca04ee Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Sat, 15 Jul 2023 19:48:21 -0500 Subject: [PATCH 08/17] clean up metrics --- src/keria/app/agenting.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 134f37a2..73970534 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -255,7 +255,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): self.anchors = decking.Deck() self.witners = decking.Deck() self.queries = decking.Deck() - self.metrics = self.agency.metrics + self.agency.metrics receiptor = agenting.Receiptor(hby=hby) self.postman = forwarding.Poster(hby=hby) @@ -312,15 +312,15 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): vry=self.verifier) doers.extend([ - Initer(agentHab=agentHab, caid=caid), + Initer(agentHab=agentHab, caid=caid, metrics = self.agency.metrics), Querier(hby=hby, agentHab=agentHab, kvy=self.kvy, queries=self.queries), 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), Messager(kvy=self.kvy, parser=self.parser), - Witnesser(receiptor=receiptor, witners=self.witners, metrics=self.metrics), - Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, metrics=self.metrics), + Witnesser(receiptor=receiptor, witners=self.witners, metrics=self.agency.metrics), + Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, metrics=self.agency.metrics), GroupRequester(hby=hby, agentHab=agentHab, postman=self.postman, counselor=self.counselor, - groups=self.groups, metrics=self.metrics), + groups=self.groups, metrics=self.agency.metrics), ]) super(Agent, self).__init__(doers=doers, always=True, **opts) @@ -360,7 +360,6 @@ def __init__(self, webhook, headers, cues=None): self.headers = headers self.cues = cues if cues is not None else decking.Deck() self.clienter = khttping.Clienter() - super(InterceptorDoer, self).__init__(doers=[self.clienter], always=True) def recur(self, tyme, deeds=None): @@ -443,18 +442,19 @@ def recur(self, tyme=None): class Initer(doing.Doer): - def __init__(self, agentHab, caid): + def __init__(self, agentHab, caid, metrics): self.agentHab = agentHab self.caid = caid + self.metrics = metrics super(Initer, self).__init__() def recur(self, tyme): """ Prints Agent name and prefix """ if not self.agentHab.inited: return False - + self.metrics.append(dict(evt="init", data=dict(aid=self.agentHab.pre))) print(" Agent:", self.agentHab.pre, " Controller:", self.caid) - + return True From 2d7a1bf5b55d6ab12a252aa9c6e779759271f2d1 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Mon, 17 Jul 2023 19:21:24 -0500 Subject: [PATCH 09/17] calling interceptor --- src/keria/app/agenting.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 73970534..b1545e5c 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -129,7 +129,7 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.agents = dict() 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) + super(Agency, self).__init__(doers=[self.interceptor], always=True) def create(self, caid): ks = keeping.Keeper(name=caid, @@ -313,6 +313,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): doers.extend([ Initer(agentHab=agentHab, caid=caid, metrics = self.agency.metrics), + self.agency.interceptor, Querier(hby=hby, agentHab=agentHab, kvy=self.kvy, queries=self.queries), 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), @@ -360,9 +361,11 @@ def __init__(self, webhook, headers, cues=None): self.headers = headers self.cues = cues if cues is not None else decking.Deck() self.clienter = khttping.Clienter() + print('InterceptorDoer') super(InterceptorDoer, self).__init__(doers=[self.clienter], always=True) def recur(self, tyme, deeds=None): + print('InterceptorDoer recur') if self.cues: msg = self.cues.popleft() # TODO: Sent the message somewhere From 2f49ed4dee6021bd2a87442db9a5c5503e5e0ed4 Mon Sep 17 00:00:00 2001 From: pfeairheller Date: Mon, 17 Jul 2023 19:37:31 -0700 Subject: [PATCH 10/17] Update to interceptor to work correctly as a DoDoer. --- src/keria/app/agenting.py | 57 ++++++++++++++++++++++---------------- src/keria/app/cli/keria.py | 5 ++-- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index b1545e5c..9d3c2cc9 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -7,6 +7,7 @@ import json import os from dataclasses import asdict +from urllib import parse from urllib.parse import urlparse from keri import kering @@ -34,7 +35,6 @@ from keri.vdr import verifying from keri.vdr.credentialing import Regery from keri.vdr.eventing import Tevery -from keri.app import httping as khttping from . import aiding, notifying, indirecting, credentialing from .specing import AgentSpecResource @@ -46,10 +46,12 @@ logger = ogler.getLogger() -def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=None, configDir=None,interceptor_webhook=None, interceptor_headers=None): +def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=None, configDir=None, + interceptor_webhook=None, interceptor_headers=None): """ Set up an ahab in Signify mode """ - agency = Agency(name=name, base=base, bran=bran, configFile=configFile, configDir=configDir,interceptor_webhook=interceptor_webhook, interceptor_headers=interceptor_headers) + agency = Agency(name=name, base=base, bran=bran, configFile=configFile, configDir=configDir, + interceptor_webhook=interceptor_webhook, interceptor_headers=interceptor_headers) bootApp = falcon.App(middleware=falcon.CORSMiddleware( allow_origins='*', allow_credentials='*', expose_headers=['cesr-attachment', 'cesr-date', 'content-type', 'signature', 'signature-input', @@ -108,7 +110,8 @@ def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=No class Agency(doing.DoDoer): - def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=None, temp=False,interceptor_webhook=None, interceptor_headers=None): + def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=None, temp=False, + interceptor_webhook=None, interceptor_headers=None): self.name = name self.base = base self.bran = bran @@ -117,7 +120,11 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.configDir = configDir self.cf = None self.metrics = decking.Deck() - self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.metrics) + doers = [] + if interceptor_webhook is not None: + self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.metrics) + doers.append(self.interceptor) + if self.configFile is not None: # Load config file if creating database self.cf = configing.Configer(name=self.configFile, base="", @@ -129,7 +136,7 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.agents = dict() self.adb = adb if adb is not None else basing.AgencyBaser(name="TheAgency", base=base, reopen=True, temp=temp) - super(Agency, self).__init__(doers=[self.interceptor], always=True) + super(Agency, self).__init__(doers=doers, always=True) def create(self, caid): ks = keeping.Keeper(name=caid, @@ -312,7 +319,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): vry=self.verifier) doers.extend([ - Initer(agentHab=agentHab, caid=caid, metrics = self.agency.metrics), + Initer(agentHab=agentHab, caid=caid, metrics=self.agency.metrics), self.agency.interceptor, Querier(hby=hby, agentHab=agentHab, kvy=self.kvy, queries=self.queries), Escrower(kvy=self.kvy, rgy=self.rgy, rvy=self.rvy, tvy=self.tvy, exc=self.exc, vry=self.verifier, @@ -354,29 +361,34 @@ def inceptExtern(self, pre, verfers, digers, **kwargs): self.agency.incept(self.caid, pre) + class InterceptorDoer(doing.DoDoer): def __init__(self, webhook, headers, cues=None): self.webhook = webhook self.headers = headers self.cues = cues if cues is not None else decking.Deck() - self.clienter = khttping.Clienter() - print('InterceptorDoer') - super(InterceptorDoer, self).__init__(doers=[self.clienter], always=True) + self.purl = parse.urlparse(webhook) + self.client = http.clienting.Client(scheme=self.purl.scheme, + hostname=self.purl.hostname, + port=self.purl.port, + portOptional=True) + clientDoer = http.clienting.ClientDoer(client=self.client) + + super(InterceptorDoer, self).__init__(doers=[clientDoer], always=True) def recur(self, tyme, deeds=None): - print('InterceptorDoer recur') if self.cues: msg = self.cues.popleft() + body = json.dumps(msg).encode("utf-8") # TODO: Sent the message somewhere - client = self.clienter.request("POST", self.webhook, body=msg, headers=self.headers) - while not client.responses: - yield self.tock - - rep = client.respond() - - self.clienter.remove(client) - return rep.status == 200 + self.client.request( + method="POST", + path=f"{self.purl.path}?{self.purl.query}", + qargs=None, + headers=self.headers, + body=body + ) return super(InterceptorDoer, self).recur(tyme, deeds) @@ -408,9 +420,7 @@ def recur(self, tyme=None): if self.witners: msg = self.witners.popleft() serder = msg["serder"] - if self.interceptor: - data = serder.pretty() - self.interceptor.push(data) + self.metrics.append(dict(evt="witnessed", ked=serder.ked)) # 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): adds = serder.ked["ba"] @@ -457,7 +467,7 @@ def recur(self, tyme): return False self.metrics.append(dict(evt="init", data=dict(aid=self.agentHab.pre))) print(" Agent:", self.agentHab.pre, " Controller:", self.caid) - + return True @@ -936,7 +946,6 @@ def on_get(req, rep, alias): rep.status = falcon.HTTP_404 return - rep.status = falcon.HTTP_200 rep.content_type = "application/json" rep.data = json.dumps(res).encode("utf-8") diff --git a/src/keria/app/cli/keria.py b/src/keria/app/cli/keria.py index 0789d073..3836435e 100644 --- a/src/keria/app/cli/keria.py +++ b/src/keria/app/cli/keria.py @@ -26,8 +26,9 @@ def main(): directing.runController(doers=doers, expire=0.0) except Exception as ex: - print(f"ERR: {ex}") - return -1 + raise ex + # print(f"ERR: {ex}") + # return -1 if __name__ == "__main__": From 2a270b4187bf56c18198e2eaf3fcaf436f07538f Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Mon, 17 Jul 2023 23:21:04 -0500 Subject: [PATCH 11/17] try getting deck into endpoints --- src/keria/app/aiding.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/keria/app/aiding.py b/src/keria/app/aiding.py index 12a03d55..2045c281 100644 --- a/src/keria/app/aiding.py +++ b/src/keria/app/aiding.py @@ -272,6 +272,10 @@ def on_post(req, rep): """ agent = req.context.agent + deserialized_media = req.get_media() + print(deserialized_media) + print(type(agent.agency.metrics)) + agent.agency.metrics.append(dict(name="identifier_update", data = deserialized_media)) try: body = req.get_media() icp = httping.getRequiredParam(body, "icp") From 2d27449c701f3665d0cc874ab2c701d3f52cd356 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Wed, 19 Jul 2023 19:02:34 -0500 Subject: [PATCH 12/17] refactor to intercepts for Deck --- .../scripts/keri/cf/demo-witness-oobis.json | 0 src/keria/app/agenting.py | 43 +++++++++---------- src/keria/app/aiding.py | 9 ++-- src/keria/app/cli/commands/start.py | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) create mode 100755 scripts/keri/cf/scripts/keri/cf/demo-witness-oobis.json diff --git a/scripts/keri/cf/scripts/keri/cf/demo-witness-oobis.json b/scripts/keri/cf/scripts/keri/cf/demo-witness-oobis.json new file mode 100755 index 00000000..e69de29b diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 9d3c2cc9..a9998e7c 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -119,10 +119,10 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.configFile = configFile self.configDir = configDir self.cf = None - self.metrics = decking.Deck() + self.intercepts = decking.Deck() doers = [] if interceptor_webhook is not None: - self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.metrics) + self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.intercepts) doers.append(self.interceptor) if self.configFile is not None: # Load config file if creating database @@ -262,7 +262,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): self.anchors = decking.Deck() self.witners = decking.Deck() self.queries = decking.Deck() - self.agency.metrics + self.agency.intercepts receiptor = agenting.Receiptor(hby=hby) self.postman = forwarding.Poster(hby=hby) @@ -319,16 +319,16 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): vry=self.verifier) doers.extend([ - Initer(agentHab=agentHab, caid=caid, metrics=self.agency.metrics), + Initer(agentHab=agentHab, caid=caid, intercepts=self.agency.intercepts), self.agency.interceptor, Querier(hby=hby, agentHab=agentHab, kvy=self.kvy, queries=self.queries), 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), Messager(kvy=self.kvy, parser=self.parser), - Witnesser(receiptor=receiptor, witners=self.witners, metrics=self.agency.metrics), - Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, metrics=self.agency.metrics), + Witnesser(receiptor=receiptor, witners=self.witners, intercepts=self.agency.intercepts), + Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors, intercepts=self.agency.intercepts), GroupRequester(hby=hby, agentHab=agentHab, postman=self.postman, counselor=self.counselor, - groups=self.groups, metrics=self.agency.metrics), + groups=self.groups, intercepts=self.agency.intercepts), ]) super(Agent, self).__init__(doers=doers, always=True, **opts) @@ -409,10 +409,10 @@ def recur(self, tyme=None): class Witnesser(doing.Doer): - def __init__(self, receiptor, witners, metrics): + def __init__(self, receiptor, witners, intercepts): self.receiptor = receiptor self.witners = witners - self.metrics = metrics + self.intercepts = intercepts super(Witnesser, self).__init__() def recur(self, tyme=None): @@ -420,7 +420,7 @@ def recur(self, tyme=None): if self.witners: msg = self.witners.popleft() serder = msg["serder"] - self.metrics.append(dict(evt="witnessed", ked=serder.ked)) + self.intercepts.append(dict(evt="witnessed", ked=serder.ked)) # 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): adds = serder.ked["ba"] @@ -428,44 +428,43 @@ def recur(self, tyme=None): yield from self.receiptor.catchup(serder.pre, wit) yield from self.receiptor.receipt(serder.pre, serder.sn) - self.metrics.append(dict(evt="witnessing", data=dict(aid=serder.pre))) + self.intercepts.append(dict(evt="witnessing", data=dict(aid=serder.pre))) yield self.tock class Delegator(doing.Doer): - def __init__(self, agentHab, swain, anchors, metrics): + def __init__(self, agentHab, swain, anchors, intercepts): self.agentHab = agentHab self.swain = swain self.anchors = anchors - self.metrics = metrics + self.intercepts = intercepts super(Delegator, self).__init__() def recur(self, tyme=None): if self.anchors: msg = self.anchors.popleft() - if self.interceptor: - self.interceptor.push(msg) + sn = msg["sn"] if "sn" in msg else None self.swain.delegation(pre=msg["pre"], sn=sn, proxy=self.agentHab) - self.metrics.append(dict(msg)) + self.intercepts.append(dict(msg)) return False class Initer(doing.Doer): - def __init__(self, agentHab, caid, metrics): + def __init__(self, agentHab, caid, intercepts): self.agentHab = agentHab self.caid = caid - self.metrics = metrics + self.intercepts = intercepts super(Initer, self).__init__() def recur(self, tyme): """ Prints Agent name and prefix """ if not self.agentHab.inited: return False - self.metrics.append(dict(evt="init", data=dict(aid=self.agentHab.pre))) + self.intercepts.append(dict(evt="init", data=dict(aid=self.agentHab.pre))) print(" Agent:", self.agentHab.pre, " Controller:", self.caid) return True @@ -473,13 +472,13 @@ def recur(self, tyme): class GroupRequester(doing.Doer): - def __init__(self, hby, agentHab, postman, counselor, groups, metrics): + def __init__(self, hby, agentHab, postman, counselor, groups, intercepts): self.hby = hby self.agentHab = agentHab self.postman = postman self.counselor = counselor self.groups = groups - self.metrics = metrics + self.intercepts = intercepts super(GroupRequester, self).__init__() @@ -489,7 +488,7 @@ def recur(self, tyme): msg = self.groups.popleft() serder = msg["serder"] sigers = msg["sigers"] - self.metrics.append(dict(evt="group", data=dict(msg))) + self.intercepts.append(dict(evt="group", data=dict(msg))) ghab = self.hby.habs[serder.pre] if "smids" in msg: smids = msg['smids'] diff --git a/src/keria/app/aiding.py b/src/keria/app/aiding.py index 2045c281..9a4b3d5c 100644 --- a/src/keria/app/aiding.py +++ b/src/keria/app/aiding.py @@ -273,9 +273,6 @@ def on_post(req, rep): """ agent = req.context.agent deserialized_media = req.get_media() - print(deserialized_media) - print(type(agent.agency.metrics)) - agent.agency.metrics.append(dict(name="identifier_update", data = deserialized_media)) try: body = req.get_media() icp = httping.getRequiredParam(body, "icp") @@ -288,6 +285,7 @@ def on_post(req, rep): # client is requesting agent to join multisig group if "group" in body: + agent.agency.intercepts.append(dict(event="creat multisig aid", data=deserialized_media)) group = body["group"] if "mhab" not in group: @@ -321,7 +319,7 @@ def on_post(req, rep): except ValueError as e: agent.hby.deleteHab(name=name) raise falcon.HTTPInternalServerError(description=f"{e.args[0]}") - + agent.agency.intercepts.append(dict(event="multisig created", data=serder.pretty())) # Generate response, a long running operaton indicator for the type agent.groups.append(dict(pre=hab.pre, serder=serder, sigers=sigers, smids=smids, rmids=rmids)) op = agent.monitor.submit(serder.pre, longrunning.OpTypes.group, metadata=dict(sn=0)) @@ -333,6 +331,7 @@ def on_post(req, rep): else: # client is requesting that the Agent track the Salty parameters if Algos.salty in body: + agent.agency.intercepts.append(dict(event="create salty aid", data=serder.pretty())) salt = body[Algos.salty] hab = agent.hby.makeSignifyHab(name, serder=serder, sigers=sigers) try: @@ -343,6 +342,7 @@ def on_post(req, rep): # client is storing encrypted randomly generated key material on agent elif Algos.randy in body: + agent.agency.intercepts.append(dict(event="create randy aid", data=serder.pretty())) rand = body[Algos.randy] hab = agent.hby.makeSignifyHab(name, serder=serder, sigers=sigers) try: @@ -352,6 +352,7 @@ def on_post(req, rep): raise falcon.HTTPInternalServerError(description=f"{e.args[0]}") elif Algos.extern in body: + agent.agency.intercepts.append(dict(event="create extern aid", data=serder.pretty())) extern = body[Algos.extern] hab = agent.hby.makeSignifyHab(name, serder=serder, sigers=sigers) try: diff --git a/src/keria/app/cli/commands/start.py b/src/keria/app/cli/commands/start.py index 0cd70eaa..c857afa2 100644 --- a/src/keria/app/cli/commands/start.py +++ b/src/keria/app/cli/commands/start.py @@ -85,7 +85,7 @@ def launch(args): configFile=args.configFile, configDir=args.configDir, interceptor_webhook=args.interceptor_webhook, - interceptor_headers=json.loads(args.interceptor_headers) if args.interceptor_headers else {'Content-Type': 'application/json'}) + interceptor_headers=json.loads(args.interceptor_headers) if args.interceptor_headers is None else {'Content-Type': 'application/json'}) logger.info("******* Ended Agent for %s listening: admin/%s, http/%s" ".******", args.name, args.admin, args.http) From 5769ccab4214fad1e4ce8f7516840e7efb5d7059 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Wed, 19 Jul 2023 20:41:43 -0500 Subject: [PATCH 13/17] refactor to handle non configured case --- src/keria/app/agenting.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index 5c8a2b09..d56830d9 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -123,6 +123,7 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.cf = None self.intercepts = decking.Deck() doers = [] + self.interceptor = None if interceptor_webhook is not None: self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.intercepts) doers.append(self.interceptor) @@ -325,8 +326,6 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): doers.extend([ Initer(agentHab=agentHab, caid=caid, intercepts=self.agency.intercepts), - self.agency.interceptor, - Querier(hby=hby, agentHab=agentHab, kvy=self.kvy, queries=self.queries), 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), @@ -337,6 +336,8 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): groups=self.groups, intercepts=self.agency.intercepts), SeekerDoer(seeker=self.seeker, cues=self.verifier.cues) ]) + if self.agency.interceptors: + doers.extend(self.agency.interceptors) super(Agent, self).__init__(doers=doers, always=True, **opts) From 6b7d685fa070d458a351b3a8f483b53534f33d81 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Wed, 19 Jul 2023 20:52:58 -0500 Subject: [PATCH 14/17] fix startup issue --- src/keria/app/cli/commands/start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keria/app/cli/commands/start.py b/src/keria/app/cli/commands/start.py index c857afa2..a436b47c 100644 --- a/src/keria/app/cli/commands/start.py +++ b/src/keria/app/cli/commands/start.py @@ -85,7 +85,7 @@ def launch(args): configFile=args.configFile, configDir=args.configDir, interceptor_webhook=args.interceptor_webhook, - interceptor_headers=json.loads(args.interceptor_headers) if args.interceptor_headers is None else {'Content-Type': 'application/json'}) + interceptor_headers=json.loads(args.interceptor_headers) if args.interceptor_headers is not None else {'Content-Type': 'application/json'}) logger.info("******* Ended Agent for %s listening: admin/%s, http/%s" ".******", args.name, args.admin, args.http) From b70889a9b7caed29178db044ff8fc7416f9bd5b4 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Wed, 19 Jul 2023 20:55:06 -0500 Subject: [PATCH 15/17] Update agenting.py --- src/keria/app/agenting.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index d56830d9..f63b020a 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -123,7 +123,6 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.cf = None self.intercepts = decking.Deck() doers = [] - self.interceptor = None if interceptor_webhook is not None: self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.intercepts) doers.append(self.interceptor) @@ -336,9 +335,6 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): groups=self.groups, intercepts=self.agency.intercepts), SeekerDoer(seeker=self.seeker, cues=self.verifier.cues) ]) - if self.agency.interceptors: - doers.extend(self.agency.interceptors) - super(Agent, self).__init__(doers=doers, always=True, **opts) @property From 01b084506b167166900d7b2fc3c9c8c32e8d6739 Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Wed, 19 Jul 2023 21:01:35 -0500 Subject: [PATCH 16/17] keep doer in list --- src/keria/app/agenting.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index f63b020a..d112ae42 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -335,6 +335,8 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts): groups=self.groups, intercepts=self.agency.intercepts), SeekerDoer(seeker=self.seeker, cues=self.verifier.cues) ]) + if self.agency.interceptor is not None: + doers.append(self.agency.interceptor) super(Agent, self).__init__(doers=doers, always=True, **opts) @property From 443e13963cded78a28f1fc265eda4f53506bf0be Mon Sep 17 00:00:00 2001 From: AlexAndrei98 Date: Wed, 19 Jul 2023 21:14:10 -0500 Subject: [PATCH 17/17] fix tests --- src/keria/app/agenting.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index d112ae42..7f0f9fdc 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -123,6 +123,7 @@ def __init__(self, name, bran, base="", configFile=None, configDir=None, adb=Non self.cf = None self.intercepts = decking.Deck() doers = [] + self.interceptor = None if interceptor_webhook is not None: self.interceptor = InterceptorDoer(interceptor_webhook, interceptor_headers, cues=self.intercepts) doers.append(self.interceptor) @@ -415,7 +416,7 @@ def recur(self, tyme=None): class Witnesser(doing.Doer): - def __init__(self, receiptor, witners, intercepts): + def __init__(self, receiptor, witners, intercepts=None): self.receiptor = receiptor self.witners = witners self.intercepts = intercepts @@ -426,7 +427,8 @@ def recur(self, tyme=None): if self.witners: msg = self.witners.popleft() serder = msg["serder"] - self.intercepts.append(dict(evt="witnessed", ked=serder.ked)) + if self.intercepts is not None: + self.intercepts.append(dict(evt="witnessed", ked=serder.ked)) # 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): adds = serder.ked["ba"] @@ -434,14 +436,15 @@ def recur(self, tyme=None): yield from self.receiptor.catchup(serder.pre, wit) yield from self.receiptor.receipt(serder.pre, serder.sn) - self.intercepts.append(dict(evt="witnessing", data=dict(aid=serder.pre))) + if self.intercepts is not None: + self.intercepts.append(dict(evt="witnessing", data=dict(aid=serder.pre))) yield self.tock class Delegator(doing.Doer): - def __init__(self, agentHab, swain, anchors, intercepts): + def __init__(self, agentHab, swain, anchors, intercepts=None): self.agentHab = agentHab self.swain = swain self.anchors = anchors @@ -451,10 +454,10 @@ def __init__(self, agentHab, swain, anchors, intercepts): def recur(self, tyme=None): if self.anchors: msg = self.anchors.popleft() - sn = msg["sn"] if "sn" in msg else None self.swain.delegation(pre=msg["pre"], sn=sn, proxy=self.agentHab) - self.intercepts.append(dict(msg)) + if self.intercepts is not None: + self.intercepts.append(dict(msg)) return False