Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ so no DataMasque server is required.
### Integration tests

`tests/integration/` hits a real DataMasque instance to catch the bugs unit tests can't —
ruleset namespace collisions,
a database and a file ruleset sharing a name,
delete targeting,
server-state resolution,
and the full `run start → retry → logs --follow` lifecycle.
Expand Down
68 changes: 60 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ For instances with self-signed or expired TLS certificates
pass `--insecure` to `dm auth login` to persist the toggle on the profile,
or set `DATAMASQUE_VERIFY_SSL=false` to skip verification per call.

## Projects

Every connection, ruleset, library, discovery config, seed, file and table reference belongs to one project.
This CLI needs a DataMasque version with projects (v3.26.22.0 or later); use an earlier CLI release with older versions.

- `--project` takes a project name (any case) or its numeric ID.
- List commands show each resource's project, and `--project` lists only that project's resources
(plus the built-in seeds, for `dm seeds list`).
- Create, upload and validate commands put the resource in the `--project` project.
Without `--project`, a create updates the resource of that name in the one project that has it
(for rulesets and discovery configs, the one of the same type).
Otherwise they use the instance's only project, and fail asking for one when there are several.
- Get, update and delete commands find a resource by name in any project.
When the name exists in more than one project they fail asking for `--project`.

```console
dm rulesets list --project Finance
dm rulesets create --name customers --file rules.yaml --type database --project Finance
dm seeds upload names.csv --project Finance
dm run start -c finance_db -r customers --project Finance
```

## Commands

### Authentication
Expand Down Expand Up @@ -148,9 +170,11 @@ dm rulesets generate --file request.json # Generate from schema
dm rulesets generate --file req.json -o out.yaml # Generate to file
dm rulesets validate --file rules.yaml --type database|file # Validate against server (YAML under 60 KiB)
dm rulesets status <name> # Validation status; poll after creating YAML of 60 KiB+
dm rulesets export-bundle -o bundle.zip # Export rulesets + libraries + seeds
dm rulesets export-bundle -o bundle.zip # Export rulesets + libraries, by project
dm rulesets export-bundle -o bundle.zip --include-seed-files # Also bundle the custom seed files they use
dm rulesets import-bundle --file bundle.zip # Import a previously exported bundle
dm rulesets import-bundle -f bundle.zip --overwrite-rulesets --overwrite-libraries # Replace existing entries
dm rulesets import-bundle -f bundle.zip --fallback-project <project> # Project for items filed under none
```

### Ruleset libraries
Expand All @@ -160,11 +184,11 @@ dm libraries list # List all libraries
dm libraries get <name> # Show library details
dm libraries get <name> --yaml # Print raw YAML only
dm libraries create --name <n> --file lib.yaml # Create/update from file
dm libraries create --name <n> --file lib.yaml --namespace pii # With namespace
dm libraries create --name <n> --file lib.yaml --project pii # In a given project
dm libraries delete <name> # Delete a library
dm libraries validate <name> # Re-validate against current server schema
dm libraries status <name> # Validation status; poll after creating YAML of 60 KiB+
dm libraries usage <name> # Show rulesets using it
dm libraries usage <name> # Show rulesets using it, with their projects
```

### Table references
Expand All @@ -180,6 +204,34 @@ dm table-references update <name> --delimiter ';' --null-string NULL # Any CS
dm table-references delete <name> # Delete a table reference
```

### Projects

```console
dm projects list # id, name, description, created
dm projects list --include-deleted # Adds deleted projects, with a deleted column
dm projects get <name-or-id> # Show a project's details
dm projects create --name <name> --description "<text>"
dm projects update <name-or-id> --name <new-name> # Rename; --description changes the description
dm projects delete <name-or-id> --to <name-or-id> # Move every resource to the --to project, then delete
dm projects delete <name-or-id> --to <name-or-id> --check # Only list what would stop the delete
```

Creating, renaming and deleting projects needs an admin user.
Renaming makes rulesets and configurations that import one of the project's libraries by the old project name invalid.

### Moving resources

```console
dm resources move --project Finance --to Archive # Every resource in Finance
dm resources move customers orders --type rulesets --to Archive # Rulesets with these exact names, from any project
dm resources move --search payroll --to HR --check # Only list the matches and what would stop them moving
```

Resources move with their files and runs. `--project`, `--type`, `--search` and names combine; pass at least one.
All of the resources move, or none do. A resource that clashes with the destination (same name, or a file in the way)
stops the move, and the command exits with the `conflict` code, listing each one. A resource already in the
destination stays there, and the others move.

### In-flight masking

The IFM service runs alongside the admin server,
Expand Down Expand Up @@ -260,11 +312,11 @@ The same library can be imported by both database and file discovery configs.

```console
dm discover libraries list
dm discover libraries get <name> [--namespace org] [--yaml]
dm discover libraries create --name <n> --namespace org -f lib.yaml
dm discover libraries delete <name> [--namespace org] [--force] # --force if imported by configs
dm discover libraries validate -f lib.yaml
dm discover libraries status <name> [--namespace org]
dm discover libraries get <name> [--project org] [--yaml]
dm discover libraries create --name <n> --project org -f lib.yaml
dm discover libraries delete <name> [--project org] [--force] # --force if imported by configs
dm discover libraries validate -f lib.yaml [--project org]
dm discover libraries status <name> [--project org]
```

### Seeds
Expand Down
18 changes: 16 additions & 2 deletions claude-skills/datamasque-cli/skills/datamasque-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,26 @@ Pass repeated `--options key=value` for server-side knobs

## Idioms and gotchas

- **Ruleset namespaces.** `database` and `file` rulesets share a name
namespace, so `customers` can exist in both. `dm run start` reads the
- **Database and file rulesets.** A `database` and a `file` ruleset can
share a name, so `customers` can exist as both. `dm run start` reads the
source connection's type and picks the matching ruleset automatically.
For `get` / `create` / `delete`, pass `--type database|file` only when
two rows share the name and you need to disambiguate.

- **Projects.** Every resource belongs to one project, and names are unique
per project (per project and type for rulesets and discovery configs). Lists show each resource's project, and `--project <name>`
narrows a list to one project. A create with no `--project` updates the
resource of that name in the one project that has it (same type, for
rulesets and discovery configs). Otherwise a create or upload with no
`--project` goes into the instance's only project, and fails with
`ambiguous` when there are several. A get or delete fails with `ambiguous` when the name
exists in two projects; pass `--project` to pick one.
`dm projects` creates, renames and deletes projects (delete needs `--to`, the
project that takes its resources). `dm resources move --to <project>` moves
resources selected by `--project`, `--type`, `--search` or exact names; it
moves nothing and exits `conflict` when any of them clashes with the
destination. Add `--check` to only preview.

- **File masking needs a destination.** Database masking is in-place;
file masking writes through to a destination connection and fails
with `invalid_input` without `--destination`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ masks:

### Output format

`Global/RuleLib` below is a placeholder for `<namespace>/<library_name>` — substitute the operator's real values, and create the library with `dm libraries create` before running the ruleset.
`Global/RuleLib` below is a placeholder for `<project>/<library_name>` — substitute the operator's real values, and create the library with `dm libraries create` before running the ruleset.

```yaml
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Define masking logic once, reuse it everywhere.

