datasecops-cli 0.7.0b10__tar.gz → 0.7.0b11__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.
Files changed (91) hide show
  1. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/CHANGELOG.md +15 -3
  2. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/PKG-INFO +15 -2
  3. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/README.md +14 -1
  4. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/pyproject.toml +1 -1
  5. datasecops_cli-0.7.0b11/src/datasecops_cli/__init__.py +1 -0
  6. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/main.py +47 -15
  7. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/pipeline_env.py +42 -0
  8. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/snowflake_service.py +5 -1
  9. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/diagram.py +11 -9
  10. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_dcm_model.py +4 -3
  11. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_main.py +61 -1
  12. datasecops_cli-0.7.0b10/src/datasecops_cli/__init__.py +0 -1
  13. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/.github/workflows/auto-tag.yml +0 -0
  14. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/.github/workflows/publish-cli.yml +0 -0
  15. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/.github/workflows/test.yml +0 -0
  16. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/.gitignore +0 -0
  17. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/AGENTS.md +0 -0
  18. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/DEVELOPMENT.md +0 -0
  19. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/LICENSE +0 -0
  20. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/docs/dcm.md +0 -0
  21. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/docs/getting-started.md +0 -0
  22. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/docs/git-operations.md +0 -0
  23. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/docs/legacy.md +0 -0
  24. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/docs/legacy_plan_of_action.md +0 -0
  25. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/docs/mcp-server.md +0 -0
  26. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/mcp-servers.json +0 -0
  27. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/scripts/vendor_model.py +0 -0
  28. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/setup.ps1 +0 -0
  29. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/setup.sh +0 -0
  30. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/config.py +0 -0
  31. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/menus/__init__.py +0 -0
  32. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/menus/configuration.py +0 -0
  33. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/menus/dcm_operations.py +0 -0
  34. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/menus/development.py +0 -0
  35. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/menus/downloads.py +0 -0
  36. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/menus/git_operations.py +0 -0
  37. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/models/__init__.py +0 -0
  38. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/models/git_helpers.py +0 -0
  39. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/models/project_config.py +0 -0
  40. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/__init__.py +0 -0
  41. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/bootstrap_service.py +0 -0
  42. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/dbt_project_generator.py +0 -0
  43. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/dbt_runner.py +0 -0
  44. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/dcm_orchestrator.py +0 -0
  45. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/dcm_pipelines.py +0 -0
  46. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/dcm_registry.py +0 -0
  47. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/dcm_service.py +0 -0
  48. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/directory_scaffolder.py +0 -0
  49. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/download_service.py +0 -0
  50. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/git_service.py +0 -0
  51. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/linting_service.py +0 -0
  52. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/model_commands.py +0 -0
  53. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/skill_service.py +0 -0
  54. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/services/upstream_service.py +0 -0
  55. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/utilities/__init__.py +0 -0
  56. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/utilities/display.py +0 -0
  57. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/utilities/file_utils.py +0 -0
  58. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/utilities/mcp.py +0 -0
  59. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_cli/utilities/yaml_utils.py +0 -0
  60. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_mcp/__init__.py +0 -0
  61. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_mcp/__main__.py +0 -0
  62. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_mcp/connection.py +0 -0
  63. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_mcp/server.py +0 -0
  64. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/__init__.py +0 -0
  65. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/convert.py +0 -0
  66. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/expand.py +0 -0
  67. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/extract.py +0 -0
  68. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/render.py +0 -0
  69. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/schema.py +0 -0
  70. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/scope.py +0 -0
  71. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/scripts.py +0 -0
  72. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/starter.py +0 -0
  73. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/templates/macros/role.sql +0 -0
  74. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/templates/macros/role_guard.sql +0 -0
  75. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/templates/macros/warehouse.sql +0 -0
  76. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/src/datasecops_model/validate.py +0 -0
  77. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/__init__.py +0 -0
  78. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_config.py +0 -0
  79. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_dbt_project_generator_profiles.py +0 -0
  80. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_dbt_runner.py +0 -0
  81. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_dcm_orchestrator.py +0 -0
  82. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_dcm_service.py +0 -0
  83. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_download_service.py +0 -0
  84. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_file_utils.py +0 -0
  85. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_linting_service.py +0 -0
  86. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_mcp_lint_tools.py +0 -0
  87. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_model_commands.py +0 -0
  88. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_models.py +0 -0
  89. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_pipeline_env.py +0 -0
  90. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_version.py +0 -0
  91. {datasecops_cli-0.7.0b10 → datasecops_cli-0.7.0b11}/tests/test_yaml_utils.py +0 -0
