From b282af0e565eb7bdd4528c52d8d4921f1678c572 Mon Sep 17 00:00:00 2001 From: Kent Bull Date: Wed, 13 Sep 2023 13:23:36 -0600 Subject: [PATCH] Return HTTPS OOBI, agent, and controller URLs --- src/keria/app/agenting.py | 18 ++++++++++++------ src/keria/app/aiding.py | 26 ++++++++++++++++++-------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index fe85fe8b..7619a3cc 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -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 diff --git a/src/keria/app/aiding.py b/src/keria/app/aiding.py index 27f3e77d..0707849f 100644 --- a/src/keria/app/aiding.py +++ b/src/keria/app/aiding.py @@ -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") @@ -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: