Skip to content

Commit

Permalink
katsu url fix for older beacons
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfk committed Feb 20, 2025
1 parent 663ed57 commit 9f9dded
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions bento_beacon/network/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import aiohttp
import asyncio
from flask import current_app
from packaging.version import Version
from urllib.parse import urlsplit, urlunsplit
from json import JSONDecodeError
from ..utils.http import tcp_connector
Expand All @@ -17,7 +18,7 @@
from .bento_public_query import fields_intersection, fields_union

# future versions will pull metadata query info directly from network beacons instead of network katsus
# to deprecate in Bento 18
# to deprecate in Bento 19
PUBLIC_SEARCH_FIELDS_PATH = "/api/metadata/api/public_search_fields"

DEFAULT_ENDPOINT = "individuals"
Expand All @@ -34,6 +35,10 @@
"variants": get_variants,
}

# temp hack to accommodate katsu url changes in Bento 18 (== beacon 0.19.0)
# we should not call katsu at all in later versions
BEACON_VERSION_ZERO_POINT_NINETEEN = Version("0.19.0")


# get network node info for this beacon, which is also hosting the network
# call methods directly instead of circular http calls
Expand Down Expand Up @@ -133,7 +138,7 @@ async def call_network_beacon_for_init(url):

# temp, call katsu for bento public "query_sections"
# TODO change to beacon spec filters, don't call katsu
beacon_info["querySections"] = (await get_public_search_fields(url)).get("sections", [])
beacon_info["querySections"] = (await get_public_search_fields(beacon_info)).get("sections", [])

Check warning on line 141 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L141

Added line #L141 was not covered by tests

except APIException as e:
current_app.logger.error(f"failed trying to initialize network beacon {url}")
Expand Down Expand Up @@ -186,18 +191,32 @@ async def init_network_service_registry():
# Temp utils for bento public search terms


# deprecate in Bento 18
async def get_public_search_fields(beacon_url):
fields_url = public_search_fields_url(beacon_url)
def is_pr_build(url):
return url.startswith("pr-")

Check warning on line 195 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L195

Added line #L195 was not covered by tests


# to deprecate
async def get_public_search_fields(beacon):
fields_url = public_search_fields_url(beacon)

Check warning on line 200 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L200

Added line #L200 was not covered by tests
current_app.logger.info(f"trying public fields url {fields_url}")
fields = await network_beacon_get(fields_url)
return fields


# deprecate in Bento 18
def public_search_fields_url(beacon_url):
split_url = urlsplit(beacon_url)
return urlunsplit((split_url.scheme, "portal." + split_url.netloc, PUBLIC_SEARCH_FIELDS_PATH, "", ""))
# to deprecate
def public_search_fields_url(beacon):
split_url = urlsplit(beacon["apiUrl"])
version_string = beacon["version"]

Check warning on line 209 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L208-L209

Added lines #L208 - L209 were not covered by tests

# fix for katsu url change in Bento 18
# pr version names break version parsing but are assumed to be recent
url_prefix = (

Check warning on line 213 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L213

Added line #L213 was not covered by tests
""
if is_pr_build(version_string) or Version(version_string) >= BEACON_VERSION_ZERO_POINT_NINETEEN
else "portal."
)

return urlunsplit((split_url.scheme, url_prefix + split_url.netloc, PUBLIC_SEARCH_FIELDS_PATH, "", ""))

Check warning on line 219 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L219

Added line #L219 was not covered by tests


def filters_union(all_search_fields):
Expand Down

0 comments on commit 9f9dded

Please sign in to comment.