From 9c469649d726ec6e4b61151993ba246bc5d031ed Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Wed, 14 Feb 2024 13:48:10 -0800 Subject: [PATCH] move token_from_config to plugin --- dbt/adapters/duckdb/credentials.py | 15 --------------- dbt/adapters/duckdb/plugins/motherduck.py | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/dbt/adapters/duckdb/credentials.py b/dbt/adapters/duckdb/credentials.py index e8c765b3..763ae142 100644 --- a/dbt/adapters/duckdb/credentials.py +++ b/dbt/adapters/duckdb/credentials.py @@ -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) diff --git a/dbt/adapters/duckdb/plugins/motherduck.py b/dbt/adapters/duckdb/plugins/motherduck.py index af534836..0b364368 100644 --- a/dbt/adapters/duckdb/plugins/motherduck.py +++ b/dbt/adapters/duckdb/plugins/motherduck.py @@ -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: @@ -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