Skip to content

Commit

Permalink
Return HTTPS OOBI, agent, and controller URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
kentbull committed Sep 13, 2023
1 parent a227ed4 commit b282af0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
18 changes: 12 additions & 6 deletions src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,31 +916,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)
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]
print(f"agenting | witness url being sent {url}")
up = urlparse(urls[kering.Schemes.http])
oobis.append(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/witness/{wit}")
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/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)
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]
up = urlparse(urls[kering.Schemes.http])
oobis.append(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
print(f"agenting | controller url being sent {url}")
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/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)
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]
up = urlparse(urls[kering.Schemes.http])
oobis.append(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/agent/{eid}")
print(f"agenting | agent url being sent {url}")
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/agent/{eid}")
res["oobis"] = oobis
else:
rep.status = falcon.HTTP_404
Expand Down
26 changes: 18 additions & 8 deletions src/keria/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,24 +641,28 @@ def on_get(req, rep, name):
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)
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")

up = urlparse(urls[kering.Schemes.http])
oobis.append(f"{kering.Schemes.http}://{up.hostname}:{up.port}/oobi/{hab.pre}/witness/{wit}")
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
print(f'aiding | witness url sent {url}')
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/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)
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]
up = urlparse(urls[kering.Schemes.http])
oobis.append(f"{kering.Schemes.http}://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
print(f"aiding | controller URL")
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
res["oobis"] = oobis
elif role in (kering.Roles.agent,): # Fetch URL OOBIs for all witnesses
roleUrls = hab.fetchRoleUrls(cid=hab.pre, role=kering.Roles.agent, scheme=kering.Schemes.http)
roleUrls = hab.fetchRoleUrls(cid=hab.pre, role=kering.Roles.agent, scheme=kering.Schemes.http) or hab.fetchRoleUrls(cid=hab.pre, role=kering.Roles.agent, scheme=kering.Schemes.https)
if kering.Roles.agent not in roleUrls:
raise falcon.HTTPNotFound(description=f"unable to query agent roles for {hab.pre}, no http endpoint")

Expand All @@ -668,9 +672,15 @@ def on_get(req, rep, name):
for agent in set(aoobis.keys()):
murls = aoobis.naball(agent)
for murl in murls:
for url in murl.naball(kering.Schemes.http):
urls = []
if kering.Schemes.http in murl:
urls.extend(murl.naball(kering.Schemes.http))
if kering.Schemes.https in murl:
urls.extend(murl.naball(kering.Schemes.https))
for url in urls:
print(f"aiding | agent URL sent {url}")
up = urlparse(url)
oobis.append(f"{kering.Schemes.http}://{up.hostname}:{up.port}/oobi/{hab.pre}/agent/{agent}")
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/agent/{agent}")

res["oobis"] = oobis
else:
Expand Down

0 comments on commit b282af0

Please sign in to comment.