Skip to content

Commit

Permalink
feat: agent config retrieval (#318)
Browse files Browse the repository at this point in the history
* feat: endpoint to get agent config

* feat: only expose iurls as needed

* fix: remove unnecessary line
  • Loading branch information
iFergal authored Nov 8, 2024
1 parent 7db348a commit 9736fcb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
34 changes: 33 additions & 1 deletion src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ def loadEnds(app):
queryEnd = QueryCollectionEnd()
app.add_route("/queries", queryEnd)

configEnd = ConfigResourceEnd()
app.add_route("/config", configEnd)


class BootEnd:
""" Resource class for creating datastore in cloud ahab """
Expand Down Expand Up @@ -1324,4 +1327,33 @@ def recur(self, tyme, deeds=None):
print("Re-submit received all witness receipts for", cue["pre"])
self.doers.remove(doer)

return super(Submitter, self).recur(tyme, deeds)
return super(Submitter, self).recur(tyme, deeds)


class ConfigResourceEnd:

@staticmethod
def on_get(req, rep):
""" Config GET endpoint
Parameters:
req (Request): falcon.Request HTTP request
rep (Response): falcon.Response HTTP response
---
summary: Retrieve agent configuration
description: Retrieve agent configuration (only necessary fields are exposed)
tags:
- Config
responses:
200:
description: Subset of configuration dict as JSON
"""
agent = req.context.agent
config = agent.hby.cf.get()
subset = {key: config[key] for key in ["iurls"] if key in config}

rep.status = falcon.HTTP_200
rep.content_type = "application/json"
rep.data = json.dumps(subset).encode("utf-8")
20 changes: 19 additions & 1 deletion tests/app/test_agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_load_ends(helpers):
assert isinstance(end, agenting.KeyEventCollectionEnd)
(end, *_) = app._router.find("/queries")
assert isinstance(end, agenting.QueryCollectionEnd)
(end, *_) = app._router.find("/config")
assert isinstance(end, agenting.ConfigResourceEnd)


def test_load_tocks_config(helpers):
Expand All @@ -84,6 +86,9 @@ def test_load_tocks_config(helpers):
"dt": "2022-01-20T12:57:59.823350+00:00",
"curls": ["http://127.0.0.1:3902/"]
},
"iurls": [
"http://127.0.0.1:5642/oobi/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha/controller&tag=witness"
],
"tocks": {
"initer": 0.0,
"escrower": 1.0
Expand Down Expand Up @@ -357,6 +362,9 @@ def test_oobi_ends(seeder, helpers):
result = client.simulate_post(path="/oobi", body=b)
assert result.status == falcon.HTTP_501

# initiated from keria.json config file (iurls), so remove
oobiery.hby.db.oobis.rem(keys=("http://127.0.0.1:5642/oobi/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha/controller&tag=witness",))

data = dict(url="http://127.0.0.1:5644/oobi/E6Dqo6tHmYTuQ3Lope4mZF_4hBoGJl93cBHRekr_iD_A/witness/")
b = json.dumps(data).encode("utf-8")
result = client.simulate_post(path="/oobi", body=b)
Expand Down Expand Up @@ -703,4 +711,14 @@ def test_submitter(seeder, helpers):
"di": "",
},
)
)
)


def test_config_ends(helpers):
with helpers.openKeria() as (agency, agent, app, client):
configEnd = agenting.ConfigResourceEnd()
app.add_route("/config", configEnd)
res = client.simulate_get(path="/config")
assert res.status == falcon.HTTP_200
assert res.json == {'iurls':
['http://127.0.0.1:5642/oobi/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha/controller&tag=witness']}
3 changes: 2 additions & 1 deletion tests/app/test_specing.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/scripts/keri/cf/main/keria.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"dt": "2022-01-20T12:57:59.823350+00:00",
"curls": ["http://127.0.0.1:3902/"]
},
"iurls": [
"http://127.0.0.1:5642/oobi/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha/controller&tag=witness"
],
"tocks": {
"initer": 0.0,
"escrower": 1.0
Expand Down

0 comments on commit 9736fcb

Please sign in to comment.