datasecops-cli 0.7.0b6__tar.gz → 0.7.0b7__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.0b6 → datasecops_cli-0.7.0b7}/CHANGELOG.md +13 -1
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/PKG-INFO +2 -2
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/README.md +1 -1
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/docs/dcm.md +6 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/pyproject.toml +1 -1
- datasecops_cli-0.7.0b7/src/datasecops_cli/__init__.py +1 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/main.py +37 -7
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dbt_project_generator.py +150 -45
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/download_service.py +8 -3
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_dbt_project_generator_profiles.py +141 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_main.py +57 -2
- datasecops_cli-0.7.0b6/src/datasecops_cli/__init__.py +0 -1
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/.github/workflows/auto-tag.yml +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/.github/workflows/publish-cli.yml +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/.github/workflows/test.yml +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/.gitignore +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/AGENTS.md +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/DEVELOPMENT.md +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/LICENSE +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/docs/getting-started.md +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/docs/git-operations.md +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/docs/legacy.md +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/docs/legacy_plan_of_action.md +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/docs/mcp-server.md +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/mcp-servers.json +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/scripts/vendor_model.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/setup.ps1 +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/setup.sh +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/config.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/__init__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/configuration.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/dcm_operations.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/development.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/downloads.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/git_operations.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/models/__init__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/models/git_helpers.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/models/project_config.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/__init__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/bootstrap_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dbt_runner.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_orchestrator.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_pipelines.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_registry.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/directory_scaffolder.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/git_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/linting_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/model_commands.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/pipeline_env.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/skill_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/snowflake_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/upstream_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/utilities/__init__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/utilities/display.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/utilities/file_utils.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/utilities/mcp.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/utilities/yaml_utils.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_mcp/__init__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_mcp/__main__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_mcp/connection.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_mcp/server.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/__init__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/convert.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/diagram.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/expand.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/extract.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/render.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/schema.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/scope.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/scripts.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/starter.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/templates/macros/role.sql +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/templates/macros/role_guard.sql +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/templates/macros/warehouse.sql +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_model/validate.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/__init__.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_config.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_dbt_runner.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_dcm_model.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_dcm_orchestrator.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_dcm_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_download_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_file_utils.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_linting_service.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_model_commands.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_models.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_pipeline_env.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_version.py +0 -0
- {datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_yaml_utils.py +0 -0
|
@@ -6,7 +6,19 @@ All notable changes to the DataSecOps CLI are documented in this file.
|
|
|
6
6
|
|
|
7
7
|
### Fixed
|
|
8
8
|
|
|
9
|
-
- **`
|
|
9
|
+
- **`profiles.yml` writes could still widen file permissions or miss a symlinked file** — the atomic-replace temp file is now created with restrictive (`0600`) permissions and, if `profiles.yml` already existed, its mode is reapplied before the swap, instead of inheriting the process umask (typically `0644`) and exposing credentials. The profiles path itself (not just its parent directory) is now resolved before deriving the lock and temp-file paths, so a symlinked `profiles.yml` is replaced at its real location instead of only the link.
|
|
10
|
+
|
|
11
|
+
## [0.7.0b7] - 2026-10-26
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **The main menu's `dcm` option now configures DCM** — previously it only appeared once `dcm_enabled` was set by hand in `.datasecops.yml`, with no CLI path to set it. It now always appears; selecting it before DCM is enabled prompts for `dcm_enabled` and the other `dcm_*` settings (model file, project root, legacy security/platform dirs, default target) and writes them to `.datasecops.yml`, then selecting it again opens DCM Infrastructure Operations directly.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **`datasecops bootstrap`/`setup` crashed writing `profiles.yml`** — `get_connection_params()` returned raw `tomlkit` value objects from `connections.toml`; dumping those into `profiles.yml` wrote a `!!python/object/apply:tomlkit.items.String` tag that `yaml.safe_load()` can't read back, crashing the *next* run (and any other profile sharing that file) with a `ConstructorError`. Values are now unwrapped to plain Python types before use, and `write_profiles_yml()` repairs a file already corrupted by this bug via a restricted loader that only reconstructs the known legacy tomlkit tags (never arbitrary objects, unlike `yaml.unsafe_load`), instead of crashing on it. A tomlkit `Integer`/`Float`/`Bool` surviving repair unconverted (still tagged on the next write), and a per-type argument-position bug in that same repair loader, are also fixed.
|
|
20
|
+
- **`profiles.yml` writes could race, corrupt on interruption, or mangle binary values** — the read-modify-write is now held under an OS-level lock (`fcntl.flock`/`msvcrt.locking`, released automatically if the holding process dies, so no stale-lock heuristic is needed) instead of proceeding unlocked if contended; it raises instead of silently skipping the lock. The write itself goes through a temp file + atomic replace so a crash or I/O error mid-write can't leave a half-written file. The profiles directory is resolved (symlinks included) before deriving the lock path, so two paths that alias the same directory can't bypass each other's lock. A pre-existing binary (`!!binary`) value is no longer corrupted into its text `b'...'` representation if the file also needs repairing.
|
|
21
|
+
- **README overstated the Python requirement** — said "Python 3.11 or later" while `pyproject.toml` (`>=3.10`) and the rest of the docs said 3.10; nothing in the codebase actually needs 3.11, so the README is corrected to match.
|
|
10
22
|
|
|
11
23
|
### Docs
|
|
12
24
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datasecops-cli
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.0b7
|
|
4
4
|
Summary: DataSecOps Framework CLI for Snowflake Native App
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -46,7 +46,7 @@ With MCP server support:
|
|
|
46
46
|
pip install "datasecops-cli[mcp]"
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
Requires Python 3.
|
|
49
|
+
Requires Python 3.10 or later.
|
|
50
50
|
|
|
51
51
|
## Prerequisites
|
|
52
52
|
|
|
@@ -64,6 +64,12 @@ The usual way is the native app:
|
|
|
64
64
|
object, owner, *CI deploys as*) and **Pipelines**. Apply, then Save.
|
|
65
65
|
4. **View generated files**, then **Push to branch** and open the pull request.
|
|
66
66
|
|
|
67
|
+
The CLI's interactive main menu only shows **DCM Infrastructure Operations** once `dcm_enabled`
|
|
68
|
+
is set in `.datasecops.yml`. Choosing **dcm** from the main menu before that walks you through
|
|
69
|
+
setting `dcm_enabled` and the other `dcm_*` settings (model file, project root, legacy
|
|
70
|
+
security/platform dirs, default target) and writes them to `.datasecops.yml` — no manual edit
|
|
71
|
+
needed. Selecting **dcm** again then opens DCM Infrastructure Operations directly.
|
|
72
|
+
|
|
67
73
|
From the CLI:
|
|
68
74
|
|
|
69
75
|
```bash
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.7.0b7"
|
|
@@ -26,7 +26,8 @@ from datasecops_cli.menus.configuration import ConfigurationMenu
|
|
|
26
26
|
from datasecops_cli.menus.dcm_operations import DcmOperationsMenu
|
|
27
27
|
from datasecops_cli.utilities.display import (
|
|
28
28
|
clear, section_header, display_action_header, menu_option, get_input_number,
|
|
29
|
-
info_line, warning_line, error_line, success_line, complete_action
|
|
29
|
+
info_line, warning_line, error_line, success_line, complete_action,
|
|
30
|
+
get_input_string_or_default
|
|
30
31
|
)
|
|
31
32
|
from datasecops_cli.utilities.yaml_utils import write_datasecops_config
|
|
32
33
|
|
|
@@ -1254,12 +1255,20 @@ def _main_menu(config: Config, dbt_runner: DbtRunner, git_service: GitService,
|
|
|
1254
1255
|
skill_targets=skill_targets, run_deps=run_deps,
|
|
1255
1256
|
scaffold_dcm=scaffold_dcm)
|
|
1256
1257
|
|
|
1257
|
-
elif option == 7
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1258
|
+
elif option == 7:
|
|
1259
|
+
if not config.datasecops.dcm_enabled:
|
|
1260
|
+
_configure_dcm(config)
|
|
1261
|
+
try:
|
|
1262
|
+
dcm_service = DcmService(sf_service, dcm_registry.dcm_root(config), config.datasecops.connection_name)
|
|
1263
|
+
except ValueError as e:
|
|
1264
|
+
error_line(str(e))
|
|
1265
|
+
dcm_service = None
|
|
1266
|
+
if dcm_service and config.datasecops.dcm_enabled:
|
|
1267
|
+
dcm_menu = DcmOperationsMenu(
|
|
1268
|
+
dcm_service, sf_service, profile_name,
|
|
1269
|
+
datasecops_config=config.datasecops, config=config,
|
|
1270
|
+
)
|
|
1271
|
+
dcm_menu.show()
|
|
1263
1272
|
|
|
1264
1273
|
elif option == 8 and has_outdated:
|
|
1265
1274
|
_update_upstream_packages(config, dbt_runner, upstream_statuses)
|
|
@@ -1276,6 +1285,25 @@ def _main_menu(config: Config, dbt_runner: DbtRunner, git_service: GitService,
|
|
|
1276
1285
|
info_line("Exiting DataSecOps Framework CLI")
|
|
1277
1286
|
|
|
1278
1287
|
|
|
1288
|
+
def _configure_dcm(config: Config) -> None:
|
|
1289
|
+
"""Prompt for the dcm_* settings, enable DCM and persist to .datasecops.yml."""
|
|
1290
|
+
ds = config.datasecops
|
|
1291
|
+
section_header("Configure DCM")
|
|
1292
|
+
info_line("DCM is not yet enabled for this project. Enter the settings below "
|
|
1293
|
+
"(press Enter to keep the default).")
|
|
1294
|
+
info_line("")
|
|
1295
|
+
|
|
1296
|
+
ds.dcm_model_path = get_input_string_or_default("DCM model file", ds.dcm_model_path)
|
|
1297
|
+
ds.dcm_root = get_input_string_or_default("DCM project root (project dirs are relative to this)", ds.dcm_root)
|
|
1298
|
+
ds.dcm_security_dir = get_input_string_or_default("Legacy security project dir", ds.dcm_security_dir)
|
|
1299
|
+
ds.dcm_platform_dir = get_input_string_or_default("Legacy platform project dir", ds.dcm_platform_dir)
|
|
1300
|
+
ds.dcm_default_target = get_input_string_or_default("Default DCM target (blank for none)", ds.dcm_default_target)
|
|
1301
|
+
ds.dcm_enabled = True
|
|
1302
|
+
|
|
1303
|
+
write_datasecops_config(config.project_dir, ds.model_dump(exclude={"VALID_ENGINES"}))
|
|
1304
|
+
success_line("DCM enabled - .datasecops.yml updated.")
|
|
1305
|
+
|
|
1306
|
+
|
|
1279
1307
|
def _show_main_menu(profile_name: str, git_service: GitService = None,
|
|
1280
1308
|
upstream_statuses: list = None, dcm_enabled: bool = False):
|
|
1281
1309
|
clear()
|
|
@@ -1290,6 +1318,8 @@ def _show_main_menu(profile_name: str, git_service: GitService = None,
|
|
|
1290
1318
|
menu_option(6, "bootstrap - Set up a new dbt project with all framework config")
|
|
1291
1319
|
if dcm_enabled:
|
|
1292
1320
|
menu_option(7, "dcm - DCM Infrastructure Operations")
|
|
1321
|
+
else:
|
|
1322
|
+
menu_option(7, "dcm - Configure & enable DCM")
|
|
1293
1323
|
if upstream_statuses and any(s.needs_update for s in upstream_statuses):
|
|
1294
1324
|
menu_option(8, "update pkgs - Update upstream packages to latest versions")
|
|
1295
1325
|
menu_option(0, "exit - Exit")
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
"""Generate dbt_project.yml matching the DataSecOps Framework skill specification."""
|
|
2
2
|
|
|
3
|
+
import contextlib
|
|
4
|
+
import os
|
|
3
5
|
import re
|
|
6
|
+
import stat
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
4
9
|
import yaml
|
|
5
10
|
from typing import Any
|
|
6
11
|
|
|
12
|
+
if sys.platform == "win32":
|
|
13
|
+
import msvcrt
|
|
14
|
+
else:
|
|
15
|
+
import fcntl
|
|
16
|
+
|
|
7
17
|
from datasecops_cli.models.project_config import ProjectProfile, ProjectSettings
|
|
8
18
|
|
|
9
19
|
|
|
@@ -244,18 +254,39 @@ def generate_local_dev_target(
|
|
|
244
254
|
|
|
245
255
|
|
|
246
256
|
def _to_plain(value: Any) -> Any:
|
|
247
|
-
"""Recursively strip non-standard object types (e.g. tomlkit's str/int/bool
|
|
248
|
-
down to plain dict/list/str/int/float/bool/None, so the result is always
|
|
249
|
-
`yaml.safe_load()` back after a `yaml.dump()` round-trip.
|
|
257
|
+
"""Recursively strip non-standard object types (e.g. tomlkit's str/int/float/bool
|
|
258
|
+
subclasses) down to plain dict/list/str/int/float/bool/None, so the result is always
|
|
259
|
+
safe to `yaml.safe_load()` back after a `yaml.dump()` round-trip.
|
|
260
|
+
|
|
261
|
+
Each primitive is coerced with its own constructor (`bool(value)`, `int(value)`, etc.)
|
|
262
|
+
rather than returned as-is: `isinstance(value, int)` is true for a `tomlkit.items.Integer`
|
|
263
|
+
too, but the object itself is still that subclass, which `yaml.dump()` would still tag as
|
|
264
|
+
a Python object. `bool` is checked before `int`/`float` since `bool` is itself an `int`
|
|
265
|
+
subclass in Python. `bytes` (from a safe `!!binary` value, unrelated to tomlkit) is passed
|
|
266
|
+
through as-is rather than stringified, so an existing binary value in an untouched profile
|
|
267
|
+
isn't corrupted into its `b'...'` text representation. Any other (e.g. tomlkit's compound
|
|
268
|
+
Array/InlineTable/DateTime) type is unwrapped via its own `.unwrap()` if available,
|
|
269
|
+
falling back to a plain string.
|
|
270
|
+
"""
|
|
250
271
|
if isinstance(value, dict):
|
|
251
272
|
return {k: _to_plain(v) for k, v in value.items()}
|
|
252
273
|
if isinstance(value, list):
|
|
253
274
|
return [_to_plain(v) for v in value]
|
|
254
|
-
if
|
|
255
|
-
return
|
|
275
|
+
if value is None:
|
|
276
|
+
return None
|
|
277
|
+
if isinstance(value, bool):
|
|
278
|
+
return bool(value)
|
|
279
|
+
if isinstance(value, int):
|
|
280
|
+
return int(value)
|
|
281
|
+
if isinstance(value, float):
|
|
282
|
+
return float(value)
|
|
283
|
+
if isinstance(value, bytes):
|
|
284
|
+
return bytes(value)
|
|
256
285
|
if isinstance(value, str):
|
|
257
286
|
return str(value)
|
|
258
|
-
|
|
287
|
+
if hasattr(value, "unwrap"):
|
|
288
|
+
return _to_plain(value.unwrap())
|
|
289
|
+
return str(value)
|
|
259
290
|
|
|
260
291
|
|
|
261
292
|
class _LegacyTomlkitSafeLoader(yaml.SafeLoader):
|
|
@@ -270,22 +301,29 @@ class _LegacyTomlkitSafeLoader(yaml.SafeLoader):
|
|
|
270
301
|
"""
|
|
271
302
|
|
|
272
303
|
|
|
273
|
-
def
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
304
|
+
def _construct_legacy_tomlkit_value(value_index: int):
|
|
305
|
+
"""Build a constructor that picks tomlkit's plain value out of its apply-sequence by
|
|
306
|
+
position, for the given tomlkit item type's `__new__(cls, ...)` argument order:
|
|
307
|
+
`String(t, value, original, trivia)` -> value is arg 1; `Integer(value, trivia, raw)`,
|
|
308
|
+
`Float(value, trivia, raw)` and `Bool(value, trivia)` -> value is arg 0. The rest of each
|
|
309
|
+
sequence (StringType/Trivia tags) is tomlkit-internal bookkeeping we deliberately never
|
|
310
|
+
construct. `construct_object` (not `construct_scalar`) is used so the value's own tag
|
|
311
|
+
(str/int/float/bool, auto-resolved by the safe resolver) still picks the right
|
|
312
|
+
already-safe constructor, instead of collapsing everything to a string.
|
|
313
|
+
"""
|
|
314
|
+
def _construct(loader: yaml.SafeLoader, node: yaml.Node) -> Any:
|
|
315
|
+
if not isinstance(node, yaml.SequenceNode) or len(node.value) <= value_index:
|
|
316
|
+
raise yaml.constructor.ConstructorError(
|
|
317
|
+
None, None, "unexpected legacy tomlkit value structure", node.start_mark)
|
|
318
|
+
return loader.construct_object(node.value[value_index], deep=True)
|
|
319
|
+
return _construct
|
|
283
320
|
|
|
284
321
|
|
|
285
|
-
|
|
322
|
+
_LEGACY_TOMLKIT_VALUE_INDEX = {"String": 1, "Integer": 0, "Float": 0, "Bool": 0}
|
|
323
|
+
for _tomlkit_type, _value_index in _LEGACY_TOMLKIT_VALUE_INDEX.items():
|
|
286
324
|
_LegacyTomlkitSafeLoader.add_constructor(
|
|
287
325
|
f"tag:yaml.org,2002:python/object/apply:tomlkit.items.{_tomlkit_type}",
|
|
288
|
-
|
|
326
|
+
_construct_legacy_tomlkit_value(_value_index),
|
|
289
327
|
)
|
|
290
328
|
|
|
291
329
|
|
|
@@ -302,6 +340,48 @@ def _load_profiles_yml_text(text: str) -> dict[str, Any]:
|
|
|
302
340
|
return _to_plain(yaml.load(text, Loader=_LegacyTomlkitSafeLoader) or {})
|
|
303
341
|
|
|
304
342
|
|
|
343
|
+
@contextlib.contextmanager
|
|
344
|
+
def _locked_profiles_file(profiles_path, timeout: float = 10.0):
|
|
345
|
+
"""OS-level advisory lock for profiles.yml's read-modify-write, so two concurrent
|
|
346
|
+
`setup`/`bootstrap` runs against the same file (e.g. two profiles sharing it, or two
|
|
347
|
+
terminals) don't read the same version and have the later write silently discard the
|
|
348
|
+
earlier one.
|
|
349
|
+
|
|
350
|
+
Holds `fcntl.flock` (POSIX) / `msvcrt.locking` (Windows) on a sibling `<profiles.yml>.lock`
|
|
351
|
+
file for the duration of the context - stdlib only, no extra dependency. Unlike a
|
|
352
|
+
marker-file-existence lock, this needs no "is it stale?" heuristic at all: the OS releases
|
|
353
|
+
the lock automatically if the holding process dies or its file descriptor is closed, so
|
|
354
|
+
there's no window for one waiter to mistake another's live lock for an abandoned one and
|
|
355
|
+
delete it out from under it. Raises `TimeoutError` rather than silently proceeding without
|
|
356
|
+
the lock if it can't be acquired in time.
|
|
357
|
+
"""
|
|
358
|
+
lock_path = profiles_path.with_name(profiles_path.name + ".lock")
|
|
359
|
+
lock_file = open(lock_path, "a+")
|
|
360
|
+
try:
|
|
361
|
+
deadline = time.time() + timeout
|
|
362
|
+
while True:
|
|
363
|
+
try:
|
|
364
|
+
if sys.platform == "win32":
|
|
365
|
+
msvcrt.locking(lock_file.fileno(), msvcrt.LK_NBLCK, 1)
|
|
366
|
+
else:
|
|
367
|
+
fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
368
|
+
break
|
|
369
|
+
except OSError:
|
|
370
|
+
if time.time() >= deadline:
|
|
371
|
+
raise TimeoutError(f"timed out waiting for lock on {lock_path}") from None
|
|
372
|
+
time.sleep(0.05)
|
|
373
|
+
try:
|
|
374
|
+
yield
|
|
375
|
+
finally:
|
|
376
|
+
if sys.platform == "win32":
|
|
377
|
+
lock_file.seek(0)
|
|
378
|
+
msvcrt.locking(lock_file.fileno(), msvcrt.LK_UNLCK, 1)
|
|
379
|
+
else:
|
|
380
|
+
fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)
|
|
381
|
+
finally:
|
|
382
|
+
lock_file.close()
|
|
383
|
+
|
|
384
|
+
|
|
305
385
|
def write_profiles_yml(
|
|
306
386
|
profiles_dir,
|
|
307
387
|
profile_name: str,
|
|
@@ -324,35 +404,60 @@ def write_profiles_yml(
|
|
|
324
404
|
"""
|
|
325
405
|
from pathlib import Path
|
|
326
406
|
|
|
407
|
+
# Resolved (symlinks included) so two paths that alias the same directory - e.g. a
|
|
408
|
+
# symlink and its target - always derive the same profiles.yml *and* the same lock
|
|
409
|
+
# file, instead of a concurrent writer through the other alias bypassing the lock.
|
|
410
|
+
# profiles.yml itself is resolved too: if it's a symlink, os.replace() must swap out
|
|
411
|
+
# its target, not the link, or the real file (and any writer reaching it directly)
|
|
412
|
+
# would be left out of sync.
|
|
327
413
|
profiles_dir = Path(profiles_dir).expanduser()
|
|
328
|
-
profiles_path = profiles_dir / "profiles.yml"
|
|
329
|
-
|
|
330
|
-
existing_profiles: dict[str, Any] = {}
|
|
331
|
-
if profiles_path.exists():
|
|
332
|
-
existing_profiles = _load_profiles_yml_text(profiles_path.read_text(encoding="utf-8"))
|
|
333
|
-
|
|
334
|
-
local_dev_output = generate_local_dev_target(profile, project_settings, connection_params, sandpit_name)
|
|
335
|
-
|
|
336
|
-
if profile_name in existing_profiles:
|
|
337
|
-
entry = existing_profiles[profile_name]
|
|
338
|
-
entry.setdefault("outputs", {})
|
|
339
|
-
entry["outputs"]["local-dev"] = local_dev_output
|
|
340
|
-
# Always force the default target to local-dev: a bare `dbt run` with no --target
|
|
341
|
-
# must use the developer's own identity, never a deployment target that happened
|
|
342
|
-
# to be marked as the file's default (e.g. by a previous run or manual edit).
|
|
343
|
-
entry["target"] = "local-dev"
|
|
344
|
-
status = "updated"
|
|
345
|
-
else:
|
|
346
|
-
existing_profiles[profile_name] = {
|
|
347
|
-
"target": "local-dev",
|
|
348
|
-
"outputs": {"local-dev": local_dev_output},
|
|
349
|
-
}
|
|
350
|
-
status = "added"
|
|
351
|
-
|
|
352
414
|
profiles_dir.mkdir(parents=True, exist_ok=True)
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
415
|
+
profiles_dir = profiles_dir.resolve()
|
|
416
|
+
profiles_path = (profiles_dir / "profiles.yml").resolve()
|
|
417
|
+
|
|
418
|
+
with _locked_profiles_file(profiles_path):
|
|
419
|
+
existing_profiles: dict[str, Any] = {}
|
|
420
|
+
if profiles_path.exists():
|
|
421
|
+
existing_profiles = _load_profiles_yml_text(profiles_path.read_text(encoding="utf-8"))
|
|
422
|
+
|
|
423
|
+
local_dev_output = generate_local_dev_target(profile, project_settings, connection_params, sandpit_name)
|
|
424
|
+
|
|
425
|
+
if profile_name in existing_profiles:
|
|
426
|
+
entry = existing_profiles[profile_name]
|
|
427
|
+
entry.setdefault("outputs", {})
|
|
428
|
+
entry["outputs"]["local-dev"] = local_dev_output
|
|
429
|
+
# Always force the default target to local-dev: a bare `dbt run` with no --target
|
|
430
|
+
# must use the developer's own identity, never a deployment target that happened
|
|
431
|
+
# to be marked as the file's default (e.g. by a previous run or manual edit).
|
|
432
|
+
entry["target"] = "local-dev"
|
|
433
|
+
status = "updated"
|
|
434
|
+
else:
|
|
435
|
+
existing_profiles[profile_name] = {
|
|
436
|
+
"target": "local-dev",
|
|
437
|
+
"outputs": {"local-dev": local_dev_output},
|
|
438
|
+
}
|
|
439
|
+
status = "added"
|
|
440
|
+
|
|
441
|
+
# Written to a temp file in the same directory and atomically swapped into place,
|
|
442
|
+
# so a crash or I/O error mid-write can never leave profiles.yml half-written, and a
|
|
443
|
+
# concurrent reader (e.g. dbt itself) never observes a partially-written file.
|
|
444
|
+
# Created with restrictive (0600) permissions and, if profiles.yml already existed,
|
|
445
|
+
# its mode is reapplied before the swap - otherwise the temp file would inherit the
|
|
446
|
+
# umask (typically 0644) and widen access to the credentials it contains.
|
|
447
|
+
new_content = yaml.dump(existing_profiles, default_flow_style=False, sort_keys=False)
|
|
448
|
+
existing_mode = stat.S_IMODE(profiles_path.stat().st_mode) if profiles_path.exists() else None
|
|
449
|
+
tmp_path = profiles_path.with_name(f".{profiles_path.name}.{os.getpid()}.tmp")
|
|
450
|
+
fd = os.open(tmp_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
|
451
|
+
try:
|
|
452
|
+
with os.fdopen(fd, "w", encoding="utf-8") as tmp_file:
|
|
453
|
+
tmp_file.write(new_content)
|
|
454
|
+
except BaseException:
|
|
455
|
+
tmp_path.unlink(missing_ok=True)
|
|
456
|
+
raise
|
|
457
|
+
if existing_mode is not None:
|
|
458
|
+
os.chmod(tmp_path, existing_mode)
|
|
459
|
+
os.replace(tmp_path, profiles_path)
|
|
460
|
+
return status
|
|
356
461
|
|
|
357
462
|
|
|
358
463
|
def generate_packages_yml(
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/download_service.py
RENAMED
|
@@ -331,9 +331,14 @@ class DownloadService:
|
|
|
331
331
|
# sandpit database - deployment targets belong to the native app's CI pipeline.
|
|
332
332
|
connection_params = get_connection_params(self.sf.config.connection_name)
|
|
333
333
|
profiles_dir = Path(project_settings.profile_dir).expanduser()
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
try:
|
|
335
|
+
status = write_profiles_yml(
|
|
336
|
+
profiles_dir, profile.profile_name, profile, project_settings,
|
|
337
|
+
connection_params, self.sf.config.sandpit_name)
|
|
338
|
+
except TimeoutError as e:
|
|
339
|
+
error_line(f"Could not write profiles.yml: {e}")
|
|
340
|
+
error_line("Another datasecops process may be writing the same profiles.yml - try again")
|
|
341
|
+
return False
|
|
337
342
|
success_line(f"profiles.yml {status} in {profiles_dir}")
|
|
338
343
|
|
|
339
344
|
# Generate .gitignore
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/tests/test_dbt_project_generator_profiles.py
RENAMED
|
@@ -119,6 +119,78 @@ def test_load_profiles_yml_text_rejects_unknown_object_tags():
|
|
|
119
119
|
_load_profiles_yml_text(malicious)
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
def test_load_profiles_yml_text_repairs_legacy_tomlkit_integer_float_bool():
|
|
123
|
+
"""Integer/Float/Bool put their plain value at a different position in their
|
|
124
|
+
apply-sequence than String does - this exercises each one end-to-end through the real
|
|
125
|
+
loader (not just _to_plain) to make sure the right argument is actually picked out."""
|
|
126
|
+
import tomlkit
|
|
127
|
+
from datasecops_cli.services.dbt_project_generator import _load_profiles_yml_text
|
|
128
|
+
|
|
129
|
+
corrupted = {
|
|
130
|
+
"threads": tomlkit.integer(8),
|
|
131
|
+
"query_timeout": tomlkit.item(1.5),
|
|
132
|
+
"client_session_keep_alive": tomlkit.boolean(True),
|
|
133
|
+
}
|
|
134
|
+
text = yaml.dump(corrupted, default_flow_style=False, sort_keys=False)
|
|
135
|
+
|
|
136
|
+
with pytest.raises(yaml.YAMLError):
|
|
137
|
+
yaml.safe_load(text)
|
|
138
|
+
|
|
139
|
+
repaired = _load_profiles_yml_text(text)
|
|
140
|
+
assert repaired == {"threads": 8, "query_timeout": 1.5, "client_session_keep_alive": True}
|
|
141
|
+
assert type(repaired["threads"]) is int
|
|
142
|
+
assert type(repaired["query_timeout"]) is float
|
|
143
|
+
assert type(repaired["client_session_keep_alive"]) is bool
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_to_plain_fully_strips_tomlkit_numeric_subclasses():
|
|
147
|
+
"""A tomlkit Integer/Bool is still `isinstance(x, int)`/`isinstance(x, bool)`, but the
|
|
148
|
+
object itself is still that subclass - yaml.dump() would still tag it as a Python object
|
|
149
|
+
unless it's coerced to the real builtin type, not just returned as-is."""
|
|
150
|
+
import tomlkit
|
|
151
|
+
from datasecops_cli.services.dbt_project_generator import _to_plain
|
|
152
|
+
|
|
153
|
+
threads = tomlkit.integer(8)
|
|
154
|
+
keep_alive = tomlkit.boolean(True)
|
|
155
|
+
plain = _to_plain({"threads": threads, "keep_alive": keep_alive})
|
|
156
|
+
|
|
157
|
+
assert type(plain["threads"]) is int
|
|
158
|
+
assert type(plain["keep_alive"]) is bool
|
|
159
|
+
# And the round-trip that matters: yaml.dump() no longer tags these as Python objects.
|
|
160
|
+
dumped = yaml.dump(plain)
|
|
161
|
+
assert "python/object" not in dumped
|
|
162
|
+
assert yaml.safe_load(dumped) == {"threads": 8, "keep_alive": True}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_to_plain_preserves_bytes():
|
|
166
|
+
"""A safe `!!binary` value loads as `bytes` - unrelated to the tomlkit corruption this
|
|
167
|
+
whole repair path targets, but still passing through _to_plain() if it sits in the same
|
|
168
|
+
file. It must come back as bytes, not get stringified into its b'...' repr."""
|
|
169
|
+
from datasecops_cli.services.dbt_project_generator import _to_plain
|
|
170
|
+
|
|
171
|
+
raw = b"\x00\x01\xff"
|
|
172
|
+
assert _to_plain({"secret": raw}) == {"secret": raw}
|
|
173
|
+
assert type(_to_plain(raw)) is bytes
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_write_profiles_yml_resolves_symlinked_profiles_dir(tmp_path):
|
|
177
|
+
"""Two paths that alias the same directory (e.g. a symlink and its target) must derive
|
|
178
|
+
the same profiles.yml *and* lock file, or a writer through one alias could bypass a
|
|
179
|
+
concurrent writer's lock through the other."""
|
|
180
|
+
real_dir = tmp_path / "real"
|
|
181
|
+
real_dir.mkdir()
|
|
182
|
+
link_dir = tmp_path / "link"
|
|
183
|
+
try:
|
|
184
|
+
link_dir.symlink_to(real_dir, target_is_directory=True)
|
|
185
|
+
except OSError:
|
|
186
|
+
pytest.skip("symlink creation not permitted in this environment")
|
|
187
|
+
|
|
188
|
+
write_profiles_yml(link_dir, "anzco_sds", _profile(), _project_settings(), {"account": "acct"}, "jon")
|
|
189
|
+
|
|
190
|
+
assert (real_dir / "profiles.yml").exists()
|
|
191
|
+
assert (real_dir / "profiles.yml.lock").exists() # flock's sibling lock file lives under the resolved dir
|
|
192
|
+
|
|
193
|
+
|
|
122
194
|
def test_write_profiles_yml_creates_folder_and_file(tmp_path):
|
|
123
195
|
profiles_dir = tmp_path / ".dbt"
|
|
124
196
|
assert not profiles_dir.exists()
|
|
@@ -199,3 +271,72 @@ def test_write_profiles_yml_adds_new_profile_without_disturbing_others(tmp_path)
|
|
|
199
271
|
assert "other_profile" in data
|
|
200
272
|
assert "anzco_sds" in data
|
|
201
273
|
assert data["anzco_sds"]["outputs"]["local-dev"]["database"] == "SDS_SANDPIT_JON"
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def test_write_profiles_yml_waits_out_a_concurrent_lock(tmp_path):
|
|
277
|
+
"""Two concurrent writers must not race a read-modify-write and silently drop one of
|
|
278
|
+
their updates: a second writer blocks on the first's OS lock until it releases."""
|
|
279
|
+
import threading
|
|
280
|
+
from datasecops_cli.services.dbt_project_generator import _locked_profiles_file
|
|
281
|
+
|
|
282
|
+
profiles_dir = tmp_path / ".dbt"
|
|
283
|
+
profiles_dir.mkdir(parents=True)
|
|
284
|
+
profiles_path = profiles_dir / "profiles.yml"
|
|
285
|
+
|
|
286
|
+
holder_ready = threading.Event()
|
|
287
|
+
release_holder = threading.Event()
|
|
288
|
+
|
|
289
|
+
def _hold_lock():
|
|
290
|
+
with _locked_profiles_file(profiles_path, timeout=5.0):
|
|
291
|
+
holder_ready.set()
|
|
292
|
+
release_holder.wait(timeout=5)
|
|
293
|
+
|
|
294
|
+
holder = threading.Thread(target=_hold_lock)
|
|
295
|
+
holder.start()
|
|
296
|
+
assert holder_ready.wait(timeout=5)
|
|
297
|
+
|
|
298
|
+
result = {}
|
|
299
|
+
|
|
300
|
+
def _write():
|
|
301
|
+
result["status"] = write_profiles_yml(
|
|
302
|
+
profiles_dir, "anzco_sds", _profile(), _project_settings(), {"account": "acct"}, "jon")
|
|
303
|
+
|
|
304
|
+
writer = threading.Thread(target=_write)
|
|
305
|
+
writer.start()
|
|
306
|
+
writer.join(timeout=0.3)
|
|
307
|
+
assert writer.is_alive() # still waiting on the holder's lock
|
|
308
|
+
|
|
309
|
+
release_holder.set() # the holder releases, like another writer finishing
|
|
310
|
+
holder.join(timeout=5)
|
|
311
|
+
writer.join(timeout=5)
|
|
312
|
+
assert not writer.is_alive()
|
|
313
|
+
assert result["status"] == "added"
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def test_locked_profiles_file_raises_timeout_error_rather_than_proceeding_unlocked(tmp_path):
|
|
317
|
+
"""If the lock genuinely can't be acquired in time, the caller must be told - silently
|
|
318
|
+
entering the critical section unlocked would reintroduce the exact race the lock exists
|
|
319
|
+
to prevent."""
|
|
320
|
+
import threading
|
|
321
|
+
from datasecops_cli.services.dbt_project_generator import _locked_profiles_file
|
|
322
|
+
|
|
323
|
+
profiles_path = tmp_path / "profiles.yml"
|
|
324
|
+
holder_ready = threading.Event()
|
|
325
|
+
release_holder = threading.Event()
|
|
326
|
+
|
|
327
|
+
def _hold_lock():
|
|
328
|
+
with _locked_profiles_file(profiles_path, timeout=5.0):
|
|
329
|
+
holder_ready.set()
|
|
330
|
+
release_holder.wait(timeout=5)
|
|
331
|
+
|
|
332
|
+
holder = threading.Thread(target=_hold_lock)
|
|
333
|
+
holder.start()
|
|
334
|
+
assert holder_ready.wait(timeout=5)
|
|
335
|
+
try:
|
|
336
|
+
with pytest.raises(TimeoutError):
|
|
337
|
+
with _locked_profiles_file(profiles_path, timeout=0.2):
|
|
338
|
+
pass # must never be reached
|
|
339
|
+
finally:
|
|
340
|
+
release_holder.set()
|
|
341
|
+
holder.join(timeout=5)
|
|
342
|
+
|
|
@@ -5,9 +5,9 @@ from pathlib import Path
|
|
|
5
5
|
|
|
6
6
|
from click.testing import CliRunner
|
|
7
7
|
|
|
8
|
-
from datasecops_cli.main import cli, _run_download, DOWNLOAD_ITEMS
|
|
8
|
+
from datasecops_cli.main import cli, _run_download, _configure_dcm, DOWNLOAD_ITEMS
|
|
9
9
|
from datasecops_cli.config import Config
|
|
10
|
-
from datasecops_cli.models.project_config import DbtTarget, ProjectProfile
|
|
10
|
+
from datasecops_cli.models.project_config import DatasecopsConfig, DbtTarget, ProjectProfile
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class TestCliParsing:
|
|
@@ -547,3 +547,58 @@ class TestPipelineEnvCommand:
|
|
|
547
547
|
result, _ = self._invoke(["--target", "prd", "--format", "shell", "--connection", "ci"])
|
|
548
548
|
assert result.exit_code == 0, result.output
|
|
549
549
|
self.config.load.assert_called_once_with(connection_name="ci")
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
class TestConfigureDcm:
|
|
553
|
+
"""Tests for the interactive _configure_dcm() helper."""
|
|
554
|
+
|
|
555
|
+
def _config(self, tmp_path):
|
|
556
|
+
config = Config.__new__(Config)
|
|
557
|
+
config.project_dir = tmp_path
|
|
558
|
+
config.datasecops = DatasecopsConfig()
|
|
559
|
+
return config
|
|
560
|
+
|
|
561
|
+
def test_enables_dcm_and_writes_entered_values(self, tmp_path):
|
|
562
|
+
config = self._config(tmp_path)
|
|
563
|
+
answers = iter([
|
|
564
|
+
"config/custom_model.json",
|
|
565
|
+
"dcm",
|
|
566
|
+
"sec",
|
|
567
|
+
"plat",
|
|
568
|
+
"DEV",
|
|
569
|
+
])
|
|
570
|
+
with patch("datasecops_cli.main.get_input_string_or_default",
|
|
571
|
+
side_effect=lambda _msg, _default: next(answers)) as mock_input, \
|
|
572
|
+
patch("datasecops_cli.main.write_datasecops_config") as mock_write:
|
|
573
|
+
_configure_dcm(config)
|
|
574
|
+
|
|
575
|
+
assert mock_input.call_count == 5
|
|
576
|
+
assert config.datasecops.dcm_enabled is True
|
|
577
|
+
assert config.datasecops.dcm_model_path == "config/custom_model.json"
|
|
578
|
+
assert config.datasecops.dcm_root == "dcm"
|
|
579
|
+
assert config.datasecops.dcm_security_dir == "sec"
|
|
580
|
+
assert config.datasecops.dcm_platform_dir == "plat"
|
|
581
|
+
assert config.datasecops.dcm_default_target == "DEV"
|
|
582
|
+
|
|
583
|
+
mock_write.assert_called_once()
|
|
584
|
+
written_dir, written_data = mock_write.call_args[0]
|
|
585
|
+
assert written_dir == tmp_path
|
|
586
|
+
assert written_data["dcm_enabled"] is True
|
|
587
|
+
assert written_data["dcm_model_path"] == "config/custom_model.json"
|
|
588
|
+
assert written_data["dcm_root"] == "dcm"
|
|
589
|
+
assert written_data["dcm_security_dir"] == "sec"
|
|
590
|
+
assert written_data["dcm_platform_dir"] == "plat"
|
|
591
|
+
assert written_data["dcm_default_target"] == "DEV"
|
|
592
|
+
assert "VALID_ENGINES" not in written_data
|
|
593
|
+
|
|
594
|
+
def test_keeps_defaults_when_user_accepts_them(self, tmp_path):
|
|
595
|
+
config = self._config(tmp_path)
|
|
596
|
+
with patch("datasecops_cli.main.get_input_string_or_default",
|
|
597
|
+
side_effect=lambda _msg, default: default), \
|
|
598
|
+
patch("datasecops_cli.main.write_datasecops_config") as mock_write:
|
|
599
|
+
_configure_dcm(config)
|
|
600
|
+
|
|
601
|
+
assert config.datasecops.dcm_enabled is True
|
|
602
|
+
assert config.datasecops.dcm_model_path == "config/dcm_model.json"
|
|
603
|
+
assert config.datasecops.dcm_root == "."
|
|
604
|
+
mock_write.assert_called_once()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.7.0b6"
|
|
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.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/dcm_operations.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/menus/git_operations.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/models/project_config.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/bootstrap_service.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_orchestrator.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_pipelines.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_registry.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/dcm_service.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/git_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/linting_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/model_commands.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/pipeline_env.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/skill_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/snowflake_service.py
RENAMED
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/services/upstream_service.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/src/datasecops_cli/utilities/file_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
{datasecops_cli-0.7.0b6 → datasecops_cli-0.7.0b7}/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.0b6 → datasecops_cli-0.7.0b7}/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
|
|
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
|