datasecops-cli 0.7.0b12__tar.gz → 0.7.0b13__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.
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/CHANGELOG.md +4 -1
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/PKG-INFO +11 -1
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/README.md +10 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/pyproject.toml +1 -1
- datasecops_cli-0.7.0b13/src/datasecops_cli/__init__.py +1 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/models/project_config.py +1 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dbt_project_generator.py +23 -12
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/download_service.py +90 -17
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/upstream_service.py +5 -1
- datasecops_cli-0.7.0b13/tests/test_download_service.py +236 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_main.py +25 -14
- datasecops_cli-0.7.0b13/tests/test_upstream_service.py +59 -0
- datasecops_cli-0.7.0b12/src/datasecops_cli/__init__.py +0 -1
- datasecops_cli-0.7.0b12/tests/test_download_service.py +0 -81
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/.github/workflows/auto-tag.yml +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/.github/workflows/publish-cli.yml +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/.github/workflows/test.yml +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/.gitignore +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/AGENTS.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/DEVELOPMENT.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/LICENSE +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/docs/dcm.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/docs/getting-started.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/docs/git-operations.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/docs/legacy.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/docs/legacy_plan_of_action.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/docs/mcp-server.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/docs/squash-merge-into-test-review.md +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/mcp-servers.json +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/scripts/vendor_model.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/setup.ps1 +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/setup.sh +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/config.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/main.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/__init__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/configuration.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/dcm_operations.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/development.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/downloads.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/git_operations.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/models/__init__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/models/git_helpers.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/__init__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/bootstrap_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dbt_runner.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_orchestrator.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_pipelines.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_registry.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/directory_scaffolder.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/git_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/linting_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/model_commands.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/pipeline_env.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/skill_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/snowflake_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/__init__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/display.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/file_utils.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/mcp.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/yaml_utils.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_mcp/__init__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_mcp/__main__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_mcp/connection.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_mcp/server.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/__init__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/convert.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/diagram.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/expand.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/extract.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/render.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/schema.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/scope.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/scripts.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/starter.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/templates/macros/role.sql +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/templates/macros/role_guard.sql +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/templates/macros/warehouse.sql +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/validate.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/__init__.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_config.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_dbt_project_generator_profiles.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_dbt_runner.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_dcm_model.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_dcm_orchestrator.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_dcm_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_file_utils.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_git_operations_menu.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_git_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_linting_service.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_mcp_branching_rules.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_mcp_lint_tools.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_model_commands.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_models.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_pipeline_env.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_version.py +0 -0
- {datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_yaml_utils.py +0 -0
|
@@ -4,9 +4,12 @@ All notable changes to the DataSecOps CLI are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.7.0b13] - 2026-11-02
|
|
8
|
+
|
|
7
9
|
### Fixed
|
|
8
10
|
|
|
9
|
-
- **`download packages` ignored
|
|
11
|
+
- **`download packages` ignored a downstream project's package selection** — `download_dbt_packages()`'s filtering was nested inside `if profile.dbt_packages:`, so a downstream project with no packages selected of its own (relying entirely on an upstream project) skipped filtering altogether and got the full, unfiltered package list. The initial fix defaulted an empty selection to "everything the framework offers, minus upstream's" — still wrong, since a project that selected zero packages should get zero framework packages, not everything else. It now distinguishes three cases: an explicit selection (those packages, minus upstream's), no selection with an upstream project (none — only the upstream added as a dependency, see below), and no selection with no upstream project (everything, unchanged). Same fix applied to the unused `generate_packages_yml()`.
|
|
12
|
+
- **Upstream project dependencies now resolve as a real git package, not `local_packages/<name>`** — `local_packages/<name>` assumed the upstream project was checked out as a sibling directory, which isn't how these projects are actually laid out. Upstream dependencies are now added as `{git: <upstream git_url>, subdirectory: <upstream's project_dir>, revision: <latest tag>}`, with the latest tag resolved via `git ls-remote` against the upstream's `git_url` (same lookup `upstream_service.get_latest_tag()` already used for update checks). Azure DevOps URLs (exact `dev.azure.com` host, parsed rather than substring-matched) get a `DBT_ENV_SECRET_DEVOPS_PAT` `env_var()` Jinja placeholder inserted for dbt to authenticate with at parse time; the `git ls-remote` lookup itself authenticates with that env var's actual value (Jinja isn't resolved by plain git). An upstream project with no `git_url` configured is skipped with a warning rather than producing a broken package entry. `ProjectProfile` gains `project_dir` (default `"dbt"`, matching prior behavior) so a project whose dbt project isn't under `dbt/` resolves correctly. `upstream_service._urls_match()` now strips URL userinfo (the PAT/Jinja placeholder) before comparing, so the upstream-version checker still recognizes a generated entry as pinned. PR review follow-ups: an upstream profile with an empty selection and no upstream of its own now correctly contributes "every catalog package" (not just its empty explicit list) when computing what a downstream profile should exclude.
|
|
10
13
|
- **Configurable branch names (PR review follow-ups):**
|
|
11
14
|
- Legacy `main`/`test`/`prod` branches could leak through as selectable deploy/reset targets when a project configured different trunk/integration/production names but its `deployment_branches`/`environments` still carried the old literal names. `_deploy()` and `_reset_branch_from_main()` now always exclude the legacy defaults in addition to the configured names.
|
|
12
15
|
- A blank or `null` `trunk_branch`/`integration_branch`/`production_branch` in the native app's `SOURCE_CONTROL` config previously produced invalid branch refs (e.g. `origin/`) or aborted config loading entirely; `SourceControl` now falls back to the documented default for any blank/null value.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datasecops-cli
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.0b13
|
|
4
4
|
Summary: DataSecOps Framework CLI for Snowflake Native App
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -137,6 +137,16 @@ none is marked active (matching how the app itself resolves a version to install
|
|
|
137
137
|
|
|
138
138
|
Available items: `sqlfluff`, `pipelines`, `packages`, `macros`, `scripts`, `install-sqlfluff`, `install-dbt`, `all`
|
|
139
139
|
|
|
140
|
+
`datasecops download packages` resolves `packages.yml` from the native app's `DBT_PACKAGES`
|
|
141
|
+
catalog and the active profile:
|
|
142
|
+
- An explicit `dbt_packages` selection gets just those packages (minus anything an upstream
|
|
143
|
+
project already provides).
|
|
144
|
+
- No selection, but an `upstream_projects` entry: none of the framework catalog directly — only
|
|
145
|
+
the upstream project(s), added as `{git: <upstream git_url>, subdirectory: dbt, revision:
|
|
146
|
+
<latest tag>}`. Azure DevOps upstream URLs get a `DBT_ENV_SECRET_DEVOPS_PAT` `env_var()` Jinja
|
|
147
|
+
placeholder inserted for dbt to authenticate with.
|
|
148
|
+
- No selection and no upstream project: every package in the catalog.
|
|
149
|
+
|
|
140
150
|
The pipeline platform (GitHub / Azure DevOps) is auto-detected from the native app's source control configuration.
|
|
141
151
|
|
|
142
152
|
### Pipeline Setup
|
|
@@ -117,6 +117,16 @@ none is marked active (matching how the app itself resolves a version to install
|
|
|
117
117
|
|
|
118
118
|
Available items: `sqlfluff`, `pipelines`, `packages`, `macros`, `scripts`, `install-sqlfluff`, `install-dbt`, `all`
|
|
119
119
|
|
|
120
|
+
`datasecops download packages` resolves `packages.yml` from the native app's `DBT_PACKAGES`
|
|
121
|
+
catalog and the active profile:
|
|
122
|
+
- An explicit `dbt_packages` selection gets just those packages (minus anything an upstream
|
|
123
|
+
project already provides).
|
|
124
|
+
- No selection, but an `upstream_projects` entry: none of the framework catalog directly — only
|
|
125
|
+
the upstream project(s), added as `{git: <upstream git_url>, subdirectory: dbt, revision:
|
|
126
|
+
<latest tag>}`. Azure DevOps upstream URLs get a `DBT_ENV_SECRET_DEVOPS_PAT` `env_var()` Jinja
|
|
127
|
+
placeholder inserted for dbt to authenticate with.
|
|
128
|
+
- No selection and no upstream project: every package in the catalog.
|
|
129
|
+
|
|
120
130
|
The pipeline platform (GitHub / Azure DevOps) is auto-detected from the native app's source control configuration.
|
|
121
131
|
|
|
122
132
|
### Pipeline Setup
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.7.0b13"
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/models/project_config.py
RENAMED
|
@@ -115,6 +115,7 @@ class ProjectProfile(BaseModel):
|
|
|
115
115
|
downstream_projects: list[str] = Field(default_factory=list)
|
|
116
116
|
upstream_projects: list[str] = Field(default_factory=list)
|
|
117
117
|
git_url: str = ""
|
|
118
|
+
project_dir: str = "dbt" # path to the dbt project within git_url's repo
|
|
118
119
|
target_database: str = ""
|
|
119
120
|
dbt_version: str = "1.9"
|
|
120
121
|
dbt_packages: list[str] = Field(default_factory=list)
|
|
@@ -478,21 +478,20 @@ def generate_packages_yml(
|
|
|
478
478
|
packages = packages_config.get("packages", [])
|
|
479
479
|
|
|
480
480
|
# Filter to only packages enabled on the profile
|
|
481
|
-
from datasecops_cli.services.download_service import
|
|
481
|
+
from datasecops_cli.services.download_service import (
|
|
482
|
+
_collect_upstream_packages, _devops_pat_authenticated, _devops_pat_placeholder,
|
|
483
|
+
_effective_packages,
|
|
484
|
+
)
|
|
485
|
+
from datasecops_cli.services.upstream_service import get_latest_tag
|
|
482
486
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
enabled = set(profile.dbt_packages) if profile.dbt_packages else {
|
|
486
|
-
p.get("name") for p in packages
|
|
487
|
-
}
|
|
487
|
+
all_package_names = {p.get("name") for p in packages}
|
|
488
|
+
enabled = _effective_packages(profile, all_package_names)
|
|
488
489
|
|
|
489
|
-
# Exclude packages already provided by upstream projects
|
|
490
|
-
# even when the profile has no explicit dbt_packages of its own, since it
|
|
491
|
-
# may rely entirely on an upstream project.
|
|
490
|
+
# Exclude packages already provided by upstream projects
|
|
492
491
|
if profile.upstream_projects and all_profiles:
|
|
493
492
|
profile_map = {p.profile_name: p for p in all_profiles}
|
|
494
493
|
upstream_pkgs = _collect_upstream_packages(
|
|
495
|
-
profile.upstream_projects, profile_map
|
|
494
|
+
profile.upstream_projects, profile_map, all_package_names
|
|
496
495
|
)
|
|
497
496
|
enabled -= upstream_pkgs
|
|
498
497
|
|
|
@@ -515,9 +514,21 @@ def generate_packages_yml(
|
|
|
515
514
|
entry["version"] = version
|
|
516
515
|
pkg_list.append(entry)
|
|
517
516
|
|
|
518
|
-
# Add upstream project dependencies as
|
|
517
|
+
# Add upstream project dependencies as git packages pinned to their latest tag
|
|
518
|
+
upstream_profile_map = {p.profile_name: p for p in (all_profiles or [])}
|
|
519
519
|
for upstream_name in profile.upstream_projects:
|
|
520
|
-
|
|
520
|
+
upstream_profile = upstream_profile_map.get(upstream_name)
|
|
521
|
+
git_url = upstream_profile.git_url if upstream_profile else ""
|
|
522
|
+
if not git_url:
|
|
523
|
+
continue
|
|
524
|
+
latest_tag = get_latest_tag(_devops_pat_authenticated(git_url))
|
|
525
|
+
entry = {
|
|
526
|
+
"git": _devops_pat_placeholder(git_url),
|
|
527
|
+
"subdirectory": upstream_profile.project_dir,
|
|
528
|
+
}
|
|
529
|
+
if latest_tag:
|
|
530
|
+
entry["revision"] = latest_tag
|
|
531
|
+
pkg_list.append(entry)
|
|
521
532
|
|
|
522
533
|
return yaml.dump({"packages": pkg_list}, default_flow_style=False, sort_keys=False)
|
|
523
534
|
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/download_service.py
RENAMED
|
@@ -1,21 +1,86 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import os
|
|
2
3
|
import subprocess
|
|
3
4
|
import yaml
|
|
4
5
|
from pathlib import Path
|
|
5
6
|
from typing import Optional
|
|
7
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
6
8
|
|
|
7
9
|
from datasecops_cli.models.project_config import ProjectProfile, ProjectSettings
|
|
8
10
|
from datasecops_cli.services.snowflake_service import SnowflakeService
|
|
9
|
-
from datasecops_cli.
|
|
11
|
+
from datasecops_cli.services.upstream_service import get_latest_tag
|
|
12
|
+
from datasecops_cli.utilities.display import info_line, success_line, error_line, warning_line
|
|
10
13
|
from datasecops_cli.utilities.file_utils import write_file, ensure_dir
|
|
11
14
|
|
|
15
|
+
# Env var dbt resolves (via `env_var()` in packages.yml) to authenticate Azure DevOps
|
|
16
|
+
# git package URLs. Projects set this once per environment to a PAT with read access
|
|
17
|
+
# to the org's repos.
|
|
18
|
+
DEVOPS_PAT_ENV_VAR = "DBT_ENV_SECRET_DEVOPS_PAT"
|
|
19
|
+
AZURE_DEVOPS_HOST = "dev.azure.com"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _is_azure_devops_url(url: str) -> bool:
|
|
23
|
+
"""True only for an exact `dev.azure.com` HTTPS host — not a substring match, which
|
|
24
|
+
would also match an attacker-controlled host like `dev.azure.com.evil.example`."""
|
|
25
|
+
try:
|
|
26
|
+
parsed = urlsplit(url)
|
|
27
|
+
except ValueError:
|
|
28
|
+
return False
|
|
29
|
+
return parsed.scheme == "https" and (parsed.hostname or "") == AZURE_DEVOPS_HOST
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _with_userinfo(url: str, userinfo: str) -> str:
|
|
33
|
+
"""Rebuild `url` with `userinfo@` inserted before the host, preserving any port."""
|
|
34
|
+
parsed = urlsplit(url)
|
|
35
|
+
netloc = f"{userinfo}@{parsed.hostname}"
|
|
36
|
+
if parsed.port:
|
|
37
|
+
netloc += f":{parsed.port}"
|
|
38
|
+
return urlunsplit((parsed.scheme, netloc, parsed.path, parsed.query, parsed.fragment))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _devops_pat_placeholder(url: str) -> str:
|
|
42
|
+
"""Insert dbt's `env_var()` Jinja placeholder for the DevOps PAT into an Azure
|
|
43
|
+
DevOps HTTPS URL, so dbt authenticates when it parses packages.yml. Non-Azure
|
|
44
|
+
DevOps URLs (e.g. GitHub) are returned unchanged."""
|
|
45
|
+
if not _is_azure_devops_url(url):
|
|
46
|
+
return url
|
|
47
|
+
placeholder = f"{{{{ env_var('{DEVOPS_PAT_ENV_VAR}', '') }}}}"
|
|
48
|
+
return _with_userinfo(url, placeholder)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _devops_pat_authenticated(url: str) -> str:
|
|
52
|
+
"""Insert the DevOps PAT's actual value (read from the environment) into an Azure
|
|
53
|
+
DevOps HTTPS URL, for authenticating the `git ls-remote` tag lookup itself (dbt's
|
|
54
|
+
`env_var()` Jinja isn't resolved by plain git). Returns the URL unchanged if the
|
|
55
|
+
env var isn't set or the URL isn't an Azure DevOps URL."""
|
|
56
|
+
if not _is_azure_devops_url(url):
|
|
57
|
+
return url
|
|
58
|
+
pat = os.environ.get(DEVOPS_PAT_ENV_VAR, "")
|
|
59
|
+
if not pat:
|
|
60
|
+
return url
|
|
61
|
+
return _with_userinfo(url, pat)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _effective_packages(profile: ProjectProfile, all_package_names: set[str]) -> set[str]:
|
|
65
|
+
"""The set of framework catalog packages a profile effectively pulls in directly,
|
|
66
|
+
before subtracting its own upstream exclusions — mirrors the three-way selection
|
|
67
|
+
logic in download_dbt_packages()/generate_packages_yml() so that collecting an
|
|
68
|
+
upstream profile's packages (for exclusion purposes) matches what it would actually
|
|
69
|
+
resolve to, including the 'no selection, no upstream' catalog-wide fallback."""
|
|
70
|
+
if profile.dbt_packages:
|
|
71
|
+
return set(profile.dbt_packages)
|
|
72
|
+
if profile.upstream_projects:
|
|
73
|
+
return set()
|
|
74
|
+
return set(all_package_names)
|
|
75
|
+
|
|
12
76
|
|
|
13
77
|
def _collect_upstream_packages(
|
|
14
78
|
upstream_names: list[str],
|
|
15
79
|
profile_map: dict[str, ProjectProfile],
|
|
80
|
+
all_package_names: set[str],
|
|
16
81
|
visited: set[str] | None = None,
|
|
17
82
|
) -> set[str]:
|
|
18
|
-
"""Recursively collect dbt package names
|
|
83
|
+
"""Recursively collect the dbt package names provided by all upstream projects."""
|
|
19
84
|
if visited is None:
|
|
20
85
|
visited = set()
|
|
21
86
|
result: set[str] = set()
|
|
@@ -25,10 +90,10 @@ def _collect_upstream_packages(
|
|
|
25
90
|
visited.add(name)
|
|
26
91
|
upstream = profile_map.get(name)
|
|
27
92
|
if upstream:
|
|
28
|
-
result.update(upstream
|
|
93
|
+
result.update(_effective_packages(upstream, all_package_names))
|
|
29
94
|
result.update(
|
|
30
95
|
_collect_upstream_packages(
|
|
31
|
-
upstream.upstream_projects or [], profile_map, visited
|
|
96
|
+
upstream.upstream_projects or [], profile_map, all_package_names, visited
|
|
32
97
|
)
|
|
33
98
|
)
|
|
34
99
|
return result
|
|
@@ -222,19 +287,14 @@ class DownloadService:
|
|
|
222
287
|
|
|
223
288
|
# Filter to only packages enabled on the active profile
|
|
224
289
|
if profile:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
# Exclude packages already provided by upstream projects — this must
|
|
232
|
-
# run even when the downstream profile has no explicit dbt_packages
|
|
233
|
-
# of its own, since it may rely entirely on an upstream project.
|
|
290
|
+
all_package_names = {p.get("name") for p in packages}
|
|
291
|
+
enabled = _effective_packages(profile, all_package_names)
|
|
292
|
+
|
|
293
|
+
# Exclude packages already provided by upstream projects
|
|
234
294
|
if profile.upstream_projects and all_profiles:
|
|
235
295
|
profile_map = {p.profile_name: p for p in all_profiles}
|
|
236
296
|
upstream_pkgs = _collect_upstream_packages(
|
|
237
|
-
profile.upstream_projects, profile_map
|
|
297
|
+
profile.upstream_projects, profile_map, all_package_names
|
|
238
298
|
)
|
|
239
299
|
enabled -= upstream_pkgs
|
|
240
300
|
|
|
@@ -257,11 +317,24 @@ class DownloadService:
|
|
|
257
317
|
entry["version"] = version
|
|
258
318
|
pkg_list.append(entry)
|
|
259
319
|
|
|
260
|
-
# Add upstream project dependencies as
|
|
320
|
+
# Add upstream project dependencies as git packages pinned to their latest tag
|
|
261
321
|
if profile and profile.upstream_projects:
|
|
322
|
+
upstream_profile_map = {p.profile_name: p for p in (all_profiles or [])}
|
|
262
323
|
for upstream_name in profile.upstream_projects:
|
|
263
|
-
|
|
264
|
-
|
|
324
|
+
upstream_profile = upstream_profile_map.get(upstream_name)
|
|
325
|
+
git_url = upstream_profile.git_url if upstream_profile else ""
|
|
326
|
+
if not git_url:
|
|
327
|
+
warning_line(f" No git_url configured for upstream project '{upstream_name}' — skipping")
|
|
328
|
+
continue
|
|
329
|
+
latest_tag = get_latest_tag(_devops_pat_authenticated(git_url))
|
|
330
|
+
entry = {
|
|
331
|
+
"git": _devops_pat_placeholder(git_url),
|
|
332
|
+
"subdirectory": upstream_profile.project_dir,
|
|
333
|
+
}
|
|
334
|
+
if latest_tag:
|
|
335
|
+
entry["revision"] = latest_tag
|
|
336
|
+
pkg_list.append(entry)
|
|
337
|
+
info_line(f" Added upstream dependency: {upstream_name} ({latest_tag or 'no tag found'})")
|
|
265
338
|
|
|
266
339
|
dest = dbt_project_dir / "packages.yml"
|
|
267
340
|
content = yaml.dump({"packages": pkg_list}, default_flow_style=False, sort_keys=False)
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/upstream_service.py
RENAMED
|
@@ -64,11 +64,15 @@ def find_pinned_version(packages_data: dict, git_url: str) -> str:
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
def _urls_match(url1: str, url2: str) -> bool:
|
|
67
|
-
"""Compare two git URLs, ignoring trailing .git
|
|
67
|
+
"""Compare two git URLs, ignoring trailing .git, protocol differences, and any
|
|
68
|
+
userinfo (e.g. a PAT or a `{{ env_var(...) }}` Jinja placeholder) before the host —
|
|
69
|
+
generated upstream dependency URLs embed one, but the profile's plain `git_url`
|
|
70
|
+
doesn't."""
|
|
68
71
|
def normalize(url: str) -> str:
|
|
69
72
|
url = url.rstrip("/").removesuffix(".git").lower()
|
|
70
73
|
url = re.sub(r"^https?://", "", url)
|
|
71
74
|
url = re.sub(r"^git@([^:]+):", r"\1/", url)
|
|
75
|
+
url = re.sub(r"^[^/]*@", "", url)
|
|
72
76
|
return url
|
|
73
77
|
return normalize(url1) == normalize(url2)
|
|
74
78
|
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Tests for engine-conditional logic in datasecops_cli.services.download_service."""
|
|
2
|
+
from unittest.mock import MagicMock, patch
|
|
3
|
+
|
|
4
|
+
from datasecops_cli.services.download_service import (
|
|
5
|
+
DownloadService, _devops_pat_placeholder, _devops_pat_authenticated,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _versions_config():
|
|
10
|
+
return {
|
|
11
|
+
"sqlfluff_versions": [{"version": "3.4.0", "active": True}],
|
|
12
|
+
"sqlfluff_templater_versions": [{"version": "3.4.0", "active": True}],
|
|
13
|
+
"dbt_core_versions": [{"version": "1.9.0", "active": True}],
|
|
14
|
+
"dbt_snowflake_versions": [{"version": "1.9.0", "active": True}],
|
|
15
|
+
"dbt2_versions": [{"version": "2.0.4", "active": True}],
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TestGetDbtRequirements:
|
|
20
|
+
def test_dbt_core_engine_returns_core_and_snowflake(self, tmp_path):
|
|
21
|
+
mock_sf = MagicMock()
|
|
22
|
+
mock_sf.get_framework_config.return_value = _versions_config()
|
|
23
|
+
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt_core")
|
|
24
|
+
|
|
25
|
+
result = service.get_dbt_requirements()
|
|
26
|
+
|
|
27
|
+
assert result == ["dbt-core==1.9.0", "dbt-snowflake==1.9.0"]
|
|
28
|
+
|
|
29
|
+
def test_dbt2_engine_returns_dbt_only(self, tmp_path):
|
|
30
|
+
mock_sf = MagicMock()
|
|
31
|
+
mock_sf.get_framework_config.return_value = _versions_config()
|
|
32
|
+
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
33
|
+
|
|
34
|
+
result = service.get_dbt_requirements()
|
|
35
|
+
|
|
36
|
+
assert result == ["dbt==2.0.4"]
|
|
37
|
+
|
|
38
|
+
def test_version_prefix_is_stripped(self, tmp_path):
|
|
39
|
+
mock_sf = MagicMock()
|
|
40
|
+
mock_sf.get_framework_config.return_value = {"dbt2_versions": [{"version": "v2.0.9", "active": True}]}
|
|
41
|
+
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
42
|
+
|
|
43
|
+
assert service.get_dbt_requirements() == ["dbt==2.0.9"]
|
|
44
|
+
|
|
45
|
+
def test_without_an_active_version_the_first_enabled_is_used(self, tmp_path):
|
|
46
|
+
mock_sf = MagicMock()
|
|
47
|
+
mock_sf.get_framework_config.return_value = {"dbt2_versions": [
|
|
48
|
+
{"version": "v2.0.9", "enabled": False},
|
|
49
|
+
{"version": "v2.0.4", "enabled": True},
|
|
50
|
+
{"version": "v2.0.0", "enabled": True},
|
|
51
|
+
]}
|
|
52
|
+
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
53
|
+
|
|
54
|
+
assert service.get_dbt_requirements() == ["dbt==2.0.4"]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class TestGetSqlfluffRequirements:
|
|
58
|
+
def test_dbt_core_engine_returns_sqlfluff_packages(self, tmp_path):
|
|
59
|
+
mock_sf = MagicMock()
|
|
60
|
+
mock_sf.get_framework_config.return_value = _versions_config()
|
|
61
|
+
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt_core")
|
|
62
|
+
|
|
63
|
+
result = service.get_sqlfluff_requirements()
|
|
64
|
+
|
|
65
|
+
assert result == ["sqlfluff==3.4.0", "sqlfluff-templater-dbt==3.4.0"]
|
|
66
|
+
|
|
67
|
+
def test_dbt2_engine_returns_empty_list(self, tmp_path):
|
|
68
|
+
"""dbt 2.0's built-in `dbt lint` needs no separate SQLFluff package."""
|
|
69
|
+
mock_sf = MagicMock()
|
|
70
|
+
mock_sf.get_framework_config.return_value = _versions_config()
|
|
71
|
+
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
72
|
+
|
|
73
|
+
result = service.get_sqlfluff_requirements()
|
|
74
|
+
|
|
75
|
+
assert result == []
|
|
76
|
+
mock_sf.get_framework_config.assert_not_called()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class TestDownloadServiceDefaults:
|
|
80
|
+
def test_defaults_to_dbt_core_engine(self, tmp_path):
|
|
81
|
+
mock_sf = MagicMock()
|
|
82
|
+
service = DownloadService(mock_sf, tmp_path)
|
|
83
|
+
assert service.dbt_engine == "dbt_core"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class TestDevOpsPatPlaceholder:
|
|
87
|
+
def test_inserts_env_var_jinja_for_azure_devops_url(self):
|
|
88
|
+
url = "https://dev.azure.com/org/proj/_git/repo"
|
|
89
|
+
result = _devops_pat_placeholder(url)
|
|
90
|
+
assert result == "https://{{ env_var('DBT_ENV_SECRET_DEVOPS_PAT', '') }}@dev.azure.com/org/proj/_git/repo"
|
|
91
|
+
|
|
92
|
+
def test_leaves_non_azure_devops_url_unchanged(self):
|
|
93
|
+
url = "https://github.com/dbt-labs/dbt-utils"
|
|
94
|
+
assert _devops_pat_placeholder(url) == url
|
|
95
|
+
|
|
96
|
+
def test_does_not_match_lookalike_host(self):
|
|
97
|
+
"""A substring check would wrongly treat this as dev.azure.com; the PAT must
|
|
98
|
+
not leak to an unrelated, attacker-controlled host."""
|
|
99
|
+
url = "https://dev.azure.com.evil.example/org/proj/_git/repo"
|
|
100
|
+
assert _devops_pat_placeholder(url) == url
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TestDevOpsPatAuthenticated:
|
|
104
|
+
def test_inserts_pat_value_for_azure_devops_url(self, monkeypatch):
|
|
105
|
+
monkeypatch.setenv("DBT_ENV_SECRET_DEVOPS_PAT", "my-secret-pat")
|
|
106
|
+
url = "https://dev.azure.com/org/proj/_git/repo"
|
|
107
|
+
assert _devops_pat_authenticated(url) == "https://my-secret-pat@dev.azure.com/org/proj/_git/repo"
|
|
108
|
+
|
|
109
|
+
def test_leaves_url_unchanged_when_env_var_not_set(self, monkeypatch):
|
|
110
|
+
monkeypatch.delenv("DBT_ENV_SECRET_DEVOPS_PAT", raising=False)
|
|
111
|
+
url = "https://dev.azure.com/org/proj/_git/repo"
|
|
112
|
+
assert _devops_pat_authenticated(url) == url
|
|
113
|
+
|
|
114
|
+
def test_leaves_non_azure_devops_url_unchanged(self, monkeypatch):
|
|
115
|
+
monkeypatch.setenv("DBT_ENV_SECRET_DEVOPS_PAT", "my-secret-pat")
|
|
116
|
+
url = "https://github.com/dbt-labs/dbt-utils"
|
|
117
|
+
assert _devops_pat_authenticated(url) == url
|
|
118
|
+
|
|
119
|
+
def test_does_not_match_lookalike_host(self, monkeypatch):
|
|
120
|
+
monkeypatch.setenv("DBT_ENV_SECRET_DEVOPS_PAT", "my-secret-pat")
|
|
121
|
+
url = "https://dev.azure.com.evil.example/org/proj/_git/repo"
|
|
122
|
+
assert _devops_pat_authenticated(url) == url
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class TestCollectUpstreamPackages:
|
|
126
|
+
def test_upstream_with_no_selection_and_no_further_upstream_contributes_all_catalog_packages(self):
|
|
127
|
+
"""An upstream profile with an empty dbt_packages selection and no upstream of
|
|
128
|
+
its own effectively gets every catalog package (the 'no selection, no upstream'
|
|
129
|
+
fallback) — collection must account for that, not just its empty explicit list,
|
|
130
|
+
otherwise a downstream profile's own explicit selection of one of those packages
|
|
131
|
+
isn't excluded and ends up listed both directly and via the upstream dependency."""
|
|
132
|
+
from datasecops_cli.models.project_config import ProjectProfile
|
|
133
|
+
from datasecops_cli.services.download_service import _collect_upstream_packages
|
|
134
|
+
|
|
135
|
+
upstream_profile = ProjectProfile(profile_name="upstream", dbt_packages=[])
|
|
136
|
+
profile_map = {"upstream": upstream_profile}
|
|
137
|
+
all_package_names = {"dbt_utils", "dbt_expectations"}
|
|
138
|
+
|
|
139
|
+
result = _collect_upstream_packages(["upstream"], profile_map, all_package_names)
|
|
140
|
+
|
|
141
|
+
assert result == all_package_names
|
|
142
|
+
|
|
143
|
+
def test_downstream_explicit_selection_excluded_via_upstream_all_fallback(self, tmp_path):
|
|
144
|
+
from datasecops_cli.models.project_config import ProjectProfile
|
|
145
|
+
from datasecops_cli.services.download_service import DownloadService
|
|
146
|
+
import yaml
|
|
147
|
+
|
|
148
|
+
mock_sf = MagicMock()
|
|
149
|
+
mock_sf.get_framework_config.return_value = {
|
|
150
|
+
"packages": [
|
|
151
|
+
{"name": "dbt_utils", "source": "git", "url": "https://github.com/dbt-labs/dbt-utils.git", "latest_version": "1.0.0"},
|
|
152
|
+
{"name": "dbt_expectations", "source": "git", "url": "https://github.com/calogica/dbt-expectations.git", "latest_version": "0.10.0"},
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
upstream_profile = ProjectProfile(profile_name="upstream", dbt_packages=[])
|
|
157
|
+
profile = ProjectProfile(
|
|
158
|
+
profile_name="downstream",
|
|
159
|
+
dbt_packages=["dbt_utils"],
|
|
160
|
+
upstream_projects=["upstream"],
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
service = DownloadService(mock_sf, tmp_path)
|
|
164
|
+
service.download_dbt_packages(tmp_path, profile=profile, all_profiles=[profile, upstream_profile])
|
|
165
|
+
|
|
166
|
+
result = yaml.safe_load((tmp_path / "packages.yml").read_text())
|
|
167
|
+
# dbt_utils must be excluded — the upstream project, having no selection and no
|
|
168
|
+
# upstream of its own, effectively already provides it.
|
|
169
|
+
names = [p.get("git") for p in result["packages"] if "git" in p]
|
|
170
|
+
assert "https://github.com/dbt-labs/dbt-utils.git" not in names
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class TestDownloadDbtPackagesUpstreamDependency:
|
|
174
|
+
def test_latest_tag_lookup_uses_real_pat_not_jinja_placeholder(self, tmp_path, monkeypatch):
|
|
175
|
+
"""The git ls-remote tag lookup must authenticate with the PAT's actual value;
|
|
176
|
+
the Jinja placeholder (only resolved by dbt) would fail as a literal URL."""
|
|
177
|
+
from datasecops_cli.models.project_config import ProjectProfile
|
|
178
|
+
|
|
179
|
+
monkeypatch.setenv("DBT_ENV_SECRET_DEVOPS_PAT", "my-secret-pat")
|
|
180
|
+
mock_sf = MagicMock()
|
|
181
|
+
mock_sf.get_framework_config.return_value = {"packages": []}
|
|
182
|
+
|
|
183
|
+
upstream_profile = ProjectProfile(
|
|
184
|
+
profile_name="upstream",
|
|
185
|
+
git_url="https://dev.azure.com/org/proj/_git/repo",
|
|
186
|
+
)
|
|
187
|
+
profile = ProjectProfile(profile_name="downstream", upstream_projects=["upstream"])
|
|
188
|
+
|
|
189
|
+
service = DownloadService(mock_sf, tmp_path)
|
|
190
|
+
with patch("datasecops_cli.services.download_service.get_latest_tag", return_value="v1.0.0") as mock_tag:
|
|
191
|
+
service.download_dbt_packages(tmp_path, profile=profile, all_profiles=[profile, upstream_profile])
|
|
192
|
+
|
|
193
|
+
mock_tag.assert_called_once_with("https://my-secret-pat@dev.azure.com/org/proj/_git/repo")
|
|
194
|
+
|
|
195
|
+
def test_no_git_url_skips_upstream_dependency(self, tmp_path):
|
|
196
|
+
from datasecops_cli.models.project_config import ProjectProfile
|
|
197
|
+
import yaml
|
|
198
|
+
|
|
199
|
+
mock_sf = MagicMock()
|
|
200
|
+
mock_sf.get_framework_config.return_value = {"packages": []}
|
|
201
|
+
|
|
202
|
+
upstream_profile = ProjectProfile(profile_name="upstream", git_url="")
|
|
203
|
+
profile = ProjectProfile(profile_name="downstream", upstream_projects=["upstream"])
|
|
204
|
+
|
|
205
|
+
service = DownloadService(mock_sf, tmp_path)
|
|
206
|
+
service.download_dbt_packages(tmp_path, profile=profile, all_profiles=[profile, upstream_profile])
|
|
207
|
+
|
|
208
|
+
result = yaml.safe_load((tmp_path / "packages.yml").read_text())
|
|
209
|
+
assert result["packages"] == []
|
|
210
|
+
|
|
211
|
+
def test_uses_upstream_projects_own_project_dir(self, tmp_path):
|
|
212
|
+
"""Not every upstream project's dbt project lives under a 'dbt/' subdirectory;
|
|
213
|
+
the generated subdirectory must come from that project's own configuration."""
|
|
214
|
+
from datasecops_cli.models.project_config import ProjectProfile
|
|
215
|
+
import yaml
|
|
216
|
+
|
|
217
|
+
mock_sf = MagicMock()
|
|
218
|
+
mock_sf.get_framework_config.return_value = {"packages": []}
|
|
219
|
+
|
|
220
|
+
upstream_profile = ProjectProfile(
|
|
221
|
+
profile_name="upstream",
|
|
222
|
+
git_url="https://github.com/org/repo",
|
|
223
|
+
project_dir="analytics",
|
|
224
|
+
)
|
|
225
|
+
profile = ProjectProfile(profile_name="downstream", upstream_projects=["upstream"])
|
|
226
|
+
|
|
227
|
+
service = DownloadService(mock_sf, tmp_path)
|
|
228
|
+
with patch("datasecops_cli.services.download_service.get_latest_tag", return_value=None):
|
|
229
|
+
service.download_dbt_packages(tmp_path, profile=profile, all_profiles=[profile, upstream_profile])
|
|
230
|
+
|
|
231
|
+
result = yaml.safe_load((tmp_path / "packages.yml").read_text())
|
|
232
|
+
assert result["packages"][0]["subdirectory"] == "analytics"
|
|
233
|
+
|
|
234
|
+
def test_project_dir_defaults_to_dbt(self):
|
|
235
|
+
from datasecops_cli.models.project_config import ProjectProfile
|
|
236
|
+
assert ProjectProfile().project_dir == "dbt"
|
|
@@ -455,6 +455,7 @@ class TestDownloadPackageFiltering:
|
|
|
455
455
|
upstream_profile = ProjectProfile(
|
|
456
456
|
profile_name="upstream_project",
|
|
457
457
|
dbt_packages=["dbt_utils"],
|
|
458
|
+
git_url="https://dev.azure.com/org/proj/_git/upstream-repo",
|
|
458
459
|
)
|
|
459
460
|
profile = ProjectProfile(
|
|
460
461
|
profile_name="test",
|
|
@@ -463,17 +464,20 @@ class TestDownloadPackageFiltering:
|
|
|
463
464
|
)
|
|
464
465
|
|
|
465
466
|
service = DownloadService(mock_sf, tmp_path)
|
|
466
|
-
|
|
467
|
+
with patch("datasecops_cli.services.download_service.get_latest_tag", return_value="v1.2.3"):
|
|
468
|
+
service.download_dbt_packages(tmp_path, profile=profile, all_profiles=[profile, upstream_profile])
|
|
467
469
|
|
|
468
470
|
import yaml
|
|
469
471
|
result = yaml.safe_load((tmp_path / "packages.yml").read_text())
|
|
470
|
-
# dbt_utils excluded (provided by upstream), only dbt_expectations +
|
|
472
|
+
# dbt_utils excluded (provided by upstream), only dbt_expectations + the
|
|
473
|
+
# upstream project itself as a git dependency pinned to its latest tag.
|
|
471
474
|
git_packages = [p for p in result["packages"] if "git" in p]
|
|
472
|
-
|
|
473
|
-
assert len(git_packages) == 1
|
|
475
|
+
assert len(git_packages) == 2
|
|
474
476
|
assert git_packages[0]["git"] == "https://github.com/calogica/dbt-expectations.git"
|
|
475
|
-
|
|
476
|
-
assert
|
|
477
|
+
upstream_dep = git_packages[1]
|
|
478
|
+
assert "{{ env_var('DBT_ENV_SECRET_DEVOPS_PAT', '') }}@dev.azure.com" in upstream_dep["git"]
|
|
479
|
+
assert upstream_dep["subdirectory"] == "dbt"
|
|
480
|
+
assert upstream_dep["revision"] == "v1.2.3"
|
|
477
481
|
|
|
478
482
|
def test_download_dbt_packages_no_profile_downloads_all(self, tmp_path):
|
|
479
483
|
"""When no profile is passed, all packages should be included."""
|
|
@@ -518,8 +522,9 @@ class TestDownloadPackageFiltering:
|
|
|
518
522
|
|
|
519
523
|
def test_download_dbt_packages_empty_dbt_packages_still_excludes_upstream(self, tmp_path):
|
|
520
524
|
"""A downstream project with no dbt_packages of its own (relying entirely on an
|
|
521
|
-
upstream project) should
|
|
522
|
-
|
|
525
|
+
upstream project) should get NONE of the framework's packages directly — not the
|
|
526
|
+
upstream's packages, and not any other package it never selected either — only
|
|
527
|
+
the upstream project added as a git dependency pinned to its latest tag."""
|
|
523
528
|
from datasecops_cli.services.download_service import DownloadService
|
|
524
529
|
|
|
525
530
|
mock_sf = MagicMock()
|
|
@@ -527,12 +532,14 @@ class TestDownloadPackageFiltering:
|
|
|
527
532
|
"packages": [
|
|
528
533
|
{"name": "dbt_utils", "source": "git", "url": "https://github.com/dbt-labs/dbt-utils.git", "latest_version": "1.0.0"},
|
|
529
534
|
{"name": "dbt_expectations", "source": "git", "url": "https://github.com/calogica/dbt-expectations.git", "latest_version": "0.10.0"},
|
|
535
|
+
{"name": "dbt_constraints", "source": "git", "url": "https://github.com/Snowflake-Labs/dbt_constraints.git", "latest_version": "0.6.0"},
|
|
530
536
|
]
|
|
531
537
|
}
|
|
532
538
|
|
|
533
539
|
upstream_profile = ProjectProfile(
|
|
534
540
|
profile_name="upstream_project",
|
|
535
|
-
dbt_packages=["dbt_utils"
|
|
541
|
+
dbt_packages=["dbt_utils"],
|
|
542
|
+
git_url="https://dev.azure.com/org/proj/_git/upstream-repo",
|
|
536
543
|
)
|
|
537
544
|
profile = ProjectProfile(
|
|
538
545
|
profile_name="downstream",
|
|
@@ -541,15 +548,19 @@ class TestDownloadPackageFiltering:
|
|
|
541
548
|
)
|
|
542
549
|
|
|
543
550
|
service = DownloadService(mock_sf, tmp_path)
|
|
544
|
-
|
|
551
|
+
with patch("datasecops_cli.services.download_service.get_latest_tag", return_value="v2.0.0"):
|
|
552
|
+
service.download_dbt_packages(tmp_path, profile=profile, all_profiles=[profile, upstream_profile])
|
|
545
553
|
|
|
546
554
|
import yaml
|
|
547
555
|
result = yaml.safe_load((tmp_path / "packages.yml").read_text())
|
|
548
556
|
git_packages = [p for p in result["packages"] if "git" in p]
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
assert
|
|
557
|
+
# Not just dbt_utils excluded — dbt_expectations and dbt_constraints must also
|
|
558
|
+
# be absent, since the downstream profile never selected them either. Only the
|
|
559
|
+
# upstream project itself should be present, as a git dependency.
|
|
560
|
+
assert len(git_packages) == 1
|
|
561
|
+
assert "{{ env_var('DBT_ENV_SECRET_DEVOPS_PAT', '') }}@dev.azure.com" in git_packages[0]["git"]
|
|
562
|
+
assert git_packages[0]["subdirectory"] == "dbt"
|
|
563
|
+
assert git_packages[0]["revision"] == "v2.0.0"
|
|
553
564
|
|
|
554
565
|
|
|
555
566
|
class TestPipelineEnvCommand:
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Tests for datasecops_cli.services.upstream_service."""
|
|
2
|
+
from datasecops_cli.services.upstream_service import _urls_match, find_pinned_version
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestUrlsMatch:
|
|
6
|
+
def test_plain_https_urls_match(self):
|
|
7
|
+
assert _urls_match(
|
|
8
|
+
"https://dev.azure.com/org/proj/_git/repo",
|
|
9
|
+
"https://dev.azure.com/org/proj/_git/repo",
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
def test_trailing_git_and_slash_ignored(self):
|
|
13
|
+
assert _urls_match(
|
|
14
|
+
"https://github.com/dbt-labs/dbt-utils.git",
|
|
15
|
+
"https://github.com/dbt-labs/dbt-utils/",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def test_ssh_and_https_forms_match(self):
|
|
19
|
+
assert _urls_match(
|
|
20
|
+
"git@github.com:dbt-labs/dbt-utils.git",
|
|
21
|
+
"https://github.com/dbt-labs/dbt-utils",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def test_jinja_pat_placeholder_userinfo_is_ignored(self):
|
|
25
|
+
"""A generated upstream dependency URL carries a `{{ env_var(...) }}@` userinfo
|
|
26
|
+
prefix; it must still match the profile's plain git_url (no userinfo) so the
|
|
27
|
+
upstream-version checker recognizes it as already pinned."""
|
|
28
|
+
generated = "https://{{ env_var('DBT_ENV_SECRET_DEVOPS_PAT', '') }}@dev.azure.com/org/proj/_git/repo"
|
|
29
|
+
plain = "https://dev.azure.com/org/proj/_git/repo"
|
|
30
|
+
assert _urls_match(generated, plain)
|
|
31
|
+
|
|
32
|
+
def test_pat_value_userinfo_is_ignored(self):
|
|
33
|
+
generated = "https://my-secret-pat@dev.azure.com/org/proj/_git/repo"
|
|
34
|
+
plain = "https://dev.azure.com/org/proj/_git/repo"
|
|
35
|
+
assert _urls_match(generated, plain)
|
|
36
|
+
|
|
37
|
+
def test_different_repos_do_not_match(self):
|
|
38
|
+
assert not _urls_match(
|
|
39
|
+
"https://dev.azure.com/org/proj/_git/repo-a",
|
|
40
|
+
"https://dev.azure.com/org/proj/_git/repo-b",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class TestFindPinnedVersion:
|
|
45
|
+
def test_finds_revision_for_generated_upstream_url(self):
|
|
46
|
+
"""find_pinned_version() must recognize a packages.yml entry generated by
|
|
47
|
+
download_dbt_packages() (git URL with the DevOps PAT placeholder) as pinning
|
|
48
|
+
the same upstream project the profile's plain git_url refers to."""
|
|
49
|
+
packages_data = {
|
|
50
|
+
"packages": [
|
|
51
|
+
{
|
|
52
|
+
"git": "https://{{ env_var('DBT_ENV_SECRET_DEVOPS_PAT', '') }}@dev.azure.com/org/proj/_git/repo",
|
|
53
|
+
"subdirectory": "dbt",
|
|
54
|
+
"revision": "v1.2.3",
|
|
55
|
+
},
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
result = find_pinned_version(packages_data, "https://dev.azure.com/org/proj/_git/repo")
|
|
59
|
+
assert result == "v1.2.3"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.7.0b12"
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"""Tests for engine-conditional logic in datasecops_cli.services.download_service."""
|
|
2
|
-
from unittest.mock import MagicMock
|
|
3
|
-
|
|
4
|
-
from datasecops_cli.services.download_service import DownloadService
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def _versions_config():
|
|
8
|
-
return {
|
|
9
|
-
"sqlfluff_versions": [{"version": "3.4.0", "active": True}],
|
|
10
|
-
"sqlfluff_templater_versions": [{"version": "3.4.0", "active": True}],
|
|
11
|
-
"dbt_core_versions": [{"version": "1.9.0", "active": True}],
|
|
12
|
-
"dbt_snowflake_versions": [{"version": "1.9.0", "active": True}],
|
|
13
|
-
"dbt2_versions": [{"version": "2.0.4", "active": True}],
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class TestGetDbtRequirements:
|
|
18
|
-
def test_dbt_core_engine_returns_core_and_snowflake(self, tmp_path):
|
|
19
|
-
mock_sf = MagicMock()
|
|
20
|
-
mock_sf.get_framework_config.return_value = _versions_config()
|
|
21
|
-
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt_core")
|
|
22
|
-
|
|
23
|
-
result = service.get_dbt_requirements()
|
|
24
|
-
|
|
25
|
-
assert result == ["dbt-core==1.9.0", "dbt-snowflake==1.9.0"]
|
|
26
|
-
|
|
27
|
-
def test_dbt2_engine_returns_dbt_only(self, tmp_path):
|
|
28
|
-
mock_sf = MagicMock()
|
|
29
|
-
mock_sf.get_framework_config.return_value = _versions_config()
|
|
30
|
-
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
31
|
-
|
|
32
|
-
result = service.get_dbt_requirements()
|
|
33
|
-
|
|
34
|
-
assert result == ["dbt==2.0.4"]
|
|
35
|
-
|
|
36
|
-
def test_version_prefix_is_stripped(self, tmp_path):
|
|
37
|
-
mock_sf = MagicMock()
|
|
38
|
-
mock_sf.get_framework_config.return_value = {"dbt2_versions": [{"version": "v2.0.9", "active": True}]}
|
|
39
|
-
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
40
|
-
|
|
41
|
-
assert service.get_dbt_requirements() == ["dbt==2.0.9"]
|
|
42
|
-
|
|
43
|
-
def test_without_an_active_version_the_first_enabled_is_used(self, tmp_path):
|
|
44
|
-
mock_sf = MagicMock()
|
|
45
|
-
mock_sf.get_framework_config.return_value = {"dbt2_versions": [
|
|
46
|
-
{"version": "v2.0.9", "enabled": False},
|
|
47
|
-
{"version": "v2.0.4", "enabled": True},
|
|
48
|
-
{"version": "v2.0.0", "enabled": True},
|
|
49
|
-
]}
|
|
50
|
-
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
51
|
-
|
|
52
|
-
assert service.get_dbt_requirements() == ["dbt==2.0.4"]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class TestGetSqlfluffRequirements:
|
|
56
|
-
def test_dbt_core_engine_returns_sqlfluff_packages(self, tmp_path):
|
|
57
|
-
mock_sf = MagicMock()
|
|
58
|
-
mock_sf.get_framework_config.return_value = _versions_config()
|
|
59
|
-
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt_core")
|
|
60
|
-
|
|
61
|
-
result = service.get_sqlfluff_requirements()
|
|
62
|
-
|
|
63
|
-
assert result == ["sqlfluff==3.4.0", "sqlfluff-templater-dbt==3.4.0"]
|
|
64
|
-
|
|
65
|
-
def test_dbt2_engine_returns_empty_list(self, tmp_path):
|
|
66
|
-
"""dbt 2.0's built-in `dbt lint` needs no separate SQLFluff package."""
|
|
67
|
-
mock_sf = MagicMock()
|
|
68
|
-
mock_sf.get_framework_config.return_value = _versions_config()
|
|
69
|
-
service = DownloadService(mock_sf, tmp_path, dbt_engine="dbt2")
|
|
70
|
-
|
|
71
|
-
result = service.get_sqlfluff_requirements()
|
|
72
|
-
|
|
73
|
-
assert result == []
|
|
74
|
-
mock_sf.get_framework_config.assert_not_called()
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class TestDownloadServiceDefaults:
|
|
78
|
-
def test_defaults_to_dbt_core_engine(self, tmp_path):
|
|
79
|
-
mock_sf = MagicMock()
|
|
80
|
-
service = DownloadService(mock_sf, tmp_path)
|
|
81
|
-
assert service.dbt_engine == "dbt_core"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/configuration.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/dcm_operations.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/menus/git_operations.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/models/git_helpers.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/bootstrap_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dbt_runner.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_orchestrator.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_pipelines.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_registry.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/dcm_service.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/git_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/linting_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/model_commands.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/pipeline_env.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/skill_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/services/snowflake_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/file_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_cli/utilities/yaml_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/src/datasecops_model/templates/macros/role.sql
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b12 → datasecops_cli-0.7.0b13}/tests/test_dbt_project_generator_profiles.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|