@@ -2,7 +2,21 @@
2
2
 
3
3
  All notable changes to the DataSecOps CLI are documented in this file.
4
4
 
5
- ## [Unreleased]
5
+ ## [0.7.0b11] - 2026-11-01
6
+
7
+ ### Added
8
+
9
+ - **`pipeline env` sets a run's full context from the app** — new `--mode release|ci|clone|default`, `--run-id`, `--clone-database` and `--profile` options. Besides the dbt target, the command calls the app's `api.pipeline_context` and exports the profile's databases (`DATABASE_PREFIX`, `SOURCE_DATABASE`, `TARGET_DATABASE` for the mode), `DBT_PROJECT_NAME`, `DBT_EXCLUDE_FLAG`, the docs repository, git tag identity, manifest storage settings and `DBT_VERSION`, so pipelines no longer hardcode them and settings changes apply on the next run. Apps without the procedure still get the dbt target values (with a note); any other failure to read the context fails the command, so a run never continues with part of it. Exported names must be plain upper-case variable names.
10
+
11
+ ### Changed
12
+
13
+ - **Role diagrams no longer say "ACE"** — Entra ID security group (SCIM) roles are labelled by their name without the security prefix (no `ACE: ` in front), the security groups' box is "Entra ID security groups (SCIM)", and `datasecops model diagram`'s titles are Full hierarchy, Snowflake roles only, Entra ID functional and security groups, Entra ID groups and their Snowflake roles. The view ids are unchanged.
14
+
15
+ ### Fixed
16
+
17
+ - **`download --profile` lost its `-p` short option** — fixing a review comment about `pipeline env --profile` reusing `-p` accidentally removed the alias from `download` instead, breaking existing invocations like `datasecops download pipelines -p core`. `-p` is restored on `download --profile`, and removed from `pipeline env --profile` (the option it was meant to come off).
18
+ - **`pipeline env` accepted a variable name with a trailing newline** — `export()`'s name check used `_NAME.match()`, and `$` in a non-multiline regex matches just before a trailing newline, so `{"X\n": "1"}` from the app passed validation and corrupted the written `$GITHUB_ENV`/`##vso` output. It now uses `fullmatch()`.
19
+ - **`test_import_round_trip_is_statement_identical` failed on Windows** — it wrote rendered SQL with `Path.write_text()` and no encoding, so Windows used the system locale (cp1252) instead of UTF-8 and crashed on the em dash in the rendered header comment; the writes now pass `encoding="utf-8"`, matching how the library itself reads and writes these files.
6
20
 
7
21
  ## [0.7.0b10] - 2026-10-28
8
22
 
@@ -23,9 +37,7 @@ All notable changes to the DataSecOps CLI are documented in this file.
23
37
  ### Fixed
24
38
 
25
39
  - **`dbt build` was missing from the Development menu entirely** — `DbtRunner.build()` already existed and the README already advertised "dbt run, build, test, lint", but no menu option called it. It's now a top-level menu entry with full/modified/specific run options, mirroring `run`.
26
- =======
27
40
  - **`install-dbt` / `install-sqlfluff` failed when no version was marked active** — the CLI only used a `DBT_VERSIONS` entry with `active: true`, while the app falls back to the first enabled version, so a pipeline could fail to install dbt that the app considered configured. The CLI now uses the same fallback, and strips the `v` prefix the app stores (`v2.0.9` → `dbt==2.0.9`). Orbit pipelines now install dbt 2.0 through `datasecops download install-dbt` too (instead of a version pinned in the YAML), so they follow the version active in the app without re-rendering.
28
- >>>>>>> b0b3c02 (Fall back to the first enabled version when none is active)
29
41
 
30
42
  ## [0.7.0b8] - 2026-10-27
31
43
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: datasecops-cli
3
- Version: 0.7.0b10
3
+ Version: 0.7.0b11
4
4
  Summary: DataSecOps Framework CLI for Snowflake Native App
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -182,9 +182,22 @@ the branch, so pipelines don't hard-code them:
182
182
  ```bash
183
183
  datasecops pipeline env --branch "$GITHUB_REF_NAME" # GitHub Actions: target whose Branch is this branch
184
184
  datasecops pipeline env --branch "$BUILD_SOURCEBRANCH" # Azure DevOps (the full ref, not BUILD_SOURCEBRANCHNAME)
185
- datasecops pipeline env --target unit-test # a named target
185
+ datasecops pipeline env --target unit-test --mode ci --run-id "$GITHUB_RUN_ID" # a unit-test run
186
186
  ```
