Skip to content

Commit

Permalink
chore(client): get unique discovery file and update urls
Browse files Browse the repository at this point in the history
  • Loading branch information
chloecarton committed Oct 2, 2024
1 parent 12cf3f2 commit 9f4b2af
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions lumapps/api/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,11 @@ def _get_discovery_urls(base_url: str, api_info: Dict[str, str]) -> Tuple[str, s

if api_name == LUMAPPS_NAME:
api_host = urlparse(base_url).netloc.split(".")
if len(api_host) < 4:
if len(api_host) < 3:
raise BaseClientError(f"Invalid base URL: {base_url}")
is_beta_cell = api_host[1] == "beta"
cell = api_host[0]
if is_beta_cell and cell not in (
"go-cell-001",
"go-cell-003",
"ms-cell-001",
):
raise BaseClientError(f"Invalid LumApps cell in base URL: {cell}")

if cell not in (
"go-cell-001",
"go-cell-002",
"go-cell-003",
"go-cell-005",
"go-cell-600",
"ms-cell-001",
"ms-cell-002",
):
raise BaseClientError(f"Invalid LumApps cell in base URL: {cell}")
return (
"https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/"
f"lumapps-discovery-{'beta-' if is_beta_cell else ''}{cell}.json",
"lumapps-discovery-go-cell-001.json",
api_url,
)
return (
Expand Down Expand Up @@ -215,6 +196,12 @@ def discovery_doc(self):
else:
resp = self.client.get(url)
resp_doc = resp.json()

discovery_base_url = urlparse(resp_doc["baseUrl"])
resp_doc["baseUrl"] = discovery_base_url._replace(netloc=self.base_url).geturl()
discovery_root_url = urlparse(resp_doc["rootUrl"])
resp_doc["rootUrl"] = discovery_root_url._replace(netloc=self.base_url).geturl()

get_discovery_cache().set(url, resp_doc)
return resp_doc

Expand Down

0 comments on commit 9f4b2af

Please sign in to comment.