Skip to content

Commit c9d7ed6

Browse files
rename config to secrets; add warning message for old versions
1 parent 7999b55 commit c9d7ed6

7 files changed

Lines changed: 38 additions & 32 deletions

File tree

docs/integrations/engines/duckdb.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
| `catalogs` | Mapping to define multiple catalogs. Can [attach DuckDB catalogs](#duckdb-catalogs-example) or [catalogs for other connections](#other-connection-catalogs-example). First entry is the default catalog. Cannot be defined if using `database`. | dict | N |
1818
| `extensions` | Extension to load into duckdb. Only autoloadable extensions are supported. | list | N |
1919
| `connector_config` | Configuration to pass into the duckdb connector. | dict | N |
20-
| `secrets_config` | Configuration for authenticating external sources (e.g., S3) using DuckDB secrets. | dict | N |
20+
| `secrets` | Configuration for authenticating external sources (e.g., S3) using DuckDB secrets. | dict | N |
2121

2222
#### DuckDB Catalogs Example
2323

@@ -142,11 +142,11 @@ If a connector, like Postgres, requires sensitive information in the path, it mi
142142

143143
DuckDB can read data directly from cloud services via extensions (e.g., [httpfs](https://duckdb.org/docs/extensions/httpfs/s3api), [azure](https://duckdb.org/docs/extensions/azure)).
144144

145-
The `secrets_config` option allows you to configure DuckDB's [Secrets Manager](https://duckdb.org/docs/configuration/secrets_manager.html) to authenticate with external services like S3. This is the recommended approach for cloud storage authentication in DuckDB v0.10.0 and newer, replacing the [legacy authentication method](https://duckdb.org/docs/stable/extensions/httpfs/s3api_legacy_authentication.html) via variables.
145+
The `secrets` option allows you to configure DuckDB's [Secrets Manager](https://duckdb.org/docs/configuration/secrets_manager.html) to authenticate with external services like S3. This is the recommended approach for cloud storage authentication in DuckDB v0.10.0 and newer, replacing the [legacy authentication method](https://duckdb.org/docs/stable/extensions/httpfs/s3api_legacy_authentication.html) via variables.
146146

147147
##### Secrets Configuration Example for S3
148148

149-
The `secrets_config` accepts a list of secret configurations, each defining the necessary authentication parameters for the specific service:
149+
The `secrets` accepts a list of secret configurations, each defining the necessary authentication parameters for the specific service:
150150

151151
=== "YAML"
152152

@@ -160,7 +160,7 @@ The `secrets_config` accepts a list of secret configurations, each defining the
160160
remote: "s3://bucket/data/remote.duckdb"
161161
extensions:
162162
- name: httpfs
163-
secrets_config:
163+
secrets:
164164
- type: s3
165165
region: "YOUR_AWS_REGION"
166166
key_id: "YOUR_AWS_ACCESS_KEY"
@@ -189,7 +189,7 @@ The `secrets_config` accepts a list of secret configurations, each defining the
189189
extensions=[
190190
{"name": "httpfs"},
191191
],
192-
secrets_config=[
192+
secrets=[
193193
{
194194
"type": "s3",
195195
"region": "YOUR_AWS_REGION",

docs/integrations/engines/motherduck.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ Congratulations \- your SQLMesh project is up and running on MotherDuck\!
104104
| `token` | The optional MotherDuck token. If not specified, the user will be prompted to login with their web browser. | string | N |
105105
| `extensions` | Extension to load into duckdb. Only autoloadable extensions are supported. | list | N |
106106
| `connector_config` | Configuration to pass into the duckdb connector. | dict | N |
107-
| `secrets_config` | Configuration for authenticating external sources (e.g. S3) using DuckDB secrets. | dict | N |
107+
| `secrets` | Configuration for authenticating external sources (e.g. S3) using DuckDB secrets. | dict | N |

sqlmesh/core/config/connection.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class BaseDuckDBConnectionConfig(ConnectionConfig):
202202
catalogs: Key is the name of the catalog and value is the path.
203203
extensions: A list of autoloadable extensions to load.
204204
connector_config: A dictionary of configuration to pass into the duckdb connector.
205-
secrets_config: A list of dictionaries used to generate DuckDB secrets for authenticating with external services (e.g. S3).
205+
secrets: A list of dictionaries used to generate DuckDB secrets for authenticating with external services (e.g. S3).
206206
concurrent_tasks: The maximum number of tasks that can use this connection concurrently.
207207
register_comments: Whether or not to register model comments with the SQL engine.
208208
pre_ping: Whether or not to pre-ping the connection before starting a new transaction to ensure it is still alive.
@@ -213,7 +213,7 @@ class BaseDuckDBConnectionConfig(ConnectionConfig):
213213
catalogs: t.Optional[t.Dict[str, t.Union[str, DuckDBAttachOptions]]] = None
214214
extensions: t.List[t.Union[str, t.Dict[str, t.Any]]] = []
215215
connector_config: t.Dict[str, t.Any] = {}
216-
secrets_config: t.List[t.Dict[str, t.Any]] = []
216+
secrets: t.List[t.Dict[str, t.Any]] = []
217217

218218
concurrent_tasks: int = 1
219219
register_comments: bool = True
@@ -286,21 +286,27 @@ def init(cursor: duckdb.DuckDBPyConnection) -> None:
286286
except Exception as e:
287287
raise ConfigError(f"Failed to set connector config {field} to {setting}: {e}")
288288

289-
if self.secrets_config and version.parse(duckdb.__version__) >= version.parse("0.10.0"):
290-
# For older versions, legacy authentication is used by setting through the connector_config
291-
# https://duckdb.org/docs/stable/extensions/httpfs/s3api_legacy_authentication.html
292-
293-
for secrets in self.secrets_config:
294-
secret_settings: t.List[str] = []
295-
for field, setting in secrets.items():
296-
secret_settings.append(f"{field} '{setting}'")
297-
298-
if secret_settings:
299-
secret_clause = ", ".join(secret_settings)
300-
try:
301-
cursor.execute(f"CREATE SECRET ({secret_clause});")
302-
except Exception as e:
303-
raise ConfigError(f"Failed to create secret: {e}")
289+
if self.secrets:
290+
duckdb_version = duckdb.__version__
291+
if version.parse(duckdb_version) < version.parse("0.10.0"):
292+
from sqlmesh.core.console import get_console
293+
294+
get_console().log_warning(
295+
f"DuckDB version {duckdb_version} does not support secrets-based authentication (requires 0.10.0 or later).\n"
296+
"To use secrets, please upgrade DuckDB. For older versions, configure legacy authentication via `connector_config`.\n"
297+
"More info: https://duckdb.org/docs/stable/extensions/httpfs/s3api_legacy_authentication.html"
298+
)
299+
else:
300+
for secrets in self.secrets:
301+
secret_settings: t.List[str] = []
302+
for field, setting in secrets.items():
303+
secret_settings.append(f"{field} '{setting}'")
304+
if secret_settings:
305+
secret_clause = ", ".join(secret_settings)
306+
try:
307+
cursor.execute(f"CREATE SECRET ({secret_clause});")
308+
except Exception as e:
309+
raise ConfigError(f"Failed to create secret: {e}")
304310

305311
for i, (alias, path_options) in enumerate(
306312
(getattr(self, "catalogs", None) or {}).items()

sqlmesh/dbt/target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def to_sqlmesh(self, **kwargs: t.Any) -> ConnectionConfig:
195195
if self.settings is not None:
196196
kwargs["connector_config"] = self.settings
197197
if self.secrets is not None:
198-
kwargs["secrets_config"] = self.secrets
198+
kwargs["secrets"] = self.secrets
199199
return DuckDBConnectionConfig(
200200
database=self.path,
201201
concurrent_tasks=1,

tests/core/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def test_connection_config_serialization():
550550
"pre_ping": False,
551551
"pretty_sql": False,
552552
"connector_config": {},
553-
"secrets_config": [],
553+
"secrets": [],
554554
"database": "my_db",
555555
}
556556
assert serialized["default_test_connection"] == {
@@ -561,7 +561,7 @@ def test_connection_config_serialization():
561561
"pre_ping": False,
562562
"pretty_sql": False,
563563
"connector_config": {},
564-
"secrets_config": [],
564+
"secrets": [],
565565
"database": "my_test_db",
566566
}
567567

tests/core/test_connection_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def test_duckdb(make_config):
426426
type="duckdb",
427427
database="test",
428428
connector_config={"foo": "bar"},
429-
secrets_config=[
429+
secrets=[
430430
{
431431
"type": "s3",
432432
"region": "aws_region",
@@ -436,7 +436,7 @@ def test_duckdb(make_config):
436436
],
437437
)
438438
assert config.connector_config
439-
assert config.secrets_config
439+
assert config.secrets
440440
assert isinstance(config, DuckDBConnectionConfig)
441441
assert not config.is_recommended_for_state_sync
442442

tests/integrations/jupyter/test_magics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,16 +759,16 @@ def test_info(notebook, sushi_context, convert_all_html_output_to_text, get_all_
759759
"Models: 18",
760760
"Macros: 8",
761761
"",
762-
"Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets_config: None",
763-
"Test Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets_config: None",
762+
"Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets: None",
763+
"Test Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets: None",
764764
"Data warehouse connection succeeded",
765765
]
766766
assert get_all_html_output(output) == [
767767
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Models: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">18</span></pre>",
768768
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Macros: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">8</span></pre>",
769769
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>",
770-
'<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace">Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false pretty_sql: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span> secrets_config: <span style="color: #800080; text-decoration-color: #800080; font-style: italic">None</span></pre>',
771-
'<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace">Test Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false pretty_sql: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span> secrets_config: <span style="color: #800080; text-decoration-color: #800080; font-style: italic">None</span></pre>',
770+
'<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace">Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false pretty_sql: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span> secrets: <span style="color: #800080; text-decoration-color: #800080; font-style: italic">None</span></pre>',
771+
'<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace">Test Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false pretty_sql: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span> secrets: <span style="color: #800080; text-decoration-color: #800080; font-style: italic">None</span></pre>',
772772
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Data warehouse connection <span style=\"color: #008000; text-decoration-color: #008000\">succeeded</span></pre>",
773773
]
774774

0 commit comments

Comments
 (0)