Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gooddata-sdk/gooddata_sdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions gooddata-sdk/tests/sdk/profiles/gooddata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions gooddata-sdk/tests/sdk/profiles/profiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions gooddata-sdk/tests/sdk/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from pathlib import Path
from typing import Any, Union
from unittest.mock import patch

import pytest
import yaml
Expand All @@ -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(
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Loading