187
187
 
188
+ With an app that has `api.pipeline_context`, the command also sets the run's other values from the
189
+ app's settings, so changing them in the app applies on the next run without regenerating the pipelines:
190
+
191
+ | Variable | From |
192
+ |---|---|
193
+ | `DBT_PROJECT_NAME`, `DATABASE_PREFIX`, `SOURCE_DATABASE`, `DBT_EXCLUDE_FLAG` | the dbt profile (`--profile`, default the project's in `.datasecops.yml`); `SOURCE_DATABASE` uses the production branch |
194
+ | `TARGET_DATABASE` | `--mode`: `release` `<prefix><TARGET>` (default), `ci` `<prefix>UT_<--run-id>`, `clone` `<prefix><--clone-database>`, `default` the production database |
195
+ | `DBT_DOCS_REPO`, `DBT_DOCS_REPO_FOLDER`, `GIT_TAG_EMAIL`, `GIT_TAG_NAME` | Settings › Deployment |
196
+ | `S3_MANIFEST_BUCKET`, `AWS_REGION` / `AZURE_STORAGE_ACCOUNT`, `AZURE_STORAGE_CONTAINER`, `AZURE_CLIENT_ID`, `AZURE_TENANT_ID` | the manifest storage provider's settings |
197
+ | `DBT_VERSION` | the active version of the project's dbt engine, dbt 2.0 or dbt Core (without the `v`) |
198
+
199
+ No secrets are returned. Older apps only give the dbt target (a note is printed).
200
+
188
201
  Pass the branch through the runner's environment variable, not a `${{ ... }}` / `$(...)` expression:
189
202
  those are substituted into the script before the shell runs, so a branch name containing `$(...)`
190
203
  would execute.
@@ -162,9 +162,22 @@ the branch, so pipelines don't hard-code them:
162
162
  ```bash
163
163
  datasecops pipeline env --branch "$GITHUB_REF_NAME" # GitHub Actions: target whose Branch is this branch
164
164
  datasecops pipeline env --branch "$BUILD_SOURCEBRANCH" # Azure DevOps (the full ref, not BUILD_SOURCEBRANCHNAME)
165
- datasecops pipeline env --target unit-test # a named target
165
+ datasecops pipeline env --target unit-test --mode ci --run-id "$GITHUB_RUN_ID" # a unit-test run
166
166
  ```
167
167
 
168
+ With an app that has `api.pipeline_context`, the command also sets the run's other values from the
169
+ app's settings, so changing them in the app applies on the next run without regenerating the pipelines:
170
+
171
+ | Variable | From |
172
+ |---|---|
173
+ | `DBT_PROJECT_NAME`, `DATABASE_PREFIX`, `SOURCE_DATABASE`, `DBT_EXCLUDE_FLAG` | the dbt profile (`--profile`, default the project's in `.datasecops.yml`); `SOURCE_DATABASE` uses the production branch |
174
+ | `TARGET_DATABASE` | `--mode`: `release` `<prefix><TARGET>` (default), `ci` `<prefix>UT_<--run-id>`, `clone` `<prefix><--clone-database>`, `default` the production database |
175
+ | `DBT_DOCS_REPO`, `DBT_DOCS_REPO_FOLDER`, `GIT_TAG_EMAIL`, `GIT_TAG_NAME` | Settings › Deployment |
176
+ | `S3_MANIFEST_BUCKET`, `AWS_REGION` / `AZURE_STORAGE_ACCOUNT`, `AZURE_STORAGE_CONTAINER`, `AZURE_CLIENT_ID`, `AZURE_TENANT_ID` | the manifest storage provider's settings |
177
+ | `DBT_VERSION` | the active version of the project's dbt engine, dbt 2.0 or dbt Core (without the `v`) |
178
+
179
+ No secrets are returned. Older apps only give the dbt target (a note is printed).
180
+
168
181
  Pass the branch through the runner's environment variable, not a `${{ ... }}` / `$(...)` expression:
169
182
  those are substituted into the script before the shell runs, so a branch name containing `$(...)`
170
183
  would execute.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "datasecops-cli"
7
- version = "0.7.0b10"
7
+ version = "0.7.0b11"
8
8
  description = "DataSecOps Framework CLI for Snowflake Native App"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1 @@
1
+ __version__ = "0.7.0b11"
@@ -254,40 +254,72 @@ def pipeline():
254
254
  help="Branch being built: picks the dbt target mapped to it (a GitHub pull request's "
255
255
  "<n>/merge ref resolves to its source branch)")
256
256
  @click.option("--target", "-t", default=None, help="dbt target name (instead of --branch)")
257
+ @click.option("--mode", "-m", type=click.Choice(pipeline_env.MODES), default="release", show_default=True,
258
+ help="The database the run writes to: release <prefix><TARGET>, ci <prefix>UT_<run id>, "
259
+ "clone <prefix><clone database>, default the production database")
260
+ @click.option("--run-id", default=None, help="ci mode: the run's id (the unit-test database suffix)")
261
+ @click.option("--clone-database", default=None, help="clone mode: the database to clone into (without the prefix)")
262
+ @click.option("--profile", default=None, help="dbt profile (default: the project's, from .datasecops.yml)")
257
263
  @click.option("--connection", "-c", default=None, help="Snowflake connection name (overrides .datasecops.yml)")
258
264
  @click.option("--format", "fmt", type=click.Choice(["auto", *pipeline_env.PLATFORMS]), default="auto",
259
265
  show_default=True, help="auto: GitHub when $GITHUB_ENV is set, Azure DevOps when $TF_BUILD is set")
260
- def pipeline_env_cmd(branch: Optional[str], target: Optional[str], connection: Optional[str], fmt: str):
261
- """Set TARGET, SF_ROLE, SF_WAREHOUSE and TARGET_SCHEMA from the app's dbt Targets.
266
+ def pipeline_env_cmd(branch: Optional[str], target: Optional[str], mode: str, run_id: Optional[str],
267
+ clone_database: Optional[str], profile: Optional[str], connection: Optional[str], fmt: str):
268
+ """Set a pipeline run's variables from the app's settings.
269
+
270
+ The dbt target (TARGET, SF_ROLE, SF_WAREHOUSE, TARGET_SCHEMA) and, from apps with api.pipeline_context, the
271
+ profile's databases (DATABASE_PREFIX, SOURCE_DATABASE, TARGET_DATABASE for --mode), DBT_PROJECT_NAME,
272
+ DBT_EXCLUDE_FLAG, the docs repository, git tag identity, manifest storage and DBT_VERSION. Settings changed
273
+ in the app apply on the next run.
262
274
 
263
275
  GitHub Actions: appended to $GITHUB_ENV. Azure DevOps: set with ##vso logging commands.
264
276
  Otherwise printed as KEY=value. Empty role / warehouse / schema values are left unset.
265
277
  """
266
278
  if bool(branch) == bool(target):
267
279
  raise click.UsageError("give exactly one of --branch or --target")
280
+ if mode == "ci" and not run_id:
281
+ raise click.UsageError("--mode ci needs --run-id")
282
+ if mode == "clone" and not clone_database:
283
+ raise click.UsageError("--mode clone needs --clone-database")
268
284
  config = Config()
269
285
  if not config.load(connection_name=connection):
270
286
  sys.exit(1)
271
287
  sf_service = SnowflakeService(config.datasecops)
272
288
  try:
273
- raw = sf_service.get_framework_config("PROJECT") or {}
274
- except Exception as e: # noqa: BLE001 - connector errors
275
- error_line(f"Failed to read the dbt targets from {config.datasecops.app_database}: {e}")
276
- sys.exit(1)
289
+ try:
290
+ raw = sf_service.get_framework_config("PROJECT") or {}
291
+ except Exception as e: # noqa: BLE001 - connector errors
292
+ error_line(f"Failed to read the dbt targets from {config.datasecops.app_database}: {e}")
293
+ sys.exit(1)
294
+ targets = [DbtTarget(**{k: v for k, v in t.items() if k in DbtTarget.model_fields})
295
+ for t in raw.get("targets") or []]
296
+ try:
297
+ resolved = pipeline_env.resolve_target(targets, branch=branch, target=target)
298
+ except pipeline_env.TargetNotFound as e:
299
+ error_line(str(e))
300
+ sys.exit(1)
301
+ values = pipeline_env.env_values(resolved)
302
+ params = {"profile": profile or config.profile_name, "target": resolved.target_name, "mode": mode,
303
+ "run_id": run_id or "", "clone_database": clone_database or ""}
304
+ try:
305
+ context, note = pipeline_env.app_context(sf_service, params)
306
+ except pipeline_env.PipelineContextError as e:
307
+ error_line(str(e))
308
+ sys.exit(1)
309
+ if note:
310
+ click.echo(f"Note: {config.datasecops.app_database}: {note}", err=True)
311
+ values = {**values, **context}
277
312
  finally:
278
313
  sf_service.close()
279
- targets = [DbtTarget(**{k: v for k, v in t.items() if k in DbtTarget.model_fields})
280
- for t in raw.get("targets") or []]
314
+ platform = pipeline_env.detect_platform() if fmt == "auto" else fmt
281
315
  try:
282
- resolved = pipeline_env.resolve_target(targets, branch=branch, target=target)
283
- except pipeline_env.TargetNotFound as e:
284
- error_line(str(e))
316
+ lines = pipeline_env.export(values, platform)
317
+ except ValueError as e:
318
+ error_line(f"Pipeline context: {e}")
285
319
  sys.exit(1)
286
- values = pipeline_env.env_values(resolved)
287
- platform = pipeline_env.detect_platform() if fmt == "auto" else fmt
288
- for line in pipeline_env.export(values, platform):
320
+ for line in lines:
289
321
  click.echo(line)
290
- click.echo("dbt environment: " + ", ".join(f"{k}={v}" for k, v in values.items()), err=True)
322
+ click.echo("pipeline environment: " + ", ".join(f"{k}={v}" for k, v in values.items()), err=True)
291
323
 
292
324
 
293
325
  # ── model commands ─────────────────────────────────────────────────────────
@@ -14,12 +14,52 @@ from typing import Optional
14
14
  from datasecops_cli.models.project_config import DbtTarget
15
15
 
16
16
  PLATFORMS = ("github", "azure", "shell")
17
+ # The database a run writes to (api.pipeline_context resolves TARGET_DATABASE for it).
18
+ MODES = ("release", "ci", "clone", "default")
19
+
20
+
21
+ # Names `export` writes: plain upper-case variable names only (they are pasted into $GITHUB_ENV lines, ##vso
22
+ # commands and shell output).
23
+ _NAME = re.compile(r"^[A-Z_][A-Z0-9_]*$")
17
24
 
18
25
 
19
26
  class TargetNotFound(ValueError):
20
27
  pass
21
28
 
22
29
 
30
+ class PipelineContextError(RuntimeError):
31
+ """The app's pipeline context couldn't be read (other than an app without the procedure)."""
32
+
33
+
34
+ def _procedure_missing(error: Exception) -> bool:
35
+ """An app older than api.pipeline_context: the compilation error for an unknown procedure, naming it
36
+ ("Unknown user-defined function ...API.PIPELINE_CONTEXT", or does not exist / not authorized)."""
37
+ text = str(error)
38
+ if "PIPELINE_CONTEXT" not in text.upper():
39
+ return False
40
+ return (getattr(error, "errno", None) in (2140, 2003)
41
+ or "unknown user-defined function" in text.lower() or "does not exist" in text.lower())
42
+
43
+
44
+ def app_context(sf_service, params: dict) -> tuple[dict[str, str], Optional[str]]:
45
+ """The run's values from the app's api.pipeline_context, and a note when the app is too old to have it (then
46
+ only the dbt target is set). Any other failure raises PipelineContextError: a run must not continue with part
47
+ of its context (e.g. a stale TARGET_DATABASE)."""
48
+ try:
49
+ context = sf_service.get_pipeline_context(params)
50
+ except Exception as e: # noqa: BLE001 - connector errors
51
+ if _procedure_missing(e):
52
+ return {}, "the app has no pipeline context (api.pipeline_context); only the dbt target is set. Upgrade the app."
53
+ raise PipelineContextError(f"Pipeline context: {e}") from e
54
+ if not isinstance(context, dict) or not context.get("ok"):
55
+ error = context.get("error") if isinstance(context, dict) else None
56
+ raise PipelineContextError(f"Pipeline context: {error or 'no result'}")
57
+ values = context.get("values") or {}
58
+ if not isinstance(values, dict):
59
+ raise PipelineContextError("Pipeline context: unexpected result")
60
+ return {str(k): "" if v is None else str(v) for k, v in values.items()}, None
61
+
62
+
23
63
  def _pick(entries: list[DbtTarget], key, value: str) -> Optional[DbtTarget]:
24
64
  """An exact match first; a case-insensitive one only when it is unambiguous."""
25
65
  exact = [t for t in entries if key(t) and key(t) == value]
@@ -81,6 +121,8 @@ def export(values: dict[str, str], platform: str) -> list[str]:
81
121
  """Write the values for the platform: GitHub appends them to $GITHUB_ENV, Azure DevOps sets
82
122
  them with logging commands, otherwise shell-quoted KEY=value lines. Returns the lines to print."""
83
123
  for k, v in values.items():
124
+ if not _NAME.fullmatch(k):
125
+ raise ValueError(f"invalid variable name {k!r}")
84
126
  if "\n" in v or "\r" in v:
85
127
  raise ValueError(f"{k} contains a newline")
86
128
  if platform == "github":
@@ -13,7 +13,7 @@ ALLOWED_PROCEDURES = frozenset({
13
13
  "get_model_definitions", "get_object_definitions", "get_source_definitions", "get_access_groups",
14
14
  "get_support_contacts", "get_sqlfluff_config_file", "get_documentation",
15
15
  "get_dcm_config", "get_dcm_projects", "update_dcm_deployment",
16
- "get_dcm_model", "set_dcm_model", "sync_deployed_model",
16
+ "get_dcm_model", "set_dcm_model", "sync_deployed_model", "pipeline_context",
17
17
  })
18
18
 
19
19
 
@@ -111,6 +111,10 @@ class SnowflakeService:
111
111
  def get_pipelines_for_profile(self, profile_name: str) -> Optional[dict]:
112
112
  return self.call_procedure("get_pipelines_for_profile", profile_name)
113
113
 
114
+ def get_pipeline_context(self, params: dict) -> Optional[dict]:
115
+ """A pipeline run's variables from the app (api.pipeline_context): {"ok", "values" | "error"}."""
116
+ return self.call_procedure("pipeline_context", json.dumps(params))
117
+
114
118
  def get_account_info(self) -> dict:
115
119
  rows = self.execute_query("SELECT CURRENT_ACCOUNT_NAME() as account, CURRENT_USER() as user_name")
116
120
  return rows[0] if rows else {}
@@ -2,11 +2,12 @@
2
2
 
3
3
  Ported from the security project's role_dot.py / gen_role_diagram.py. Every box and
4
4
  role sits at an exact grid position (diagram_groups row/col) with right-angled edges.
5
- Four views:
5
+ Four views (shown as Full, Snowflake, Entra and Entra -> Snowflake):
6
6
  grid full hierarchy
7
7
  snowflake-only without SCIM / Entra (UGE) roles
8
- entra-links Entra groups and their direct links to Snowflake roles
9
- entra-ace-map Entra groups -> ACE (SCIM) roles only
8
+ entra-ace-map Entra: functional groups -> security groups (SCIM roles) only
9
+ entra-links Entra -> Snowflake: Entra groups and their direct links to Snowflake roles
10
+ Security group (SCIM) roles are labelled by their name without the security prefix.
10
11
  """
11
12
  from __future__ import annotations
12
13
 
@@ -46,7 +47,7 @@ def label(graph: RoleGraph, n: str) -> str:
46
47
  short = n[len(s.scim_security_prefix):]
47
48
  for strip in s.scim_label_strip:
48
49
  short = short.replace(strip, "")
49
- return "ACE: " + short
50
+ return short
50
51
  if graph.kind(n) == "uge":
51
52
  short = n[len(s.scim_functional_prefix):] if n.startswith(s.scim_functional_prefix) else n.split("-", 1)[-1]
52
53
  return "\\n".join(textwrap.wrap(short.title().replace("(Admin Accounts)", "(Admin)"), 22))
@@ -301,7 +302,7 @@ def render_view(security: SecurityModel, view: str = "grid") -> str:
301
302
  if view == "entra-ace-map":
302
303
  ace_edges = [(p, c) for p, c in link_edges if (is_uge(p) or is_uge(c)) and (is_scim(p) or is_scim(c))]
303
304
  ace_nodes = sorted({n for e in ace_edges for n in e})
304
- ace_box = "Snowflake ACE roles (SCIM)"
305
+ ace_box = "Entra ID security groups (SCIM)"
305
306
  force = {n: ace_box for n in ace_nodes if is_scim(n)}
306
307
  force.update({n: full_box[n] for n in ace_nodes if is_uge(n)})
307
308
  ml = {ace_box: {"row": 1, "col": 0}}
@@ -310,7 +311,7 @@ def render_view(security: SecurityModel, view: str = "grid") -> str:
310
311
  ml.setdefault(full_box[n], {"row": 0, "col": len([b for b in ml if b != ace_box])})
311
312
  return build_svg(graph, ace_edges, ace_nodes, ml, role_group, force_box=force)
312
313
 
313
- # entra-links: each ACE role is drawn inside the box of the Snowflake role it links to
314
+ # entra-links: each security group (SCIM) role is drawn inside the box of the Snowflake role it links to
314
315
  env_re = re.compile(r"_(" + "|".join(map(re.escape, s.environment_suffixes)) + r")$") if s.environment_suffixes else None
315
316
 
316
317
  def env_box(sf):
@@ -385,9 +386,10 @@ def role_hierarchy_markdown(security: SecurityModel, image_dir: str = "images")
385
386
  ]
386
387
  md += [f"- {k}: {v}" for k, v in LEGEND.items()]
387
388
  md += ["- Dashed arrows: Snowflake default system hierarchy", ""]
388
- titles = {"snowflake-only": "Snowflake roles only", "entra-links": "Entra ID groups and their Snowflake roles",
389
- "entra-ace-map": "Entra ID groups to ACE roles", "grid": "Full hierarchy"}
390
- for v in ("snowflake-only", "entra-links", "entra-ace-map", "grid"):
389
+ titles = {"grid": "Full hierarchy", "snowflake-only": "Snowflake roles only",
390
+ "entra-ace-map": "Entra ID functional and security groups",
391
+ "entra-links": "Entra ID groups and their Snowflake roles"}
392
+ for v in ("grid", "snowflake-only", "entra-ace-map", "entra-links"):
391
393
  md += [f"## {titles[v]}", "", f"![{titles[v]}]({image_dir}/role-hierarchy-{v}.svg)", ""]
392
394
  md += ["## Account-level privileges", "", "| Role | Privileges |", "|---|---|"]
393
395
  md += [f"| `{r}` | {', '.join(p)} |" for r, p in sorted(graph.privs.items())]
@@ -165,8 +165,8 @@ class TestRender:
165
165
  m = sample_model()
166
166
  sec = write_project(tmp_path, "security", ["role.sql", "role_guard.sql"])
167
167
  plat = write_project(tmp_path, "platform", ["warehouse.sql"])
168
- (sec / "sources/definitions/roles.sql").write_text(render.render_roles_sql(m.security))
169
- (plat / "sources/definitions/warehouses.sql").write_text(render.render_warehouses_sql(m.warehouses))
168
+ (sec / "sources/definitions/roles.sql").write_text(render.render_roles_sql(m.security), encoding="utf-8")
169
+ (plat / "sources/definitions/warehouses.sql").write_text(render.render_warehouses_sql(m.warehouses), encoding="utf-8")
170
170
  back_sec, back_wh = convert.import_security(sec), convert.import_warehouses(plat)
171
171
  assert render.render_roles_sql(back_sec) == render.render_roles_sql(m.security)
172
172
  assert render.render_warehouses_sql(back_wh) == render.render_warehouses_sql(m.warehouses)
@@ -323,7 +323,8 @@ class TestDiagram:
323
323
 
324
324
  def test_grid_contains_every_role_and_colours(self):
325
325
  svg = diagram.render_view(sample_model().security, "grid")
326
- assert 'data-role="READERS_PRD"' in svg and "ACE: READERS_TST" in svg
326
+ assert 'data-role="READERS_PRD"' in svg and ">READERS_TST<" in svg
327
+ assert "ACE" not in svg.replace("ACE-", "") # no "ACE" wording, only in role names
327
328
  assert diagram.COLORS["sys"][0] in svg and diagram.COLORS["mine"][0] in svg
328
329
 
329
330
  def test_layout_errors(self):
@@ -46,6 +46,13 @@ class TestCliParsing:
46
46
  args, kwargs = mock_run.call_args
47
47
  assert args[1] == ["sqlfluff", "packages", "macros"]
48
48
 
49
+ def test_download_profile_short_option(self):
50
+ runner = self._runner()
51
+ with patch("datasecops_cli.main._run_download") as mock_run:
52
+ result = runner.invoke(cli, ["download", "sqlfluff", "-p", "core"])
53
+ assert result.exit_code == 0, result.output
54
+ assert mock_run.call_args.kwargs["profile"] == "core"
55
+
49
56
  def test_download_all(self):
50
57
  runner = self._runner()
51
58
  with patch("datasecops_cli.main._run_download") as mock_run:
@@ -517,13 +524,18 @@ class TestPipelineEnvCommand:
517
524
  target_schema="CORE"),
518
525
  ]
519
526
 
520
- def _invoke(self, args, project=None):
527
+ def _invoke(self, args, project=None, context=None):
521
528
  sf = MagicMock()
529
+ if isinstance(context, Exception):
530
+ sf.get_pipeline_context.side_effect = context
531
+ else:
532
+ sf.get_pipeline_context.return_value = context if context is not None else {"ok": True, "values": {}}
522
533
  sf.get_framework_config.return_value = project if project is not None else {
523
534
  "targets": [t.model_dump() for t in self.TARGETS]}
524
535
  with patch("datasecops_cli.main.Config") as config_cls, \
525
536
  patch("datasecops_cli.main.SnowflakeService", return_value=sf):
526
537
  config_cls.return_value.load.return_value = True
538
+ config_cls.return_value.profile_name = "core"
527
539
  self.config = config_cls.return_value
528
540
  result = CliRunner().invoke(cli, ["pipeline", "env", *args])
529
541
  return result, sf
@@ -535,6 +547,54 @@ class TestPipelineEnvCommand:
535
547
  sf.get_framework_config.assert_called_once_with("PROJECT")
536
548
  sf.close.assert_called_once()
537
549
 
550
+ def test_exports_the_apps_pipeline_context(self):
551
+ context = {"ok": True, "values": {"TARGET_DATABASE": "CORE_UT_42", "DBT_VERSION": "2.0.9"}}
552
+ result, sf = self._invoke(["--target", "unit-test", "--mode", "ci", "--run-id", "42", "--format", "shell"],
553
+ context=context)
554
+ assert result.exit_code == 0, result.output
555
+ assert "TARGET=unit-test\n" in result.output and "TARGET_DATABASE=CORE_UT_42\nDBT_VERSION=2.0.9\n" in result.output
556
+ sf.get_pipeline_context.assert_called_once_with(
557
+ {"profile": "core", "target": "unit-test", "mode": "ci", "run_id": "42", "clone_database": ""})
558
+
559
+ def test_profile_option_overrides_the_projects(self):
560
+ result, sf = self._invoke(["--branch", "main", "--profile", "other", "--format", "shell"],
561
+ context={"ok": True, "values": {}})
562
+ assert result.exit_code == 0, result.output
563
+ assert sf.get_pipeline_context.call_args[0][0]["profile"] == "other"
564
+ assert sf.get_pipeline_context.call_args[0][0]["target"] == "prd"
565
+
566
+ def test_an_app_without_the_procedure_sets_only_the_target(self):
567
+ from snowflake.connector.errors import ProgrammingError
568
+ missing = ProgrammingError("SQL compilation error:\nUnknown user-defined function MONITORIAL_ORBIT.API.PIPELINE_CONTEXT.",
569
+ errno=2140)
570
+ result, _ = self._invoke(["--branch", "main", "--format", "shell"], context=missing)
571
+ assert result.exit_code == 0, result.output
572
+ assert "TARGET=prd\n" in result.output and "Upgrade the app" in result.output
573
+
574
+ def test_other_procedure_failures_fail_the_run(self):
575
+ result, _ = self._invoke(["--target", "unit-test", "--mode", "ci", "--run-id", "1", "--format", "shell"],
576
+ context=Exception("connection timed out"))
577
+ assert result.exit_code == 1 and "connection timed out" in result.output
578
+ assert "TARGET=" not in result.output
579
+
580
+ def test_invalid_variable_names_from_the_app_are_rejected(self):
581
+ result, _ = self._invoke(["--branch", "main", "--format", "shell"],
582
+ context={"ok": True, "values": {"X\nEVIL": "1"}})
583
+ assert result.exit_code == 1 and "invalid variable name" in result.output
584
+
585
+ def test_variable_names_with_a_trailing_newline_are_rejected(self):
586
+ result, _ = self._invoke(["--branch", "main", "--format", "shell"],
587
+ context={"ok": True, "values": {"X\n": "1"}})
588
+ assert result.exit_code == 1 and "invalid variable name" in result.output
589
+
590
+ def test_a_context_error_fails_the_run(self):
591
+ result, _ = self._invoke(["--branch", "main", "--format", "shell"], context={"ok": False, "error": "no dbt profile"})
592
+ assert result.exit_code == 1 and "no dbt profile" in result.output
593
+
594
+ def test_ci_and_clone_modes_need_their_value(self):
595
+ assert self._invoke(["--target", "prd", "--mode", "ci"])[0].exit_code == 2
596
+ assert self._invoke(["--target", "prd", "--mode", "clone"])[0].exit_code == 2
597
+
538
598
  def test_unknown_branch_fails(self):
539
599
  result, _ = self._invoke(["--branch", "feature/x", "--format", "shell"])
540
600
  assert result.exit_code == 1
@@ -1 +0,0 @@
1
- __version__ = "0.7.0b10"