diff --git a/dbt/adapters/duckdb/plugins/unity.py b/dbt/adapters/duckdb/plugins/unity.py index 85b11f67..4a7fbbe9 100644 --- a/dbt/adapters/duckdb/plugins/unity.py +++ b/dbt/adapters/duckdb/plugins/unity.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -import sys from enum import Enum from typing import Any from typing import Dict @@ -237,18 +236,22 @@ def initialize(self, config: Dict[str, Any]): # Get the endpoint from the UC secret host_and_port = uc_secret["endpoint"] + # Get the token from the UC secret + token = uc_secret["token"] + + # Get the optional base path from the plugin config + api_base_path = config.get("api_base_path", "api/2.1/unity-catalog") + # Construct the full base URL - catalog_base_url = f"{host_and_port}/api/2.1/unity-catalog" + catalog_base_url = f"{host_and_port}/{api_base_path}" # Prism mocks the UC server to http://127.0.0.1:4010 with no option to specify a basePath (api/2.1/unity-catalog) # https://github.com/stoplightio/prism/discussions/906 # This is why we need to check if we are running in pytest and only use the host_and_port # Otherwise we will not be able to connect to the mock UC server - if "pytest" in sys.modules: - self.uc_client: Unitycatalog = Unitycatalog(base_url=host_and_port) - else: - # Otherwise, use the full base URL - self.uc_client: Unitycatalog = Unitycatalog(base_url=catalog_base_url) + self.uc_client: Unitycatalog = Unitycatalog( + base_url=catalog_base_url, default_headers={"Authorization": f"Bearer {token}"} + ) def load(self, source_config: SourceConfig): raise NotImplementedError("Loading data to Unitycatalog is not supported!") diff --git a/tests/functional/plugins/test_unity.py b/tests/functional/plugins/test_unity.py index d0db81e1..d57401ff 100644 --- a/tests/functional/plugins/test_unity.py +++ b/tests/functional/plugins/test_unity.py @@ -58,7 +58,7 @@ def unity_create_table_and_schema(self): @pytest.fixture(scope="class") def profiles_config_update(self, dbt_profile_target): - plugins = [{"module": "unity"}] + plugins = [{"module": "unity", "config": {"api_base_path": ""}}] extensions = dbt_profile_target.get("extensions") extensions.extend([{"name": "delta"}]) return {