Skip to content

Commit a4047e5

Browse files
committed
fix: use standard password field for MotherDuck token
- Use standard password field (stored in keyring) instead of custom token field - Fix file-based vs tcp-based endpoint handling - Access token is now stored securely via credentials service
1 parent ed9392f commit a4047e5

4 files changed

Lines changed: 24 additions & 35 deletions

File tree

sqlit/domains/connections/providers/motherduck/adapter.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def connect(self, config: ConnectionConfig) -> Any:
3131
package_name=self.install_package,
3232
)
3333

34-
# Get database from file_path
35-
database = ""
36-
if config.file_endpoint and config.file_endpoint.path:
37-
database = config.file_endpoint.path.lstrip("/")
38-
39-
# Get token from extra_options (URL) or options (UI)
40-
token = config.extra_options.get("motherduck_token", "")
41-
if not token:
42-
token = config.get_option("motherduck_token", "")
34+
# Get database from options or tcp_endpoint
35+
database = config.get_option("database", "")
36+
if not database and config.tcp_endpoint:
37+
database = config.tcp_endpoint.database
38+
39+
# Get token from tcp_endpoint.password (stored in keyring)
40+
token = ""
41+
if config.tcp_endpoint:
42+
token = config.tcp_endpoint.password or ""
4343

4444
if not database:
4545
raise ValueError("MotherDuck connections require a database name.")

sqlit/domains/connections/providers/motherduck/provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def _display_info(config) -> str:
1111
database = config.get_option("database", "") or config.database or ""
1212
if database:
1313
return f"md:{database}"
14-
return "md: (default)"
14+
return "MotherDuck"
1515

1616

1717
def _provider_factory(spec: ProviderSpec) -> DatabaseProvider:
@@ -25,7 +25,7 @@ def _provider_factory(spec: ProviderSpec) -> DatabaseProvider:
2525
display_name="MotherDuck",
2626
schema_path=("sqlit.domains.connections.providers.motherduck.schema", "SCHEMA"),
2727
supports_ssh=False,
28-
is_file_based=True, # Use file-based URL parsing (motherduck:///database)
28+
is_file_based=False,
2929
has_advanced_auth=False,
3030
default_port="",
3131
requires_auth=True,

sqlit/domains/connections/providers/motherduck/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
display_name="MotherDuck",
1212
fields=(
1313
SchemaField(
14-
name="file_path",
14+
name="database",
1515
label="Database",
1616
placeholder="my_database",
1717
required=True,
1818
),
1919
SchemaField(
20-
name="motherduck_token",
20+
name="password",
2121
label="Access Token",
2222
field_type=FieldType.PASSWORD,
2323
required=True,
2424
),
2525
),
2626
supports_ssh=False,
27-
is_file_based=True,
27+
is_file_based=False, # Not file-based, uses database + token
2828
requires_auth=True,
2929
)

tests/unit/test_motherduck_adapter.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
from sqlit.domains.connections.domain.config import ConnectionConfig, FileEndpoint
6-
75

86
def test_motherduck_provider_registered():
97
"""Test that MotherDuck provider is properly registered."""
@@ -19,7 +17,7 @@ def test_motherduck_provider_metadata():
1917

2018
provider = get_provider("motherduck")
2119
assert provider.metadata.display_name == "MotherDuck"
22-
assert provider.metadata.is_file_based is True
20+
assert provider.metadata.is_file_based is False
2321
assert provider.metadata.supports_ssh is False
2422
assert provider.metadata.requires_auth is True
2523
assert "md" in provider.metadata.url_schemes
@@ -33,23 +31,14 @@ def test_motherduck_database_type_enum():
3331
assert DatabaseType.MOTHERDUCK.value == "motherduck"
3432

3533

36-
def test_motherduck_url_parsing():
37-
"""Test MotherDuck URL parsing."""
38-
from sqlit.domains.connections.app.url_parser import parse_connection_url
39-
40-
config = parse_connection_url("motherduck:///my_database?motherduck_token=abc123")
41-
42-
assert config.db_type == "motherduck"
43-
assert config.file_path == "/my_database"
44-
assert config.extra_options.get("motherduck_token") == "abc123"
45-
46-
47-
def test_motherduck_md_scheme_url_parsing():
48-
"""Test MotherDuck md:// URL parsing."""
49-
from sqlit.domains.connections.app.url_parser import parse_connection_url
34+
def test_motherduck_schema_uses_password_field():
35+
"""Test MotherDuck schema uses standard password field for token."""
36+
from sqlit.domains.connections.providers.motherduck.schema import SCHEMA
5037

51-
config = parse_connection_url("md:///prod_db?motherduck_token=xyz789")
38+
field_names = [f.name for f in SCHEMA.fields]
39+
assert "database" in field_names
40+
assert "password" in field_names # Uses standard password field for token
5241

53-
assert config.db_type == "motherduck"
54-
assert config.file_path == "/prod_db"
55-
assert config.extra_options.get("motherduck_token") == "xyz789"
42+
# Password field should be labeled as "Access Token"
43+
password_field = next(f for f in SCHEMA.fields if f.name == "password")
44+
assert password_field.label == "Access Token"

0 commit comments

Comments
 (0)