Skip to content

Commit 036ce76

Browse files
authored
Merge pull request #200 from lumapps/fix/get-discovery-url
chore(client): get unique discovery file and update urls
2 parents 12cf3f2 + 59f9d0b commit 036ce76

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

lumapps/api/base_client.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,9 @@ def _get_discovery_urls(base_url: str, api_info: Dict[str, str]) -> Tuple[str, s
7070
api_host = urlparse(base_url).netloc.split(".")
7171
if len(api_host) < 4:
7272
raise BaseClientError(f"Invalid base URL: {base_url}")
73-
is_beta_cell = api_host[1] == "beta"
74-
cell = api_host[0]
75-
if is_beta_cell and cell not in (
76-
"go-cell-001",
77-
"go-cell-003",
78-
"ms-cell-001",
79-
):
80-
raise BaseClientError(f"Invalid LumApps cell in base URL: {cell}")
81-
82-
if cell not in (
83-
"go-cell-001",
84-
"go-cell-002",
85-
"go-cell-003",
86-
"go-cell-005",
87-
"go-cell-600",
88-
"ms-cell-001",
89-
"ms-cell-002",
90-
):
91-
raise BaseClientError(f"Invalid LumApps cell in base URL: {cell}")
9273
return (
9374
"https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/"
94-
f"lumapps-discovery-{'beta-' if is_beta_cell else ''}{cell}.json",
75+
"lumapps-discovery-go-cell-001.json",
9576
api_url,
9677
)
9778
return (
@@ -215,6 +196,16 @@ def discovery_doc(self):
215196
else:
216197
resp = self.client.get(url)
217198
resp_doc = resp.json()
199+
200+
discovery_base_url = urlparse(resp_doc["baseUrl"])
201+
resp_doc["baseUrl"] = discovery_base_url._replace(
202+
netloc=urlparse(self.base_url).netloc
203+
).geturl()
204+
discovery_root_url = urlparse(resp_doc["rootUrl"])
205+
resp_doc["rootUrl"] = discovery_root_url._replace(
206+
netloc=urlparse(self.base_url).netloc
207+
).geturl()
208+
218209
get_discovery_cache().set(url, resp_doc)
219210
return resp_doc
220211

lumapps/api/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def __init__(
7979
self.cache = DiscoveryCacheDict()
8080
self.dry_run = dry_run
8181
self._langs = None
82+
extra_http_headers = {
83+
**({"LumApps-Organization-Id": str(self.customer_id)}),
84+
**(extra_http_headers or {}),
85+
}
8286
super().__init__(
8387
api_info,
8488
auth_info=auth_info,

tests/legacy/test_base_client.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def test_get_new_client_as_using_dwd(cli: BaseClient):
385385
("go-cell-002", {"base_url": "https://go-cell-002.api.lumapps.com/"}, None),
386386
("ms-cell-001", {"base_url": "https://ms-cell-001.api.lumapps.com/"}, None),
387387
("go-cell-003", {"base_url": "https://go-cell-003.beta.api.lumapps.com/"}, None),
388-
("go-cell-004", {"base_url": "https://go-cell-004.api.lumapps.com/"}, BaseClientError),
388+
("go-cell-004", {"base_url": "https://go-cell-004.lumapps.com/"}, BaseClientError),
389389
("go-cell-001", {"base_url": "http://localhost/sdk"}, BaseClientError),
390390
("go-cell-001", {}, BaseClientError),
391391
])
@@ -415,13 +415,3 @@ def test_create_client(cell: str, api_info: Dict[str, str], expected_exception:
415415
"authorization": "Bearer None"
416416
}
417417
assert client.base_url == api_info["base_url"].rstrip("/")
418-
if ".beta." in client.base_url:
419-
assert client._discovery_url == (
420-
"https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/"
421-
f"lumapps-discovery-beta-{cell}.json"
422-
)
423-
else:
424-
assert client._discovery_url == (
425-
"https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/"
426-
f"lumapps-discovery-{cell}.json"
427-
)

0 commit comments

Comments
 (0)