datamasque-cli 1.5.1__tar.gz → 1.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/CHANGELOG.md +17 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/PKG-INFO +15 -2
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/README.md +13 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/datamasque-cli/skills/datamasque-cli/SKILL.md +10 -1
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/pyproject.toml +2 -2
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/client.py +10 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/connections.py +8 -10
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/discovery.py +3 -11
- datamasque_cli-1.6.0/src/datamasque_cli/commands/table_references.py +287 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/fileio.py +11 -1
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/main.py +2 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_connections.py +19 -0
- datamasque_cli-1.6.0/tests/commands/test_table_references.py +670 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/conftest.py +7 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/test_delete_safety.py +1 -1
- datamasque_cli-1.6.0/tests/integration/test_table_references.py +88 -0
- datamasque_cli-1.6.0/tests/test_client_connections.py +34 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/uv.lock +5 -5
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/.claude-plugin/marketplace.json +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/.github/workflows/ci.yml +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/.github/workflows/release-testpypi.yml +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/.github/workflows/release.yml +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/.gitignore +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/CONTRIBUTING.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/LICENSE +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/Makefile +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/NOTICE +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/assets/demo.gif +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/README.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/datamasque-cli/.claude-plugin/plugin.json +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-builder/.claude-plugin/plugin.json +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-builder/skills/ruleset-builder/SKILL.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-builder/skills/ruleset-builder/references/fk-cascade.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-builder/skills/ruleset-builder/references/hash-columns-guide.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-builder/skills/ruleset-builder/references/mask-definitions-guide.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-builder/skills/ruleset-builder/references/ruleset-libraries-guide.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-builder/skills/ruleset-builder/references/ruleset-yaml-reference.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-splitter/.claude-plugin/plugin.json +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/claude-skills/ruleset-splitter/skills/ruleset-splitter/SKILL.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/scripts/active_profile_env.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/scripts/bump_version.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/scripts/installation_smoke_test.sh +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/__init__.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/__init__.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/auth.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/discovery_config_libraries.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/discovery_configs.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/files.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/ifm.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/ruleset_libraries.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/rulesets.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/runs.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/seeds.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/system.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/commands/users.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/config.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/errors.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/output.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/protocols.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/src/datamasque_cli/py.typed +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/__init__.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/__init__.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_auth.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_catalog.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_discovery.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_discovery_config_libraries.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_discovery_configs.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_files.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_ifm.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_ruleset_libraries.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_rulesets.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_runs.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_seeds.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_system.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/commands/test_users.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/conftest.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/README.md +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/__init__.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/test_connections.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/test_discovery.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/test_discovery_configs.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/test_rulesets.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/test_runs.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/integration/test_system.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_client_auth.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_client_env.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_client_ifm.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_client_profile.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_config.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_main.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_output.py +0 -0
- {datamasque_cli-1.5.1 → datamasque_cli-1.6.0}/tests/test_version.py +0 -0
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.6.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `dm table-references` — manage table references (`list`, `get`, `create`,
|
|
7
|
+
`update`, `delete`), the named pointers to identity data used for
|
|
8
|
+
cross-system consistent masking. `create` accepts `--file` for a full
|
|
9
|
+
JSON definition or `--name`/`--connection`/`--source` flags plus the
|
|
10
|
+
format/CSV options (`--format`, `--delimiter`, `--encoding`,
|
|
11
|
+
`--quotechar`, `--null-string`) for the common case, and is a
|
|
12
|
+
create-or-update like `dm connections create`; `update` changes only the
|
|
13
|
+
fields passed, preserving the reference's id.
|
|
14
|
+
|
|
15
|
+
### Internal
|
|
16
|
+
- Extracted `resolve_connection` (name-or-ID lookup) into `client.py` and
|
|
17
|
+
routed `connections.py`'s `test`/`update` and `discover schema`/`discover
|
|
18
|
+
file` through it, replacing three separate inline copies.
|
|
19
|
+
|
|
3
20
|
## v1.5.1
|
|
4
21
|
|
|
5
22
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datamasque-cli
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.0
|
|
4
4
|
Summary: Official command-line interface for the DataMasque data-masking platform.
|
|
5
5
|
Project-URL: Homepage, https://datamasque.com/
|
|
6
6
|
Project-URL: Repository, https://github.com/datamasque/datamasque-cli
|
|
@@ -23,7 +23,7 @@ Classifier: Topic :: Database
|
|
|
23
23
|
Classifier: Topic :: Utilities
|
|
24
24
|
Classifier: Typing :: Typed
|
|
25
25
|
Requires-Python: >=3.11
|
|
26
|
-
Requires-Dist: datamasque-python<2,>=1.2.
|
|
26
|
+
Requires-Dist: datamasque-python<2,>=1.2.5
|
|
27
27
|
Requires-Dist: pydantic<3,>=2.5
|
|
28
28
|
Requires-Dist: rich>=13.8
|
|
29
29
|
Requires-Dist: tomli-w<2,>=1.0.0
|
|
@@ -199,6 +199,19 @@ dm libraries status <name> # Validation status; poll afte
|
|
|
199
199
|
dm libraries usage <name> # Show rulesets using it
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
+
### Table references
|
|
203
|
+
|
|
204
|
+
```console
|
|
205
|
+
dm table-references list # id, name, connection (ID), source
|
|
206
|
+
dm table-references get <name> # Show full details
|
|
207
|
+
dm table-references create --file reference.json # Create/update from JSON — connection must be an ID, not a name
|
|
208
|
+
dm table-references create --name <name> --connection <name-or-id> --source <path-or-schema.table>
|
|
209
|
+
dm table-references create --name <name> --connection <name-or-id> --source data.csv --format parquet # Format is explicit, never inferred from --source
|
|
210
|
+
dm table-references update <name> --source <new-path> # Change selected fields, preserving the id
|
|
211
|
+
dm table-references update <name> --delimiter ';' --null-string NULL # Any CSV/format flag replaces options wholesale, not a merge
|
|
212
|
+
dm table-references delete <name> # Delete a table reference
|
|
213
|
+
```
|
|
214
|
+
|
|
202
215
|
### In-flight masking
|
|
203
216
|
|
|
204
217
|
The IFM service runs alongside the admin server,
|
|
@@ -167,6 +167,19 @@ dm libraries status <name> # Validation status; poll afte
|
|
|
167
167
|
dm libraries usage <name> # Show rulesets using it
|
|
168
168
|
```
|
|
169
169
|
|
|
170
|
+
### Table references
|
|
171
|
+
|
|
172
|
+
```console
|
|
173
|
+
dm table-references list # id, name, connection (ID), source
|
|
174
|
+
dm table-references get <name> # Show full details
|
|
175
|
+
dm table-references create --file reference.json # Create/update from JSON — connection must be an ID, not a name
|
|
176
|
+
dm table-references create --name <name> --connection <name-or-id> --source <path-or-schema.table>
|
|
177
|
+
dm table-references create --name <name> --connection <name-or-id> --source data.csv --format parquet # Format is explicit, never inferred from --source
|
|
178
|
+
dm table-references update <name> --source <new-path> # Change selected fields, preserving the id
|
|
179
|
+
dm table-references update <name> --delimiter ';' --null-string NULL # Any CSV/format flag replaces options wholesale, not a merge
|
|
180
|
+
dm table-references delete <name> # Delete a table reference
|
|
181
|
+
```
|
|
182
|
+
|
|
170
183
|
### In-flight masking
|
|
171
184
|
|
|
172
185
|
The IFM service runs alongside the admin server,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: datamasque-cli
|
|
3
|
-
description: Use when the user wants to interact with a DataMasque instance — start masking runs, check run status, list connections or rulesets, manage seeds, manage ruleset libraries, check system health, configure the AI Engine, or any task involving the DataMasque API. Triggers on "mask the data", "start a run", "check the run", "list connections", "list rulesets", "upload a seed", "check DataMasque health", "dm status", "ruleset library", "configure the AI Engine", "set the AI Engine URL", or any request to operate DataMasque programmatically.
|
|
3
|
+
description: Use when the user wants to interact with a DataMasque instance — start masking runs, check run status, list connections or rulesets, manage seeds, manage ruleset libraries, manage table references, check system health, configure the AI Engine, or any task involving the DataMasque API. Triggers on "mask the data", "start a run", "check the run", "list connections", "list rulesets", "upload a seed", "check DataMasque health", "dm status", "ruleset library", "table reference", "cross-system consistent masking", "configure the AI Engine", "set the AI Engine URL", or any request to operate DataMasque programmatically.
|
|
4
4
|
argument-hint: e.g. "start a run with docx_masking on var_input_docx"
|
|
5
5
|
user-invocable: true
|
|
6
6
|
---
|
|
@@ -113,3 +113,12 @@ Pass repeated `--options key=value` for server-side knobs
|
|
|
113
113
|
`dm run start -c <x>`, `dm discover schema <x>`, etc. all try the name
|
|
114
114
|
first and fall back to a UUID match. Prefer names for readability;
|
|
115
115
|
reach for UUIDs only when names collide (rare).
|
|
116
|
+
|
|
117
|
+
- **Table references are the identity map behind cross-system consistent
|
|
118
|
+
masking.** `dm table-references create --name <n> --connection <c>
|
|
119
|
+
--source <path-or-schema.table>` registers one; a ruleset then addresses
|
|
120
|
+
it by name via the `table_reference` hash source in `hash_columns`
|
|
121
|
+
(`source_key`/`target_key`/`value`) — this CLI doesn't generate or
|
|
122
|
+
validate that ruleset syntax. `create` is create-or-update like
|
|
123
|
+
`dm connections create`; `--file`'s JSON needs a connection **ID**, not
|
|
124
|
+
a name, unlike the `--connection` flag.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "datamasque-cli"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "1.6.0"
|
|
4
4
|
description = "Official command-line interface for the DataMasque data-masking platform."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "DataMasque Ltd" },
|
|
@@ -13,7 +13,7 @@ dependencies = [
|
|
|
13
13
|
"typer>=0.16.0,<1",
|
|
14
14
|
"rich>=13.8",
|
|
15
15
|
"tomli-w>=1.0.0,<2",
|
|
16
|
-
"datamasque-python>=1.2.
|
|
16
|
+
"datamasque-python>=1.2.5,<2",
|
|
17
17
|
"pydantic>=2.5,<3",
|
|
18
18
|
]
|
|
19
19
|
classifiers = [
|
|
@@ -10,6 +10,7 @@ import os
|
|
|
10
10
|
|
|
11
11
|
from datamasque.client import DataMasqueClient, DataMasqueIfmClient
|
|
12
12
|
from datamasque.client.exceptions import DataMasqueApiError, DataMasqueTransportError, IfmAuthError
|
|
13
|
+
from datamasque.client.models.connection import ConnectionConfig
|
|
13
14
|
from datamasque.client.models.dm_instance import DataMasqueInstanceConfig
|
|
14
15
|
from datamasque.client.models.ifm import DataMasqueIfmInstanceConfig
|
|
15
16
|
|
|
@@ -212,3 +213,12 @@ def get_ifm_client(profile_name: str | None = None) -> DataMasqueIfmClient:
|
|
|
212
213
|
extra_auth_excs=(IfmAuthError,),
|
|
213
214
|
)
|
|
214
215
|
return client
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def resolve_connection(client: DataMasqueClient, name_or_id: str) -> ConnectionConfig:
|
|
219
|
+
"""Resolve a connection by name or ID via the connection listing, aborting when not found."""
|
|
220
|
+
connections = client.list_connections()
|
|
221
|
+
match = next((c for c in connections if c.name == name_or_id or str(c.id) == name_or_id), None)
|
|
222
|
+
if match is None:
|
|
223
|
+
abort(f"Connection '{name_or_id}' not found.", code=ErrorCode.NOT_FOUND)
|
|
224
|
+
return match
|
|
@@ -20,8 +20,9 @@ from datamasque.client.models.connection import (
|
|
|
20
20
|
S3ConnectionConfig,
|
|
21
21
|
SnowflakeConnectionConfig,
|
|
22
22
|
)
|
|
23
|
+
from pydantic import ValidationError
|
|
23
24
|
|
|
24
|
-
from datamasque_cli.client import get_client
|
|
25
|
+
from datamasque_cli.client import get_client, resolve_connection
|
|
25
26
|
from datamasque_cli.errors import ErrorCode, abort, abort_api_error, confirm_or_abort
|
|
26
27
|
from datamasque_cli.fileio import read_json_object_or_abort
|
|
27
28
|
from datamasque_cli.output import print_success, redact_sensitive_fields, render_output
|
|
@@ -218,7 +219,10 @@ def _create_from_file(client: DataMasqueClient, file: Path) -> None:
|
|
|
218
219
|
data["database_type"] = DatabaseType(data["database_type"])
|
|
219
220
|
|
|
220
221
|
klass = _CONNECTION_CLASSES[conn_type]
|
|
221
|
-
|
|
222
|
+
try:
|
|
223
|
+
config = klass(**data)
|
|
224
|
+
except ValidationError as exc:
|
|
225
|
+
abort(f"{file} does not match the expected format: {exc}", code=ErrorCode.INVALID_INPUT)
|
|
222
226
|
client.create_or_update_connection(config)
|
|
223
227
|
print_success(f"Connection '{config.name}' created/updated.")
|
|
224
228
|
|
|
@@ -298,10 +302,7 @@ def test_connection(
|
|
|
298
302
|
success, a warning, or a hard failure.
|
|
299
303
|
"""
|
|
300
304
|
client = get_client(profile)
|
|
301
|
-
|
|
302
|
-
match = next((c for c in client.list_connections() if c.name == name or str(c.id) == name), None)
|
|
303
|
-
if match is None:
|
|
304
|
-
abort(f"Connection '{name}' not found.", code=ErrorCode.NOT_FOUND)
|
|
305
|
+
match = resolve_connection(client, name)
|
|
305
306
|
|
|
306
307
|
try:
|
|
307
308
|
response = client.make_request("POST", f"/api/connections/{match.id}/test/", data={})
|
|
@@ -334,10 +335,7 @@ def update_connection(
|
|
|
334
335
|
references it stays intact. Pass only the fields that should change.
|
|
335
336
|
"""
|
|
336
337
|
client = get_client(profile)
|
|
337
|
-
|
|
338
|
-
match = next((c for c in client.list_connections() if c.name == name or str(c.id) == name), None)
|
|
339
|
-
if match is None:
|
|
340
|
-
abort(f"Connection '{name}' not found.", code=ErrorCode.NOT_FOUND)
|
|
338
|
+
match = resolve_connection(client, name)
|
|
341
339
|
|
|
342
340
|
updates: dict[str, object] = {
|
|
343
341
|
key: value
|
|
@@ -23,7 +23,7 @@ from datamasque.client.models.discovery import (
|
|
|
23
23
|
from datamasque.client.models.discovery_config import DiscoveryConfigId, DiscoveryConfigType
|
|
24
24
|
from datamasque.client.models.status import MaskingRunStatus
|
|
25
25
|
|
|
26
|
-
from datamasque_cli.client import get_client
|
|
26
|
+
from datamasque_cli.client import get_client, resolve_connection
|
|
27
27
|
from datamasque_cli.commands import discovery_config_libraries, discovery_configs
|
|
28
28
|
from datamasque_cli.errors import (
|
|
29
29
|
ErrorCode,
|
|
@@ -79,14 +79,6 @@ def _write_or_echo(content: str, output: Path | None, success_label: str) -> Non
|
|
|
79
79
|
print_success(f"{success_label} written to {output}")
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
def _resolve_connection_id(client: DataMasqueClient, name_or_id: str) -> str:
|
|
83
|
-
"""Resolve a connection name or ID to its UUID string."""
|
|
84
|
-
match = next((c for c in client.list_connections() if c.name == name_or_id or str(c.id) == name_or_id), None)
|
|
85
|
-
if match is None:
|
|
86
|
-
abort(f"Connection '{name_or_id}' not found.", code=ErrorCode.NOT_FOUND)
|
|
87
|
-
return str(match.id)
|
|
88
|
-
|
|
89
|
-
|
|
90
82
|
def _resolve_discovery_config_id(
|
|
91
83
|
client: DataMasqueClient, name: str, expected_type: DiscoveryConfigType
|
|
92
84
|
) -> DiscoveryConfigId:
|
|
@@ -126,7 +118,7 @@ def schema_discovery(
|
|
|
126
118
|
(poll with `dm run status <run-id>`).
|
|
127
119
|
"""
|
|
128
120
|
client = get_client(profile)
|
|
129
|
-
conn_id =
|
|
121
|
+
conn_id = str(resolve_connection(client, connection).id)
|
|
130
122
|
|
|
131
123
|
try:
|
|
132
124
|
if config is not None:
|
|
@@ -168,7 +160,7 @@ def start_file_discovery(
|
|
|
168
160
|
(poll with `dm run status <run-id>`).
|
|
169
161
|
"""
|
|
170
162
|
client = get_client(profile)
|
|
171
|
-
conn_id =
|
|
163
|
+
conn_id = str(resolve_connection(client, connection).id)
|
|
172
164
|
|
|
173
165
|
try:
|
|
174
166
|
if config is not None:
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"""Table reference management commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from http import HTTPStatus
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
from datamasque.client import DataMasqueClient
|
|
10
|
+
from datamasque.client.exceptions import DataMasqueApiError
|
|
11
|
+
from datamasque.client.models.connection import ConnectionId
|
|
12
|
+
from datamasque.client.models.table_reference import TableReference, TableReferenceFormat, TableReferenceOptions
|
|
13
|
+
|
|
14
|
+
from datamasque_cli.client import get_client, resolve_connection
|
|
15
|
+
from datamasque_cli.errors import ErrorCode, abort, abort_api_error, confirm_or_abort
|
|
16
|
+
from datamasque_cli.fileio import read_model_or_abort
|
|
17
|
+
from datamasque_cli.output import print_success, render_output
|
|
18
|
+
|
|
19
|
+
app = typer.Typer(
|
|
20
|
+
help=(
|
|
21
|
+
"Manage table references — named pointers to identity data (a CSV/Parquet file in a file "
|
|
22
|
+
"connection, or a schema.table in a database connection) that a ruleset addresses by name "
|
|
23
|
+
"for cross-system consistent masking."
|
|
24
|
+
),
|
|
25
|
+
no_args_is_help=True,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
_SOURCE_HELP = "File path within the connection (file connections), or a dotted schema.table (database connections)"
|
|
29
|
+
_CSV_OPTION_HELP = "(file connections using --format csv only)"
|
|
30
|
+
_CREATE_FORMAT_HELP = "csv if unset (server default), or parquet — file connections only, never inferred from --source"
|
|
31
|
+
_UPDATE_FORMAT_HELP = "csv or parquet, unchanged if omitted — file connections only, never inferred from --source"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _abort_if_unsupported(exc: DataMasqueApiError) -> None:
|
|
35
|
+
"""Explain a 404 from the table-references listing as an absent feature, not an absent object.
|
|
36
|
+
|
|
37
|
+
The listing endpoint takes no name filter, so both readers below fetch the whole collection.
|
|
38
|
+
A 404 from either therefore means the route itself is missing on an older server. Only the
|
|
39
|
+
readers may use this: a write targets `/api/table-references/<id>/`, where a 404 means that
|
|
40
|
+
one reference is gone.
|
|
41
|
+
"""
|
|
42
|
+
if exc.response.status_code != HTTPStatus.NOT_FOUND:
|
|
43
|
+
return
|
|
44
|
+
abort("Table references are not supported by this DataMasque version.", code=ErrorCode.NOT_FOUND)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _list_or_abort(client: DataMasqueClient) -> list[TableReference]:
|
|
48
|
+
"""Return every table reference, or abort with the reason the listing failed."""
|
|
49
|
+
try:
|
|
50
|
+
# `datamasque.*` is exempted from mypy's `follow_imports`, so the SDK call resolves to
|
|
51
|
+
# `Any` here even though `list_table_references` itself declares `-> list[TableReference]`.
|
|
52
|
+
references: list[TableReference] = client.list_table_references()
|
|
53
|
+
return references
|
|
54
|
+
except DataMasqueApiError as exc:
|
|
55
|
+
_abort_if_unsupported(exc)
|
|
56
|
+
abort_api_error("Failed to list table references", exc)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _get_or_abort(client: DataMasqueClient, name: str) -> TableReference | None:
|
|
60
|
+
"""Return the table reference named `name`, or `None`, or abort with the reason the lookup failed."""
|
|
61
|
+
try:
|
|
62
|
+
reference: TableReference | None = client.get_table_reference_by_name(name)
|
|
63
|
+
return reference
|
|
64
|
+
except DataMasqueApiError as exc:
|
|
65
|
+
_abort_if_unsupported(exc)
|
|
66
|
+
abort_api_error(f"Failed to look up table reference '{name}'", exc)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@app.command("list")
|
|
70
|
+
def list_references(
|
|
71
|
+
profile: str | None = typer.Option(None, "--profile", "-p", help="Profile to use"),
|
|
72
|
+
is_json: bool = typer.Option(False, "--json", help="Output as JSON"),
|
|
73
|
+
) -> None:
|
|
74
|
+
"""List all table references."""
|
|
75
|
+
client = get_client(profile)
|
|
76
|
+
references = _list_or_abort(client)
|
|
77
|
+
|
|
78
|
+
data = [
|
|
79
|
+
{
|
|
80
|
+
"id": ref.id,
|
|
81
|
+
"name": ref.name,
|
|
82
|
+
"connection": ref.connection_id,
|
|
83
|
+
"source": ref.source,
|
|
84
|
+
}
|
|
85
|
+
for ref in references
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
render_output(data, is_json=is_json, columns=["id", "name", "connection", "source"], title="Table References")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@app.command("get")
|
|
92
|
+
def get_reference(
|
|
93
|
+
name: str = typer.Argument(help="Table reference name"),
|
|
94
|
+
profile: str | None = typer.Option(None, "--profile", "-p", help="Profile to use"),
|
|
95
|
+
is_json: bool = typer.Option(False, "--json", help="Output as JSON"),
|
|
96
|
+
) -> None:
|
|
97
|
+
"""Show details for a specific table reference."""
|
|
98
|
+
client = get_client(profile)
|
|
99
|
+
reference = _get_or_abort(client, name)
|
|
100
|
+
if reference is None:
|
|
101
|
+
abort(f"Table reference '{name}' not found.", code=ErrorCode.NOT_FOUND)
|
|
102
|
+
|
|
103
|
+
options = reference.options
|
|
104
|
+
data: dict[str, object] = {
|
|
105
|
+
"id": reference.id,
|
|
106
|
+
"name": reference.name,
|
|
107
|
+
"connection": reference.connection_id,
|
|
108
|
+
"source": reference.source,
|
|
109
|
+
"format": options.format.value if options else None,
|
|
110
|
+
"delimiter": options.delimiter if options else None,
|
|
111
|
+
"encoding": options.encoding if options else None,
|
|
112
|
+
"quotechar": options.quotechar if options else None,
|
|
113
|
+
"null_string": options.null_string if options else None,
|
|
114
|
+
"created": reference.created,
|
|
115
|
+
"modified": reference.modified,
|
|
116
|
+
}
|
|
117
|
+
render_output(data, is_json=is_json, title=f"Table Reference: {name}")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _resolve_connection_id(client: DataMasqueClient, name_or_id: str) -> ConnectionId:
|
|
121
|
+
"""Resolve a `--connection` value (name or ID) to a connection ID."""
|
|
122
|
+
return resolve_connection(client, name_or_id).id
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _option_overrides(
|
|
126
|
+
file_format: TableReferenceFormat | None,
|
|
127
|
+
delimiter: str | None,
|
|
128
|
+
encoding: str | None,
|
|
129
|
+
quotechar: str | None,
|
|
130
|
+
null_string: str | None,
|
|
131
|
+
) -> dict[str, object]:
|
|
132
|
+
"""Return only the format/CSV fields that were explicitly passed."""
|
|
133
|
+
overrides: dict[str, object] = {}
|
|
134
|
+
if file_format is not None:
|
|
135
|
+
overrides["format"] = file_format
|
|
136
|
+
if delimiter is not None:
|
|
137
|
+
overrides["delimiter"] = delimiter
|
|
138
|
+
if encoding is not None:
|
|
139
|
+
overrides["encoding"] = encoding
|
|
140
|
+
if quotechar is not None:
|
|
141
|
+
overrides["quotechar"] = quotechar
|
|
142
|
+
if null_string is not None:
|
|
143
|
+
overrides["null_string"] = null_string
|
|
144
|
+
return overrides
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@app.command("create")
|
|
148
|
+
def create_reference(
|
|
149
|
+
file: Path | None = typer.Option(None, "--file", "-f", help="JSON file defining the table reference"),
|
|
150
|
+
name: str | None = typer.Option(None, help="Table reference name"),
|
|
151
|
+
connection: str | None = typer.Option(None, help="Connection (name or ID) the data lives in"),
|
|
152
|
+
source: str | None = typer.Option(None, help=_SOURCE_HELP),
|
|
153
|
+
file_format: TableReferenceFormat | None = typer.Option(None, "--format", help=_CREATE_FORMAT_HELP),
|
|
154
|
+
delimiter: str | None = typer.Option(None, help=f"CSV delimiter {_CSV_OPTION_HELP}"),
|
|
155
|
+
encoding: str | None = typer.Option(None, help=f"CSV encoding {_CSV_OPTION_HELP}"),
|
|
156
|
+
quotechar: str | None = typer.Option(None, help=f"CSV quote character {_CSV_OPTION_HELP}"),
|
|
157
|
+
null_string: str | None = typer.Option(None, help=f"String read as null {_CSV_OPTION_HELP}"),
|
|
158
|
+
profile: str | None = typer.Option(None, "--profile", "-p", help="Profile to use"),
|
|
159
|
+
) -> None:
|
|
160
|
+
"""Create or update a table reference.
|
|
161
|
+
|
|
162
|
+
Use --file for full control (JSON), or flags for the common case.
|
|
163
|
+
|
|
164
|
+
Examples:
|
|
165
|
+
|
|
166
|
+
# From JSON file
|
|
167
|
+
dm table-references create --file reference.json
|
|
168
|
+
|
|
169
|
+
# Quick file-connection reference
|
|
170
|
+
dm table-references create --name customer_identities \\
|
|
171
|
+
--connection input --source identities/customers.csv
|
|
172
|
+
|
|
173
|
+
# Quick database-connection reference
|
|
174
|
+
dm table-references create --name customer_identities \\
|
|
175
|
+
--connection mydb --source public.customers
|
|
176
|
+
"""
|
|
177
|
+
client = get_client(profile)
|
|
178
|
+
|
|
179
|
+
if file is not None:
|
|
180
|
+
other_flags_passed = any(
|
|
181
|
+
value is not None
|
|
182
|
+
for value in (name, connection, source, file_format, delimiter, encoding, quotechar, null_string)
|
|
183
|
+
)
|
|
184
|
+
if other_flags_passed:
|
|
185
|
+
abort(
|
|
186
|
+
"--file cannot be combined with --name/--connection/--source/--format/CSV-option flags.",
|
|
187
|
+
code=ErrorCode.INVALID_INPUT,
|
|
188
|
+
)
|
|
189
|
+
_create_from_file(client, file)
|
|
190
|
+
return
|
|
191
|
+
|
|
192
|
+
if name is None or connection is None or source is None:
|
|
193
|
+
abort("Provide either --file or all of --name, --connection, and --source.", code=ErrorCode.INVALID_INPUT)
|
|
194
|
+
|
|
195
|
+
overrides = _option_overrides(file_format, delimiter, encoding, quotechar, null_string)
|
|
196
|
+
reference = TableReference(
|
|
197
|
+
name=name,
|
|
198
|
+
connection=_resolve_connection_id(client, connection),
|
|
199
|
+
source=source,
|
|
200
|
+
options=TableReferenceOptions(**overrides) if overrides else None,
|
|
201
|
+
)
|
|
202
|
+
_create_or_update(client, reference)
|
|
203
|
+
print_success(f"Table reference '{name}' created/updated.")
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _create_from_file(client: DataMasqueClient, file: Path) -> None:
|
|
207
|
+
"""Create a table reference from a JSON file."""
|
|
208
|
+
reference = read_model_or_abort(file, TableReference)
|
|
209
|
+
_create_or_update(client, reference)
|
|
210
|
+
print_success(f"Table reference '{reference.name}' created/updated.")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _create_or_update(client: DataMasqueClient, reference: TableReference) -> None:
|
|
214
|
+
"""Create or update `reference`, distinguishing an unsupported server from any other failure.
|
|
215
|
+
|
|
216
|
+
`create_or_update_table_reference` itself makes two requests (a GET to look up an existing
|
|
217
|
+
reference by name, then a POST or PUT), so probe support with `_get_or_abort` first and let
|
|
218
|
+
a 404 from the create/update call surface as a plain API error instead of being misread as
|
|
219
|
+
"not supported".
|
|
220
|
+
"""
|
|
221
|
+
_get_or_abort(client, reference.name)
|
|
222
|
+
try:
|
|
223
|
+
client.create_or_update_table_reference(reference)
|
|
224
|
+
except DataMasqueApiError as exc:
|
|
225
|
+
abort_api_error(f"Failed to create/update table reference '{reference.name}'", exc)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
@app.command("update")
|
|
229
|
+
def update_reference(
|
|
230
|
+
name: str = typer.Argument(help="Table reference name to update"),
|
|
231
|
+
connection: str | None = typer.Option(None, help="New connection (name or ID)"),
|
|
232
|
+
source: str | None = typer.Option(None, help=f"New source. {_SOURCE_HELP}"),
|
|
233
|
+
file_format: TableReferenceFormat | None = typer.Option(None, "--format", help=_UPDATE_FORMAT_HELP),
|
|
234
|
+
delimiter: str | None = typer.Option(None, help=f"New CSV delimiter {_CSV_OPTION_HELP}"),
|
|
235
|
+
encoding: str | None = typer.Option(None, help=f"New CSV encoding {_CSV_OPTION_HELP}"),
|
|
236
|
+
quotechar: str | None = typer.Option(None, help=f"New CSV quote character {_CSV_OPTION_HELP}"),
|
|
237
|
+
null_string: str | None = typer.Option(None, help=f"New null-string value {_CSV_OPTION_HELP}"),
|
|
238
|
+
profile: str | None = typer.Option(None, "--profile", "-p", help="Profile to use"),
|
|
239
|
+
) -> None:
|
|
240
|
+
"""Update selected fields on an existing table reference, preserving its ID."""
|
|
241
|
+
overrides = _option_overrides(file_format, delimiter, encoding, quotechar, null_string)
|
|
242
|
+
if connection is None and source is None and not overrides:
|
|
243
|
+
abort("Pass at least one field to update (e.g. --source, --format).", code=ErrorCode.INVALID_INPUT)
|
|
244
|
+
|
|
245
|
+
client = get_client(profile)
|
|
246
|
+
reference = _get_or_abort(client, name)
|
|
247
|
+
if reference is None:
|
|
248
|
+
abort(f"Table reference '{name}' not found.", code=ErrorCode.NOT_FOUND)
|
|
249
|
+
|
|
250
|
+
if connection is not None:
|
|
251
|
+
reference.connection = _resolve_connection_id(client, connection)
|
|
252
|
+
if source is not None:
|
|
253
|
+
reference.source = source
|
|
254
|
+
if overrides:
|
|
255
|
+
# A full PUT can't send a sparse options object, so a reference with no prior options
|
|
256
|
+
# gets the untouched fields filled with `TableReferenceOptions`' own declared defaults —
|
|
257
|
+
# there's no other value to send for them.
|
|
258
|
+
base_options = reference.options or TableReferenceOptions()
|
|
259
|
+
reference.options = base_options.model_copy(update=overrides)
|
|
260
|
+
|
|
261
|
+
try:
|
|
262
|
+
client.update_table_reference(reference)
|
|
263
|
+
except DataMasqueApiError as exc:
|
|
264
|
+
abort_api_error(f"Failed to update table reference '{name}'", exc)
|
|
265
|
+
print_success(f"Table reference '{name}' updated.")
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@app.command("delete")
|
|
269
|
+
def delete_reference(
|
|
270
|
+
name: str = typer.Argument(help="Table reference name to delete"),
|
|
271
|
+
profile: str | None = typer.Option(None, "--profile", "-p", help="Profile to use"),
|
|
272
|
+
is_confirmed: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation"),
|
|
273
|
+
) -> None:
|
|
274
|
+
"""Delete a table reference by name."""
|
|
275
|
+
client = get_client(profile)
|
|
276
|
+
reference = _get_or_abort(client, name)
|
|
277
|
+
if reference is None:
|
|
278
|
+
abort(f"Table reference '{name}' not found.", code=ErrorCode.NOT_FOUND)
|
|
279
|
+
|
|
280
|
+
if not is_confirmed:
|
|
281
|
+
confirm_or_abort(f"Delete table reference '{name}'?")
|
|
282
|
+
|
|
283
|
+
try:
|
|
284
|
+
client.delete_table_reference_by_name_if_exists(name)
|
|
285
|
+
except DataMasqueApiError as exc:
|
|
286
|
+
abort_api_error(f"Failed to delete table reference '{name}'", exc)
|
|
287
|
+
print_success(f"Table reference '{name}' deleted.")
|
|
@@ -9,7 +9,8 @@ from __future__ import annotations
|
|
|
9
9
|
import json
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
|
|
12
|
-
from
|
|
12
|
+
from datamasque.client.models.table_reference import TableReference
|
|
13
|
+
from pydantic import JsonValue, ValidationError
|
|
13
14
|
|
|
14
15
|
from datamasque_cli.errors import ErrorCode, abort
|
|
15
16
|
|
|
@@ -60,6 +61,15 @@ def read_json_object_or_abort(file: Path) -> dict[str, JsonValue]:
|
|
|
60
61
|
return parsed
|
|
61
62
|
|
|
62
63
|
|
|
64
|
+
def read_model_or_abort(file: Path, model: type[TableReference]) -> TableReference:
|
|
65
|
+
"""Read `file` as a JSON object matching `model`, and abort when it does not."""
|
|
66
|
+
data = read_json_object_or_abort(file)
|
|
67
|
+
try:
|
|
68
|
+
return model.model_validate(data)
|
|
69
|
+
except ValidationError as exc:
|
|
70
|
+
abort(f"{file} does not match the expected format: {exc}", code=ErrorCode.INVALID_INPUT)
|
|
71
|
+
|
|
72
|
+
|
|
63
73
|
def write_bytes_or_abort(path: Path, content: bytes) -> None:
|
|
64
74
|
"""Write `content` to `path`, and abort when the path cannot be written."""
|
|
65
75
|
try:
|
|
@@ -32,6 +32,7 @@ from datamasque_cli.commands import (
|
|
|
32
32
|
runs,
|
|
33
33
|
seeds,
|
|
34
34
|
system,
|
|
35
|
+
table_references,
|
|
35
36
|
users,
|
|
36
37
|
)
|
|
37
38
|
from datamasque_cli.errors import ErrorCode, abort, abort_api_error
|
|
@@ -63,6 +64,7 @@ app.add_typer(files.app, name="files")
|
|
|
63
64
|
app.add_typer(system.app, name="system")
|
|
64
65
|
app.add_typer(ruleset_libraries.app, name="libraries")
|
|
65
66
|
app.add_typer(ifm.app, name="ifm")
|
|
67
|
+
app.add_typer(table_references.app, name="table-references")
|
|
66
68
|
|
|
67
69
|
|
|
68
70
|
@app.command()
|
|
@@ -168,6 +168,25 @@ def test_create_connection_from_json_file(mock_get_client: MagicMock, runner: Cl
|
|
|
168
168
|
client.create_or_update_connection.assert_called_once()
|
|
169
169
|
|
|
170
170
|
|
|
171
|
+
@patch(f"{MODULE}.get_client")
|
|
172
|
+
def test_create_connection_from_json_file_invalid_schema_aborts(
|
|
173
|
+
mock_get_client: MagicMock, runner: CliRunner, tmp_path: MagicMock
|
|
174
|
+
) -> None:
|
|
175
|
+
"""Valid JSON that doesn't match the connection type's schema aborts cleanly instead of raising."""
|
|
176
|
+
client = MagicMock()
|
|
177
|
+
mock_get_client.return_value = client
|
|
178
|
+
|
|
179
|
+
conn_file = tmp_path / "conn.json"
|
|
180
|
+
conn_file.write_text(json.dumps({"type": "database", "name": "from_file"}))
|
|
181
|
+
|
|
182
|
+
result = runner.invoke(app, ["connections", "create", "--file", str(conn_file)])
|
|
183
|
+
|
|
184
|
+
assert result.exit_code == ExitCode.INVALID_INPUT
|
|
185
|
+
assert "does not match the expected format" in " ".join(result.stderr.lower().split())
|
|
186
|
+
assert "Traceback" not in result.stderr
|
|
187
|
+
client.create_or_update_connection.assert_not_called()
|
|
188
|
+
|
|
189
|
+
|
|
171
190
|
@patch(f"{MODULE}.get_client")
|
|
172
191
|
def test_create_databricks_connection_from_json_file(
|
|
173
192
|
mock_get_client: MagicMock, runner: CliRunner, tmp_path: MagicMock
|