Skip to content

Commit 5636fc6

Browse files
Merge pull request #1229 from gooddata/snapshot-master-b7e9aebf-to-rel/dev
[bot] Merge master/b7e9aebf into rel/dev
2 parents 1bd2b47 + b7e9aeb commit 5636fc6

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

packages/gooddata-pipelines/src/gooddata_pipelines/api/gooddata_api.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,11 @@ class ApiMethods:
2020
def _get_base_url(domain: str) -> str:
2121
"""Returns the root endpoint for the GoodData Cloud API.
2222
23-
Method ensures that the URL starts with "https://" and does not
24-
end with a trailing slash.
25-
2623
Args:
2724
domain (str): The domain of the GoodData Cloud instance.
2825
Returns:
2926
str: The base URL for the GoodData Cloud API.
3027
"""
31-
# Remove trailing slash if present.
32-
if domain[-1] == "/":
33-
domain = domain[:-1]
34-
35-
if not domain.startswith("https://") and not domain.startswith(
36-
"http://"
37-
):
38-
domain = f"https://{domain}"
39-
40-
if domain.startswith("http://") and not domain.startswith("https://"):
41-
domain = domain.replace("http://", "https://")
4228

4329
return f"{domain}/api/{API_VERSION}"
4430

packages/gooddata-pipelines/src/gooddata_pipelines/api/gooddata_api_wrapper.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from gooddata_pipelines.api.gooddata_sdk import SdkMethods
99

1010

11+
# TODO: Refactor the GoodDataApi class to use composition instead of inheritance.
1112
class GoodDataApi(SdkMethods, ApiMethods):
1213
"""Wrapper class for the GoodData Cloud API.
1314
@@ -22,7 +23,7 @@ def __init__(self, host: str, token: str) -> None:
2223
host (str): The GoodData Cloud host URL.
2324
token (str): The authentication token for the GoodData Cloud API.
2425
"""
25-
self._domain: str = host
26+
self._domain: str = self._get_clean_host(host)
2627
self._token: str = token
2728

2829
# Initialize the GoodData SDK
@@ -34,3 +35,31 @@ def __init__(self, host: str, token: str) -> None:
3435
"Authorization": f"Bearer {self._token}",
3536
"Content-Type": "application/vnd.gooddata.api+json",
3637
}
38+
39+
@staticmethod
40+
def _get_clean_host(host: str) -> str:
41+
"""Returns a clean URL of the GoodData Cloud host.
42+
43+
Method ensures that the URL starts with "https://" and does not
44+
end with a trailing slash.
45+
"""
46+
47+
if host is None:
48+
raise RuntimeError("Host is not set. Please provide a valid host.")
49+
50+
if host == "":
51+
raise ValueError(
52+
"Host is an empty string. Please provide a valid host."
53+
)
54+
55+
# Remove trailing slash if present.
56+
if host[-1] == "/":
57+
host = host[:-1]
58+
59+
if not host.startswith("https://") and not host.startswith("http://"):
60+
host = f"https://{host}"
61+
62+
if host.startswith("http://") and not host.startswith("https://"):
63+
host = host.replace("http://", "https://")
64+
65+
return host

packages/gooddata-pipelines/tests/panther/test_api_wrapper.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,40 @@
66
API_VERSION,
77
ApiMethods,
88
)
9+
from gooddata_pipelines.api.gooddata_api_wrapper import GoodDataApi
10+
11+
12+
def test_get_base_url():
13+
"""Test the get_base_url method with various domain inputs."""
14+
domain = "example.com"
15+
expected_base_url = f"example.com/api/{API_VERSION}"
16+
result = ApiMethods._get_base_url(domain)
17+
assert result == expected_base_url
918

1019

1120
@pytest.mark.parametrize(
12-
"domain, expected_base_url",
21+
"host, expected_clean_host",
1322
[
14-
("example.com", f"https://example.com/api/{API_VERSION}"),
23+
("example.com", "https://example.com"),
1524
(
1625
"https://example.com",
17-
f"https://example.com/api/{API_VERSION}",
26+
"https://example.com",
1827
),
1928
(
2029
"http://example.com",
21-
f"https://example.com/api/{API_VERSION}",
30+
"https://example.com",
2231
),
23-
("example.com/", f"https://example.com/api/{API_VERSION}"),
32+
("example.com/", "https://example.com"),
2433
(
2534
"https://example.com/",
26-
f"https://example.com/api/{API_VERSION}",
35+
"https://example.com",
2736
),
2837
(
2938
"http://example.com/",
30-
f"https://example.com/api/{API_VERSION}",
39+
"https://example.com",
3140
),
3241
],
3342
)
34-
def test_get_base_url(domain, expected_base_url):
35-
"""Test the get_base_url method with various domain inputs."""
36-
result = ApiMethods._get_base_url(domain)
37-
assert result == expected_base_url
43+
def test_get_clean_host(host, expected_clean_host):
44+
result = GoodDataApi._get_clean_host(host)
45+
assert result == expected_clean_host

packages/gooddata-pipelines/tests/provisioning/test_provisioning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_create_from_profile() -> None:
119119
profile="mock_profile",
120120
profiles_path=Path(f"{TEST_DATA_DIR}/profiles.yaml"),
121121
)
122-
assert provisioner._api._domain == "http://localhost:3000"
122+
assert provisioner._api._domain == "https://localhost:3000"
123123
assert provisioner._api._token == os.environ.pop("MOCK_TOKEN")
124124

125125

0 commit comments

Comments
 (0)