Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: agent config retrieval #318

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading