From 44d826cd4f1d365e023f5c0fd879952600f80213 Mon Sep 17 00:00:00 2001 From: ThomasThelen Date: Mon, 9 Sep 2024 12:44:37 -0700 Subject: [PATCH 1/6] Account for nginx redirect address --- docker-compose.local.yaml | 1 + docker-compose.prod.yaml | 1 + docker-compose.stage.yaml | 1 + kwg_api/api/node_negotiator.py | 2 +- kwg_api/lib/content_negotiator.py | 1 + kwg_api/lib/prefix_builder.py | 5 ++++- 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml index 4f28fb6..51fa904 100644 --- a/docker-compose.local.yaml +++ b/docker-compose.local.yaml @@ -12,5 +12,6 @@ services: environment: - base_address_http=http://localhost - base_address_https=https://localhost + - base_browse_address=staging.knowwheregraph.org/browse networks: - kwg_network diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml index 77dbb6b..3f5df70 100755 --- a/docker-compose.prod.yaml +++ b/docker-compose.prod.yaml @@ -12,5 +12,6 @@ services: environment: - base_address_http=http://stko-kwg.geog.ucsb.edu - base_address_https=https://stko-kwg.geog.ucsb.edu + - base_browse_address=https://stko-kwg.geog.ucsb.edu/browse networks: - kwg_network diff --git a/docker-compose.stage.yaml b/docker-compose.stage.yaml index 8665ade..0c9d85a 100644 --- a/docker-compose.stage.yaml +++ b/docker-compose.stage.yaml @@ -12,5 +12,6 @@ services: environment: - base_address_http=http://staging.knowwheregraph.org - base_address_https=https://staging.knowwheregraph.org + - base_browse_address=staging.knowwheregraph.org/browse networks: - kwg_network diff --git a/kwg_api/api/node_negotiator.py b/kwg_api/api/node_negotiator.py index 8cdaf13..10df4a4 100644 --- a/kwg_api/api/node_negotiator.py +++ b/kwg_api/api/node_negotiator.py @@ -75,7 +75,7 @@ def _redirect_browse(self) -> RedirectResponse: :return: A response signaling a redirect to a URL """ - browse_url = f"{self.base_address_https}/browse/" + browse_url = f"{self.base_browse_address_https}/browse/" resource_id_shortened = PrefixBuilder.resolve_prefix( self.request_url, self.resource_id ) diff --git a/kwg_api/lib/content_negotiator.py b/kwg_api/lib/content_negotiator.py index 63415e7..c3b36c9 100644 --- a/kwg_api/lib/content_negotiator.py +++ b/kwg_api/lib/content_negotiator.py @@ -18,6 +18,7 @@ def __init__(self, request: Request, resource_id: str): """ self.base_address_http = os.getenv("base_address_http") self.base_address_https = os.getenv("base_address_https") + self.base_browse_address = os.getenv("base_browse_address") accept_header = request.headers.get("accept") if not accept_header: raise ValueError("Failed to read the request headers") diff --git a/kwg_api/lib/prefix_builder.py b/kwg_api/lib/prefix_builder.py index a9cea9b..601651f 100644 --- a/kwg_api/lib/prefix_builder.py +++ b/kwg_api/lib/prefix_builder.py @@ -33,6 +33,7 @@ def build() -> Dict[str, str]: base_kwg_url_http=os.environ.get("base_address_http"), base_kwg_url_https=os.environ.get("base_address_https"), ) + print( json.loads(context)) return json.loads(context) @staticmethod @@ -54,7 +55,7 @@ def resolve_prefix(full_uri: str | URL, resource_id: str) -> str | None: # Split the resource out of the . It should look like # {base_address}/lod/resource/ base_url = str(full_uri).split(resource_id)[0] - + print(base_url) except IndexError: logging.warning( f"Failed to find a prefix for URI {full_uri}", exc_info=True @@ -62,6 +63,8 @@ def resolve_prefix(full_uri: str | URL, resource_id: str) -> str | None: return None try: # Find the prefix (key) whose full path (value) matches + print("1234") + print(f"{vocab[base_url]}:{resource_id}") return f"{vocab[base_url]}:{resource_id}" except KeyError: logging.warning( From 8374addcea61d6d3523095da7ae98f85c09f368e Mon Sep 17 00:00:00 2001 From: ThomasThelen Date: Mon, 9 Sep 2024 12:49:49 -0700 Subject: [PATCH 2/6] Fix incorrect member var name --- kwg_api/api/node_negotiator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kwg_api/api/node_negotiator.py b/kwg_api/api/node_negotiator.py index 10df4a4..627253f 100644 --- a/kwg_api/api/node_negotiator.py +++ b/kwg_api/api/node_negotiator.py @@ -75,7 +75,7 @@ def _redirect_browse(self) -> RedirectResponse: :return: A response signaling a redirect to a URL """ - browse_url = f"{self.base_browse_address_https}/browse/" + browse_url = f"{self.base_browse_address}/browse/" resource_id_shortened = PrefixBuilder.resolve_prefix( self.request_url, self.resource_id ) From ae8d39b80fbd72d40639b2ff39d6bd284045aa41 Mon Sep 17 00:00:00 2001 From: ThomasThelen Date: Mon, 9 Sep 2024 12:56:03 -0700 Subject: [PATCH 3/6] Remove extra /browse --- kwg_api/api/node_negotiator.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kwg_api/api/node_negotiator.py b/kwg_api/api/node_negotiator.py index 627253f..a9064d5 100644 --- a/kwg_api/api/node_negotiator.py +++ b/kwg_api/api/node_negotiator.py @@ -75,11 +75,9 @@ def _redirect_browse(self) -> RedirectResponse: :return: A response signaling a redirect to a URL """ - browse_url = f"{self.base_browse_address}/browse/" resource_id_shortened = PrefixBuilder.resolve_prefix( self.request_url, self.resource_id ) if not resource_id_shortened: resource_id_shortened = self.resource_id - print(self.base_address_https) - return RedirectResponse(url=f"{browse_url}#{resource_id_shortened}") + return RedirectResponse(url=f"{self.base_browse_address}#{resource_id_shortened}") From 68d46c2d576cd31e8c8e66ceb9be2332ce3e721a Mon Sep 17 00:00:00 2001 From: ThomasThelen Date: Mon, 9 Sep 2024 13:01:11 -0700 Subject: [PATCH 4/6] Add https prefix to browse address --- docker-compose.local.yaml | 2 +- docker-compose.stage.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml index 51fa904..99cfa89 100644 --- a/docker-compose.local.yaml +++ b/docker-compose.local.yaml @@ -12,6 +12,6 @@ services: environment: - base_address_http=http://localhost - base_address_https=https://localhost - - base_browse_address=staging.knowwheregraph.org/browse + - base_browse_address=https://staging.knowwheregraph.org/browse networks: - kwg_network diff --git a/docker-compose.stage.yaml b/docker-compose.stage.yaml index 0c9d85a..e463c03 100644 --- a/docker-compose.stage.yaml +++ b/docker-compose.stage.yaml @@ -12,6 +12,6 @@ services: environment: - base_address_http=http://staging.knowwheregraph.org - base_address_https=https://staging.knowwheregraph.org - - base_browse_address=staging.knowwheregraph.org/browse + - base_browse_address=https://staging.knowwheregraph.org/browse networks: - kwg_network From c5f0e637a8bcba6fb1d86edce58cf51d55615492 Mon Sep 17 00:00:00 2001 From: ThomasThelen Date: Mon, 9 Sep 2024 13:17:53 -0700 Subject: [PATCH 5/6] Use nginx values --- docker-compose.prod.yaml | 4 ++-- docker-compose.stage.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml index 3f5df70..11a43d3 100755 --- a/docker-compose.prod.yaml +++ b/docker-compose.prod.yaml @@ -10,8 +10,8 @@ services: ports: - '8080:8080' environment: - - base_address_http=http://stko-kwg.geog.ucsb.edu - - base_address_https=https://stko-kwg.geog.ucsb.edu + - base_address_http=http://kwg-api:8080 + - base_address_https=https://kwg-api:8080 - base_browse_address=https://stko-kwg.geog.ucsb.edu/browse networks: - kwg_network diff --git a/docker-compose.stage.yaml b/docker-compose.stage.yaml index e463c03..36ff971 100644 --- a/docker-compose.stage.yaml +++ b/docker-compose.stage.yaml @@ -10,8 +10,8 @@ services: ports: - '8080:8080' environment: - - base_address_http=http://staging.knowwheregraph.org - - base_address_https=https://staging.knowwheregraph.org + - base_address_http=http://kwg-api:8080 + - base_address_https=https://kwg-api:8080 - base_browse_address=https://staging.knowwheregraph.org/browse networks: - kwg_network From a6ae71f5bc4bb792109e9604d123ac7d67f92dc7 Mon Sep 17 00:00:00 2001 From: ThomasThelen Date: Mon, 9 Sep 2024 13:24:08 -0700 Subject: [PATCH 6/6] Remove print statements --- kwg_api/lib/prefix_builder.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kwg_api/lib/prefix_builder.py b/kwg_api/lib/prefix_builder.py index 601651f..4ea3b23 100644 --- a/kwg_api/lib/prefix_builder.py +++ b/kwg_api/lib/prefix_builder.py @@ -33,7 +33,6 @@ def build() -> Dict[str, str]: base_kwg_url_http=os.environ.get("base_address_http"), base_kwg_url_https=os.environ.get("base_address_https"), ) - print( json.loads(context)) return json.loads(context) @staticmethod @@ -55,7 +54,6 @@ def resolve_prefix(full_uri: str | URL, resource_id: str) -> str | None: # Split the resource out of the . It should look like # {base_address}/lod/resource/ base_url = str(full_uri).split(resource_id)[0] - print(base_url) except IndexError: logging.warning( f"Failed to find a prefix for URI {full_uri}", exc_info=True @@ -63,8 +61,6 @@ def resolve_prefix(full_uri: str | URL, resource_id: str) -> str | None: return None try: # Find the prefix (key) whose full path (value) matches - print("1234") - print(f"{vocab[base_url]}:{resource_id}") return f"{vocab[base_url]}:{resource_id}" except KeyError: logging.warning(