Skip to content

Commit

Permalink
move token_from_config to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
guenp committed Feb 14, 2024
1 parent a0723cf commit 9c46964
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
15 changes: 0 additions & 15 deletions dbt/adapters/duckdb/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,6 @@ def is_motherduck(self):
def _is_motherduck(scheme: str) -> bool:
return scheme in {"md", "motherduck"}

@property
def token_from_config(self) -> str:
"""Load the token from the MotherDuck plugin config
If not specified, this returns an empty string
Returns:
str: MotherDuck token
"""
plugins = self.plugins or []
for plugin in plugins:
if plugin.config:
token = plugin.config.get("token") or ""
return str(token)
return ""

@classmethod
def __pre_deserialize__(cls, data: Dict[Any, Any]) -> Dict[Any, Any]:
data = super().__pre_deserialize__(data)
Expand Down
19 changes: 17 additions & 2 deletions dbt/adapters/duckdb/plugins/motherduck.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ def initialize(self, config: Dict[str, Any]):
def configure_connection(self, conn: DuckDBPyConnection):
conn.load_extension("motherduck")

@staticmethod
def token_from_config(creds: DuckDBCredentials) -> str:
"""Load the token from the MotherDuck plugin config
If not specified, this returns an empty string
:param str: MotherDuck token
"""
plugins = creds.plugins or []
for plugin in plugins:
if plugin.config:
token = plugin.config.get("token") or ""
return str(token)
return ""

def update_connection_config(self, creds: DuckDBCredentials, config: Dict[str, Any]):
user_agent = f"dbt/{__version__}"
if "custom_user_agent" in config:
Expand All @@ -24,5 +38,6 @@ def update_connection_config(self, creds: DuckDBCredentials, config: Dict[str, A

# If a user specified the token via the plugin config,
# pass it to the config kwarg in duckdb.connect
if creds.token_from_config != "":
config["motherduck_token"] = creds.token_from_config
token = self.token_from_config(creds)
if token != "":
config["motherduck_token"] = token

0 comments on commit 9c46964

Please sign in to comment.