Skip to content

Commit

Permalink
Merge pull request #200 from lumapps/fix/get-discovery-url
Browse files Browse the repository at this point in the history
chore(client): get unique discovery file and update urls
  • Loading branch information
jssevestre authored Oct 24, 2024
2 parents 12cf3f2 + 59f9d0b commit 036ce76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
31 changes: 11 additions & 20 deletions lumapps/api/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,9 @@ def _get_discovery_urls(base_url: str, api_info: Dict[str, str]) -> Tuple[str, s
api_host = urlparse(base_url).netloc.split(".")
if len(api_host) < 4:
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,16 @@ 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=urlparse(self.base_url).netloc
).geturl()
discovery_root_url = urlparse(resp_doc["rootUrl"])
resp_doc["rootUrl"] = discovery_root_url._replace(
netloc=urlparse(self.base_url).netloc
).geturl()

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

Expand Down
4 changes: 4 additions & 0 deletions lumapps/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def __init__(
self.cache = DiscoveryCacheDict()
self.dry_run = dry_run
self._langs = None
extra_http_headers = {
**({"LumApps-Organization-Id": str(self.customer_id)}),
**(extra_http_headers or {}),
}
super().__init__(
api_info,
auth_info=auth_info,
Expand Down
12 changes: 1 addition & 11 deletions tests/legacy/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def test_get_new_client_as_using_dwd(cli: BaseClient):
("go-cell-002", {"base_url": "https://go-cell-002.api.lumapps.com/"}, None),
("ms-cell-001", {"base_url": "https://ms-cell-001.api.lumapps.com/"}, None),
("go-cell-003", {"base_url": "https://go-cell-003.beta.api.lumapps.com/"}, None),
("go-cell-004", {"base_url": "https://go-cell-004.api.lumapps.com/"}, BaseClientError),
("go-cell-004", {"base_url": "https://go-cell-004.lumapps.com/"}, BaseClientError),
("go-cell-001", {"base_url": "http://localhost/sdk"}, BaseClientError),
("go-cell-001", {}, BaseClientError),
])
Expand Down Expand Up @@ -415,13 +415,3 @@ def test_create_client(cell: str, api_info: Dict[str, str], expected_exception:
"authorization": "Bearer None"
}
assert client.base_url == api_info["base_url"].rstrip("/")
if ".beta." in client.base_url:
assert client._discovery_url == (
"https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/"
f"lumapps-discovery-beta-{cell}.json"
)
else:
assert client._discovery_url == (
"https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/"
f"lumapps-discovery-{cell}.json"
)

0 comments on commit 036ce76

Please sign in to comment.