diff --git a/gooddata-sdk/gooddata_sdk/config.py b/gooddata-sdk/gooddata_sdk/config.py index 3929c224c..06b8d1e5e 100644 --- a/gooddata-sdk/gooddata_sdk/config.py +++ b/gooddata-sdk/gooddata_sdk/config.py @@ -35,6 +35,7 @@ class Profile(ConfigBase): token: str custom_headers: Optional[dict[str, str]] = None extra_user_agent: Optional[str] = None + ssl_ca_cert: Optional[str] = None def to_dict(self, use_env: bool = False) -> dict[str, str]: load_dotenv() diff --git a/gooddata-sdk/tests/sdk/profiles/gooddata.yaml b/gooddata-sdk/tests/sdk/profiles/gooddata.yaml index c4de2acea..a2e03f2a8 100644 --- a/gooddata-sdk/tests/sdk/profiles/gooddata.yaml +++ b/gooddata-sdk/tests/sdk/profiles/gooddata.yaml @@ -12,6 +12,13 @@ profiles: host: https://xyz.com/ token: $ENV_VAR data_source_id: demo_ds + certificate: + host: http://abc:3000 + token: $OK_TOKEN + custom_headers: + Host: localhost123 + extra_user_agent: abc + ssl_ca_cert: /path/to/cert.pem source_dir: analytics default_profile: abc diff --git a/gooddata-sdk/tests/sdk/profiles/profiles.yaml b/gooddata-sdk/tests/sdk/profiles/profiles.yaml index 741457386..c82dbc338 100644 --- a/gooddata-sdk/tests/sdk/profiles/profiles.yaml +++ b/gooddata-sdk/tests/sdk/profiles/profiles.yaml @@ -32,3 +32,10 @@ wrong: custom_headers: Host: localhost123 extra_user_agent: abc +certificate: + host: http://abc:3000 + token: "123" + custom_headers: + Host: localhost123 + extra_user_agent: abc + ssl_ca_cert: /path/to/cert.pem diff --git a/gooddata-sdk/tests/sdk/test_sdk.py b/gooddata-sdk/tests/sdk/test_sdk.py index 13a00ce9c..30d219d7c 100644 --- a/gooddata-sdk/tests/sdk/test_sdk.py +++ b/gooddata-sdk/tests/sdk/test_sdk.py @@ -4,6 +4,7 @@ import os from pathlib import Path from typing import Any, Union +from unittest.mock import patch import pytest import yaml @@ -27,6 +28,8 @@ def are_same_check(profile_data: dict[str, Any], sdk: GoodDataSdk): assert profile_data["custom_headers"] == sdk.client._custom_headers if "extra_user_agent" in profile_data: assert profile_data["extra_user_agent"] in sdk.client._api_client.user_agent + if "ssl_ca_cert" in profile_data: + assert profile_data["ssl_ca_cert"] == sdk.client._api_config.ssl_ca_cert @pytest.mark.parametrize( @@ -46,6 +49,14 @@ def test_legacy_config(profile): are_same_check(data[profile], sdk) +def test_legacy_certificate_profile(): + profile = "certificate" + with patch.object(Path, "exists", return_value=True): + sdk = GoodDataSdk.create_from_profile(profile=profile, profiles_path=PROFILES_PATH) + data = load_profiles_content(PROFILES_PATH) + are_same_check(data[profile], sdk) + + def test_legacy_wrong_profile(): profile = "wrong" with pytest.raises(ValueError): @@ -70,6 +81,17 @@ def test_new_config_selected(setenvvar): assert os.environ[profile_data["token"][1:]] == sdk.client._token +def test_new_config_certificate(setenvvar): + profile = "certificate" + with patch.object(Path, "exists", return_value=True): + sdk = GoodDataSdk.create_from_profile(profile=profile, profiles_path=AAC_PROFILES_PATH) + data = load_profiles_content(AAC_PROFILES_PATH) + profile_data = data["profiles"][profile] + assert profile_data["host"] == sdk.client._hostname + assert os.environ[profile_data["token"][1:]] == sdk.client._token + assert profile_data["ssl_ca_cert"] == sdk.client._api_config.ssl_ca_cert + + def test_non_existing_token(setenvvar): profile = "def" with pytest.raises(ValueError):