```bash
dm libraries list # List all libraries
dm libraries get <name> [--namespace <ns>] [--yaml] # Show details or YAML
dm libraries create --name <name> --file lib.yml [--namespace <ns>]
dm libraries delete <name> [--namespace <ns>] [--force]
dm libraries usage <name> [--namespace <ns>] # Which rulesets use it
dm libraries get <name> [--project <p>] [--yaml] # Show details or YAML
dm libraries create --name <name> --file lib.yml [--project <p>]
dm libraries delete <name> [--project <p>] [--force]
dm libraries usage <name> [--project <p>] # Which rulesets use it
```

## Library Structure
Expand Down Expand Up @@ -78,8 +78,8 @@ other:
Rulesets reference library content using `$ref`:

```
$ref: "<namespace>/<library_name>#<section>/<key>"
$ref: "<library_name>#<section>/<key>" # No namespace
$ref: "<project>/<library_name>#<section>/<key>"
$ref: "<library_name>#<section>/<key>" # The ruleset's own project
$ref: "<lib>#<section>/<key>/<nested_key>" # Nested access
$ref: "<lib>#<section>/0" # Array index
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ See `ruleset-libraries-guide.md` for full details.

```yaml
imports:
- namespace/library_name
- project/library_name

tasks:
- type: mask_table
table: users
key: id
rules:
- $ref: "namespace/library_name#database_rules/email_rule"
- $ref: "project/library_name#database_rules/email_rule"
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
"typer>=0.16.0,<1",
"rich>=13.8",
"tomli-w>=1.0.0,<2",
"datamasque-python>=1.2.5,<2",
"datamasque-python>=1.6.0,<2",
"pydantic>=2.5,<3",
]
classifiers = [
Expand Down
27 changes: 21 additions & 6 deletions src/datamasque_cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from datamasque_cli.config import Config, Profile, load_config
from datamasque_cli.errors import ErrorCode, abort
from datamasque_cli.projects import filter_by_project, require_single_or_abort, resolve_optional_project

ENV_URL = "DATAMASQUE_URL"
ENV_USERNAME = "DATAMASQUE_USERNAME"
Expand Down Expand Up @@ -215,10 +216,24 @@ def get_ifm_client(profile_name: str | None = None) -> DataMasqueIfmClient:
return client


def resolve_connection(client: DataMasqueClient, name_or_id: str) -> ConnectionConfig:
"""Resolve a connection by name or ID via the connection listing, aborting when not found."""
def resolve_connection(client: DataMasqueClient, name_or_id: str, project: str | None = None) -> ConnectionConfig:
"""
Resolve a connection by name, in the project `--project` names if given, else by ID.

Aborts when nothing matches, or when the name matches connections in more than one project.
"""
connections = client.list_connections()
match = next((c for c in connections if c.name == name_or_id or str(c.id) == name_or_id), None)
if match is None:
abort(f"Connection '{name_or_id}' not found.", code=ErrorCode.NOT_FOUND)
return match
by_name = filter_by_project(
[c for c in connections if c.name == name_or_id], resolve_optional_project(client, project)
)
if not by_name:
by_id = next((c for c in connections if str(c.id) == name_or_id), None)
if by_id is not None:
return by_id
return require_single_or_abort(
client,
by_name,
f"Connection '{name_or_id}'",
describe=lambda c: f"id={c.id}",
hint="Pass --project, or the connection's id, to disambiguate.",
)
Loading
Loading