Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v1.4.0

### Added
- `dm connections create --file` now supports Databricks SQL Warehouse
(`"type": "databricks"`) and MongoDB (`"type": "mongodb"`) connections.
Both list, get, create, and delete like the existing connection types.

## v1.3.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "datamasque-cli"
version = "1.3.0"
version = "1.4.0"
description = "Official command-line interface for the DataMasque data-masking platform."
authors = [
{ name = "DataMasque Ltd" },
Expand Down
15 changes: 14 additions & 1 deletion src/datamasque_cli/commands/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
ConnectionConfig,
DatabaseConnectionConfig,
DatabaseType,
DatabricksConnectionConfig,
DynamoConnectionConfig,
MongoConnectionConfig,
MountedShareConnectionConfig,
S3ConnectionConfig,
SnowflakeConnectionConfig,
Expand All @@ -37,6 +39,8 @@ class ConnectionType(StrEnum):
MOUNTED_SHARE = "mounted_share"
SNOWFLAKE = "snowflake"
DYNAMODB = "dynamodb"
DATABRICKS = "databricks"
MONGODB = "mongodb"


_FILE_CONNECTION_TYPES = (MountedShareConnectionConfig, S3ConnectionConfig, AzureConnectionConfig)
Expand Down Expand Up @@ -69,6 +73,8 @@ def _format_role(conn: ConnectionConfig) -> str:
ConnectionType.MOUNTED_SHARE: MountedShareConnectionConfig,
ConnectionType.SNOWFLAKE: SnowflakeConnectionConfig,
ConnectionType.DYNAMODB: DynamoConnectionConfig,
ConnectionType.DATABRICKS: DatabricksConnectionConfig,
ConnectionType.MONGODB: MongoConnectionConfig,
}


Expand Down Expand Up @@ -131,7 +137,9 @@ def get_connection(
def create_connection(
file: Path | None = typer.Option(None, "--file", "-f", help="JSON file defining the connection"),
name: str | None = typer.Option(None, help="Connection name"),
conn_type: str | None = typer.Option(None, "--type", "-t", help="database, s3, azure, mounted_share"),
conn_type: str | None = typer.Option(
None, "--type", "-t", help="database, s3, azure, mounted_share, snowflake, dynamodb, databricks, mongodb"
),
host: str | None = typer.Option(None, help="Database host"),
port: str | None = typer.Option(None, help="Database port"),
database: str | None = typer.Option(None, help="Database name"),
Expand Down Expand Up @@ -160,6 +168,11 @@ def create_connection(

# Quick mounted share
dm connections create --name input --type mounted_share --base-dir my-data --source

# Databricks, MongoDB, Snowflake and DynamoDB have many fields, so use --file:
# {"type": "databricks", "name": "dbx", "server_hostname": "...", "http_path": "...",
# "access_token": "...", "catalog": "main", "schema": "default"}
dm connections create --file databricks.json
"""
client = get_client(profile)

Expand Down
60 changes: 60 additions & 0 deletions tests/commands/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from datamasque.client.models.connection import (
DatabaseConnectionConfig,
DatabaseType,
DatabricksConnectionConfig,
MongoConnectionConfig,
MountedShareConnectionConfig,
)
from typer.testing import CliRunner
Expand Down Expand Up @@ -164,6 +166,64 @@ def test_create_connection_from_json_file(mock_get_client: MagicMock, runner: Cl
client.create_or_update_connection.assert_called_once()


@patch(f"{MODULE}.get_client")
def test_create_databricks_connection_from_json_file(
mock_get_client: MagicMock, runner: CliRunner, tmp_path: MagicMock
) -> None:
client = MagicMock()
mock_get_client.return_value = client

conn_file = tmp_path / "dbx.json"
conn_file.write_text(
json.dumps(
{
"type": "databricks",
"name": "dbx",
"server_hostname": "dbc-1514b142-1c6c.cloud.databricks.com",
"http_path": "/sql/1.0/warehouses/ea7d918dd5f236f9",
"access_token": "dapiTOKEN",
"catalog": "main",
"schema": "default",
}
)
)

result = runner.invoke(app, ["connections", "create", "--file", str(conn_file)])
assert result.exit_code == 0
config = client.create_or_update_connection.call_args.args[0]
assert isinstance(config, DatabricksConnectionConfig)
assert config.db_type == "databricks"


@patch(f"{MODULE}.get_client")
def test_create_mongodb_connection_from_json_file(
mock_get_client: MagicMock, runner: CliRunner, tmp_path: MagicMock
) -> None:
client = MagicMock()
mock_get_client.return_value = client

conn_file = tmp_path / "mongo.json"
conn_file.write_text(
json.dumps(
{
"type": "mongodb",
"name": "mongo",
"host": "localhost",
"port": "27017",
"database": "mydb",
"user": "admin",
"password": "secret",
}
)
)

result = runner.invoke(app, ["connections", "create", "--file", str(conn_file)])
assert result.exit_code == 0
config = client.create_or_update_connection.call_args.args[0]
assert isinstance(config, MongoConnectionConfig)
assert config.db_type == "mongodb"


# -- delete (tests confirmation logic) ------------------------------------


Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading