Skip to content

Commit d5929bb

Browse files
Merge pull request #973 from chrisbonilla95/cbon-lx-691-databricks-ds-token-cred-fix
fix: proper cred loading for Databricks pt.3
2 parents ca10fe2 + 537faac commit d5929bb

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

gooddata-sdk/gooddata_sdk/catalog/data_source/declarative_model/data_source.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def _inject_base(self, credentials: dict[str, Any]) -> DeclarativeDataSources:
4141
)
4242
data_sources.append(data_source.to_api(client_secret=client_secret))
4343
else:
44-
token = TokenCredentialsFromFile.token_from_file(credentials[data_source.id])
44+
token = TokenCredentialsFromFile.token_from_file(
45+
file_path=credentials[data_source.id], base64_encode=False
46+
)
4547
data_sources.append(data_source.to_api(token=token))
4648
else:
4749
data_sources.append(data_source.to_api(password=credentials[data_source.id]))

gooddata-sdk/gooddata_sdk/catalog/data_source/service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,9 @@ def test_data_sources_connection(
484484
declarative_data_source.to_test_request(client_secret=client_secret)
485485
)
486486
else:
487-
token = TokenCredentialsFromFile.token_from_file(credentials[declarative_data_source.id])
487+
token = TokenCredentialsFromFile.token_from_file(
488+
file_path=credentials[declarative_data_source.id], base64_encode=False
489+
)
488490
response = self._actions_api.test_data_source_definition(
489491
declarative_data_source.to_test_request(token=token)
490492
)

gooddata-sdk/tests/catalog/test_catalog_data_source.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
from pathlib import Path
5-
from typing import Optional
5+
from typing import Optional, Union
66
from unittest import mock
77
from unittest.mock import MagicMock
88

@@ -416,13 +416,13 @@ def test_delete_declarative_data_sources(test_config):
416416
credentials_path = _current_dir / "load" / "data_source_credentials" / "data_sources_credentials.yaml"
417417
expected_json_path = _current_dir / "expected" / "declarative_data_sources.json"
418418

419-
def token_from_file_side_effect(arg):
420-
if arg == "~/home/secrets.json":
419+
def token_from_file_side_effect(file_path: Union[str, Path], base64_encode: bool):
420+
if file_path == "~/home/secrets.json":
421421
return test_config["bigquery_token"]
422-
elif arg == "databricks-token":
422+
elif file_path == "databricks-token":
423423
return test_config["databricks_token"]
424424
else:
425-
raise ValueError(f"Unexpected argument: {arg}")
425+
raise ValueError(f"Unexpected argument: {file_path}")
426426

427427
TokenCredentialsFromFile.token_from_file = MagicMock(side_effect=token_from_file_side_effect)
428428
ClientSecretCredentialsFromFile.client_secret_from_file = MagicMock(
@@ -460,13 +460,13 @@ def test_load_and_put_declarative_data_sources(test_config):
460460
try:
461461
sdk.catalog_data_source.put_declarative_data_sources(CatalogDeclarativeDataSources(data_sources=[]))
462462

463-
def token_from_file_side_effect(arg):
464-
if arg == "~/home/secrets.json":
463+
def token_from_file_side_effect(file_path: Union[str, Path], base64_encode: bool = True):
464+
if file_path == "~/home/secrets.json":
465465
return test_config["bigquery_token"]
466-
elif arg == "databricks-token":
466+
elif file_path == "databricks-token":
467467
return test_config["databricks_token"]
468468
else:
469-
raise ValueError(f"Unexpected argument: {arg}")
469+
raise ValueError(f"Unexpected argument: {file_path}")
470470

471471
TokenCredentialsFromFile.token_from_file = MagicMock(side_effect=token_from_file_side_effect)
472472
ClientSecretCredentialsFromFile.client_secret_from_file = MagicMock(
@@ -506,13 +506,13 @@ def test_put_declarative_data_sources_connection(test_config):
506506
# Must filter out databricks data sources for this test as they do not have valid URLs
507507
data_sources_e.data_sources = [item for item in data_sources_e.data_sources if "databricks" not in item.id]
508508

509-
def token_from_file_side_effect(arg):
510-
if arg == "~/home/secrets.json":
509+
def token_from_file_side_effect(file_path: Union[str, Path], base64_encode: bool):
510+
if file_path == "~/home/secrets.json":
511511
return test_config["bigquery_token"]
512-
elif arg == "databricks-token":
512+
elif file_path == "databricks-token":
513513
return test_config["databricks_token"]
514514
else:
515-
raise ValueError(f"Unexpected argument: {arg}")
515+
raise ValueError(f"Unexpected argument: {file_path}")
516516

517517
TokenCredentialsFromFile.token_from_file = MagicMock(side_effect=token_from_file_side_effect)
518518
ClientSecretCredentialsFromFile.client_secret_from_file = MagicMock(
@@ -605,13 +605,13 @@ def test_cache_strategy(test_config: dict):
605605
path = _current_dir / "expected" / "declarative_data_sources.json"
606606
credentials_path = _current_dir / "load" / "data_source_credentials" / "data_sources_credentials.yaml"
607607

608-
def token_from_file_side_effect(arg):
609-
if arg == "~/home/secrets.json":
608+
def token_from_file_side_effect(file_path: Union[str, Path], base64_encode: bool):
609+
if file_path == "~/home/secrets.json":
610610
return test_config["bigquery_token"]
611-
elif arg == "databricks-token":
611+
elif file_path == "databricks-token":
612612
return test_config["databricks_token"]
613613
else:
614-
raise ValueError(f"Unexpected argument: {arg}")
614+
raise ValueError(f"Unexpected argument: {file_path}")
615615

616616
TokenCredentialsFromFile.token_from_file = MagicMock(side_effect=token_from_file_side_effect)
617617
ClientSecretCredentialsFromFile.client_secret_from_file = MagicMock(

0 commit comments

Comments
 (0)