datasecops-cli 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,62 @@
1
+ import json
2
+ from typing import Any, Optional
3
+ import snowflake.connector
4
+
5
+ from datasecops_cli.models.project_config import DatasecopsConfig
6
+
7
+
8
+ class SnowflakeService:
9
+ """Connects to Snowflake and calls native app API procedures."""
10
+
11
+ def __init__(self, config: DatasecopsConfig):
12
+ self.config = config
13
+ self._conn: Optional[snowflake.connector.SnowflakeConnection] = None
14
+
15
+ def connect(self) -> None:
16
+ self._conn = snowflake.connector.connect(
17
+ connection_name=self.config.connection_name,
18
+ )
19
+
20
+ def close(self) -> None:
21
+ if self._conn:
22
+ self._conn.close()
23
+ self._conn = None
24
+
25
+ @property
26
+ def conn(self) -> snowflake.connector.SnowflakeConnection:
27
+ if self._conn is None:
28
+ self.connect()
29
+ return self._conn
30
+
31
+ def execute_query(self, sql: str, params: list = None) -> list[dict]:
32
+ cur = self.conn.cursor(snowflake.connector.DictCursor)
33
+ try:
34
+ cur.execute(sql, params or [])
35
+ return cur.fetchall()
36
+ finally:
37
+ cur.close()
38
+
39
+ def call_procedure(self, proc_name: str, *args) -> Any:
40
+ db = self.config.app_database
41
+ arg_placeholders = ", ".join(["%s"] * len(args))
42
+ sql = f"CALL {db}.api.{proc_name}({arg_placeholders})"
43
+ rows = self.execute_query(sql, list(args))
44
+ if rows:
45
+ first_val = list(rows[0].values())[0]
46
+ if isinstance(first_val, str):
47
+ try:
48
+ return json.loads(first_val)
49
+ except (json.JSONDecodeError, TypeError):
50
+ return first_val
51
+ return first_val
52
+ return None
53
+
54
+ def get_framework_config(self, config_code: str) -> Optional[dict]:
55
+ return self.call_procedure("get_framework_config", config_code)
56
+
57
+ def get_project_profiles(self) -> Optional[list[dict]]:
58
+ return self.call_procedure("get_project_profiles")
59
+
60
+ def get_account_info(self) -> dict:
61
+ rows = self.execute_query("SELECT CURRENT_ACCOUNT_NAME() as account, CURRENT_USER() as user_name")
62
+ return rows[0] if rows else {}
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,122 @@
1
+ import os
2
+ from colorama import init, Fore, Style
3
+
4
+ init(autoreset=True)
5
+
6
+
7
+ def clear():
8
+ os.system('cls' if os.name == 'nt' else 'clear')
9
+
10
+
11
+ def print_detail(message: str, color: str = Fore.WHITE) -> None:
12
+ print(Style.NORMAL + color + message)
13
+
14
+
15
+ def print_long_line(color: str = Fore.GREEN) -> None:
16
+ print_detail("=" * 76, color)
17
+
18
+
19
+ def section_header(message: str, active_profile: str = None, current_branch: str = None) -> None:
20
+ print_long_line(Fore.GREEN)
21
+ print_detail(message, Fore.GREEN)
22
+ print_long_line(Fore.GREEN)
23
+ if active_profile:
24
+ print_detail(f" Profile: {active_profile}", Fore.GREEN)
25
+ if current_branch:
26
+ print_detail(f" Branch: {current_branch}", Fore.GREEN)
27
+ if active_profile or current_branch:
28
+ print_long_line(Fore.GREEN)
29
+
30
+
31
+ def display_action_header(message: str) -> None:
32
+ clear()
33
+ print_long_line(Fore.GREEN)
34
+ print_detail(f" {message}", Fore.GREEN)
35
+ print_long_line(Fore.GREEN)
36
+
37
+
38
+ def menu_option(number: int, text: str) -> None:
39
+ print_detail(f" [{number}] {text}", Fore.WHITE)
40
+
41
+
42
+ def info_line(message: str) -> None:
43
+ print_detail(message, Fore.BLUE)
44
+
45
+
46
+ def warning_line(message: str) -> None:
47
+ print_detail(f"WARNING: {message}", Fore.YELLOW)
48
+
49
+
50
+ def error_line(message: str) -> None:
51
+ print_detail(f"ERROR: {message}", Fore.RED)
52
+
53
+
54
+ def success_line(message: str) -> None:
55
+ print_detail(message, Fore.GREEN)
56
+
57
+
58
+ def complete_action(message: str = None) -> None:
59
+ print_long_line()
60
+ input(message or "Press Enter to continue...")
61
+
62
+
63
+ def get_input_string(message: str, allow_empty: bool = False) -> str:
64
+ while True:
65
+ result = input(message)
66
+ if result.strip() or allow_empty:
67
+ return result.strip()
68
+
69
+
70
+ def get_input_number(message: str) -> int:
71
+ while True:
72
+ result = input(message).strip()
73
+ if result.isdigit() or (result.startswith('-') and result[1:].isdigit()):
74
+ return int(result)
75
+ if not result:
76
+ return 0
77
+
78
+
79
+ def get_input_true_false(message: str, default: str = "n") -> bool:
80
+ while True:
81
+ result = input(f"{message} (y/n, default: {default}): ").strip().lower()
82
+ if not result:
83
+ result = default
84
+ if result in ("y", "n"):
85
+ return result == "y"
86
+
87
+
88
+ def get_input_string_or_default(message: str, default_value: str) -> str:
89
+ result = input(f"{message} (default: '{default_value}'): ").strip()
90
+ return result if result else default_value
91
+
92
+
93
+ def select_from_dict(options: dict[str, str], select_name: str, add_back: bool = True) -> str:
94
+ """Numbered selection from a dict. Returns the selected value. '0' returns 'back'."""
95
+ items = list(options.items())
96
+ if add_back and "back" not in options:
97
+ items.append(("back", "back"))
98
+
99
+ for idx, (key, _) in enumerate(items):
100
+ if key == "back":
101
+ print_detail(f" [0] {key}", Fore.WHITE)
102
+ else:
103
+ print_detail(f" [{idx + 1}] {key}", Fore.WHITE)
104
+
105
+ while True:
106
+ raw = get_input_string(f"Select {select_name}: ")
107
+ if raw == "0":
108
+ return "back"
109
+ try:
110
+ num = int(raw) - 1
111
+ if 0 <= num < len(items) and items[num][0] != "back":
112
+ info_line(f"Selected {select_name}: {items[num][0]}")
113
+ return items[num][1]
114
+ except ValueError:
115
+ pass
116
+ warning_line(f"Please select a valid {select_name} number")
117
+
118
+
119
+ def select_from_list(options: list[str], select_name: str, add_back: bool = True) -> str:
120
+ """Numbered selection from a list. Returns the selected value."""
121
+ d = {opt: opt for opt in options}
122
+ return select_from_dict(d, select_name, add_back)
@@ -0,0 +1,33 @@
1
+ from pathlib import Path
2
+
3
+
4
+ def ensure_dir(path: Path) -> Path:
5
+ path.mkdir(parents=True, exist_ok=True)
6
+ return path
7
+
8
+
9
+ def read_file(path: Path) -> str:
10
+ if path.exists():
11
+ return path.read_text(encoding="utf-8")
12
+ return ""
13
+
14
+
15
+ def write_file(path: Path, content: str) -> None:
16
+ ensure_dir(path.parent)
17
+ path.write_text(content, encoding="utf-8")
18
+
19
+
20
+ def file_exists(path: Path) -> bool:
21
+ return path.exists() and path.is_file()
22
+
23
+
24
+ def find_files(root: Path, pattern: str) -> list[Path]:
25
+ return sorted(root.rglob(pattern))
26
+
27
+
28
+ def get_dbt_profiles_dir() -> Path:
29
+ return Path.home() / ".dbt"
30
+
31
+
32
+ def get_cortex_skills_dir() -> Path:
33
+ return Path.home() / ".cortex" / "skills"
@@ -0,0 +1,39 @@
1
+ from pathlib import Path
2
+ from typing import Any, Optional
3
+ import yaml
4
+
5
+
6
+ def read_yaml(path: Path) -> Optional[dict]:
7
+ if not path.exists():
8
+ return None
9
+ with open(path, "r", encoding="utf-8") as f:
10
+ return yaml.safe_load(f)
11
+
12
+
13
+ def write_yaml(path: Path, data: Any, sort_keys: bool = False) -> None:
14
+ path.parent.mkdir(parents=True, exist_ok=True)
15
+ with open(path, "w", encoding="utf-8") as f:
16
+ yaml.dump(data, f, default_flow_style=False, sort_keys=sort_keys)
17
+
18
+
19
+ def read_datasecops_config(project_dir: Path) -> Optional[dict]:
20
+ return read_yaml(project_dir / ".datasecops.yml")
21
+
22
+
23
+ def write_datasecops_config(project_dir: Path, config: dict) -> None:
24
+ write_yaml(project_dir / ".datasecops.yml", config)
25
+
26
+
27
+ def read_dbt_project(project_dir: Path) -> Optional[dict]:
28
+ for name in ["dbt_project.yml", "dbt/dbt_project.yml"]:
29
+ p = project_dir / name
30
+ if p.exists():
31
+ return read_yaml(p)
32
+ return None
33
+
34
+
35
+ def get_profile_name(project_dir: Path) -> str:
36
+ data = read_dbt_project(project_dir)
37
+ if data:
38
+ return data.get("profile", "")
39
+ return ""
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: datasecops-cli
3
+ Version: 0.1.0
4
+ Summary: DataSecOps Framework CLI for Snowflake Native App
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: colorama>=0.4
9
+ Requires-Dist: gitpython>=3.1
10
+ Requires-Dist: pydantic>=2.0
11
+ Requires-Dist: pyyaml>=6.0
12
+ Requires-Dist: snowflake-connector-python>=3.0
13
+ Requires-Dist: sqlfluff>=3.0
14
+ Provides-Extra: test
15
+ Requires-Dist: pytest-cov>=4.0; extra == 'test'
16
+ Requires-Dist: pytest>=7.0; extra == 'test'
@@ -0,0 +1,26 @@
1
+ datasecops_cli/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
2
+ datasecops_cli/config.py,sha256=2e0gdNvbuv-9EZgTrF9IG9KId-jFmPL3tgCa2X5442w,4222
3
+ datasecops_cli/main.py,sha256=MrI3rr4iMLuvZXPghoajFWtmchU6gfYkPDMKF7hm1kM,4430
4
+ datasecops_cli/menus/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
5
+ datasecops_cli/menus/development.py,sha256=kYAklLdpJrA8rIbbE3dfmfGejsL4kF00uz4sbhIZ8nM,7032
6
+ datasecops_cli/menus/downloads.py,sha256=VufM5Sl2wkIYGbEKU1NRPdmjAUbqykNo9vL34Hd7FuY,3474
7
+ datasecops_cli/menus/git_operations.py,sha256=nhFnmHK3JE-2rbbd6hzwQm_R9eekr5tBLrFMWuSPe_k,8470
8
+ datasecops_cli/models/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
9
+ datasecops_cli/models/git_helpers.py,sha256=Mi-5dnlbvNjBTZGEOG6ChA5_FupiW86ckMH8ANjjy-c,714
10
+ datasecops_cli/models/project_config.py,sha256=87YaVP9P_pF0FMk_-XZGNTKrrB2pv_2Y61qwHj1yEMU,2860
11
+ datasecops_cli/services/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
12
+ datasecops_cli/services/dbt_runner.py,sha256=xfOvslXPPYtRb5vQPhqH655mQXNL9Xt0m9wgnnSl5rw,5123
13
+ datasecops_cli/services/download_service.py,sha256=roMPgpBWWBRICa4f8HrqxuIG9bk4ifF69Z5QvhjTUTQ,4122
14
+ datasecops_cli/services/git_service.py,sha256=wiVSxD-jyp-Rt4UA9RgRCluruWhZdSSeM_LNyDMWYxY,7158
15
+ datasecops_cli/services/linting_service.py,sha256=4r5PdnjIZ2zAtGDJpQE19xu0iJKH8IoRhuWewPJyIe4,1743
16
+ datasecops_cli/services/skill_service.py,sha256=eOTKay7pKxZCZq4mCQDPc0d_zRINZ-KxGcYWj1wb-Bs,3427
17
+ datasecops_cli/services/snowflake_service.py,sha256=FXZ_zoTy1wGjq9JB0BvIh5XW-d-Gk2PrXHnEfFeawZ8,2167
18
+ datasecops_cli/utilities/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
19
+ datasecops_cli/utilities/display.py,sha256=f07CfRJXRPxoVj6byyt6o1Foo7wS2JeZFzi7bS8U7E0,3675
20
+ datasecops_cli/utilities/file_utils.py,sha256=BeYghjXFe2n9JiVchZaV8KAFr7V_q9MkuCGuZCo3qYs,705
21
+ datasecops_cli/utilities/yaml_utils.py,sha256=dty6t4zbn5PQWNqFSRjXsJtLF2qGxJzGUQfzzduJRGU,1122
22
+ datasecops_cli-0.1.0.dist-info/METADATA,sha256=inaMVWUw9etoRi7CIHIkEYbhjgRNOaxWTEl33dCAFIM,491
23
+ datasecops_cli-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
24
+ datasecops_cli-0.1.0.dist-info/entry_points.txt,sha256=wv98kE6CKKApNQkW5-wU9JpMa0i2Llsl3Gmp6tn_Hvs,56
25
+ datasecops_cli-0.1.0.dist-info/licenses/LICENSE,sha256=uBqkXEuQ68MBM2A-Ea6UVcxVM0LUt1rGtkDOp69XQ1k,1071
26
+ datasecops_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ datasecops = datasecops_cli.main:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Data Engineers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.