Skip to content

Commit 92ba757

Browse files
authored
Merge pull request #1181 from hkad98/jkd/add-certificate-support
feat: configure ssl_ca_cert in profile
2 parents a602d64 + a880907 commit 92ba757

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

gooddata-sdk/gooddata_sdk/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Profile(ConfigBase):
3535
token: str
3636
custom_headers: Optional[dict[str, str]] = None
3737
extra_user_agent: Optional[str] = None
38+
ssl_ca_cert: Optional[str] = None
3839

3940
def to_dict(self, use_env: bool = False) -> dict[str, str]:
4041
load_dotenv()

gooddata-sdk/tests/sdk/profiles/gooddata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ profiles:
1212
host: https://xyz.com/
1313
token: $ENV_VAR
1414
data_source_id: demo_ds
15+
certificate:
16+
host: http://abc:3000
17+
token: $OK_TOKEN
18+
custom_headers:
19+
Host: localhost123
20+
extra_user_agent: abc
21+
ssl_ca_cert: /path/to/cert.pem
1522
source_dir: analytics
1623
default_profile: abc
1724

gooddata-sdk/tests/sdk/profiles/profiles.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ wrong:
3232
custom_headers:
3333
Host: localhost123
3434
extra_user_agent: abc
35+
certificate:
36+
host: http://abc:3000
37+
token: "123"
38+
custom_headers:
39+
Host: localhost123
40+
extra_user_agent: abc
41+
ssl_ca_cert: /path/to/cert.pem

gooddata-sdk/tests/sdk/test_sdk.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
from pathlib import Path
66
from typing import Any, Union
7+
from unittest.mock import patch
78

89
import pytest
910
import yaml
@@ -27,6 +28,8 @@ def are_same_check(profile_data: dict[str, Any], sdk: GoodDataSdk):
2728
assert profile_data["custom_headers"] == sdk.client._custom_headers
2829
if "extra_user_agent" in profile_data:
2930
assert profile_data["extra_user_agent"] in sdk.client._api_client.user_agent
31+
if "ssl_ca_cert" in profile_data:
32+
assert profile_data["ssl_ca_cert"] == sdk.client._api_config.ssl_ca_cert
3033

3134

3235
@pytest.mark.parametrize(
@@ -46,6 +49,14 @@ def test_legacy_config(profile):
4649
are_same_check(data[profile], sdk)
4750

4851

52+
def test_legacy_certificate_profile():
53+
profile = "certificate"
54+
with patch.object(Path, "exists", return_value=True):
55+
sdk = GoodDataSdk.create_from_profile(profile=profile, profiles_path=PROFILES_PATH)
56+
data = load_profiles_content(PROFILES_PATH)
57+
are_same_check(data[profile], sdk)
58+
59+
4960
def test_legacy_wrong_profile():
5061
profile = "wrong"
5162
with pytest.raises(ValueError):
@@ -70,6 +81,17 @@ def test_new_config_selected(setenvvar):
7081
assert os.environ[profile_data["token"][1:]] == sdk.client._token
7182

7283

84+
def test_new_config_certificate(setenvvar):
85+
profile = "certificate"
86+
with patch.object(Path, "exists", return_value=True):
87+
sdk = GoodDataSdk.create_from_profile(profile=profile, profiles_path=AAC_PROFILES_PATH)
88+
data = load_profiles_content(AAC_PROFILES_PATH)
89+
profile_data = data["profiles"][profile]
90+
assert profile_data["host"] == sdk.client._hostname
91+
assert os.environ[profile_data["token"][1:]] == sdk.client._token
92+
assert profile_data["ssl_ca_cert"] == sdk.client._api_config.ssl_ca_cert
93+
94+
7395
def test_non_existing_token(setenvvar):
7496
profile = "def"
7597
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)