Skip to content

Commit

Permalink
[Unity] add default auth header for the unity catalog python client (#5)
Browse files Browse the repository at this point in the history
* add default auth header for uc catalog

* clean up init for unity catalog
  • Loading branch information
chidifrank authored Oct 4, 2024
1 parent 879b80d commit c8927eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions dbt/adapters/duckdb/plugins/unity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import json
import sys
from enum import Enum
from typing import Any
from typing import Dict
Expand Down Expand Up @@ -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!")
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/plugins/test_unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c8927eb

Please sign in to comment.