womm-cli 4.0.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.
- womm/__init__.py +53 -0
- womm/__main__.py +48 -0
- womm/_version.py +10 -0
- womm/assets/copier/meta/copier.yml +15 -0
- womm/assets/copier/meta/template/README.md.jinja +32 -0
- womm/assets/copier/meta/template/copier.yml.jinja +13 -0
- womm/assets/copier/meta/template/template/.gitkeep +0 -0
- womm/assets/copier/official/javascript/copier.yml +104 -0
- womm/assets/copier/official/javascript/template/.gitignore.jinja +35 -0
- womm/assets/copier/official/javascript/template/.nvmrc.jinja +1 -0
- womm/assets/copier/official/javascript/template/.prettierignore.jinja +10 -0
- womm/assets/copier/official/javascript/template/README.md.jinja +81 -0
- womm/assets/copier/official/javascript/template/biome.json.jinja +54 -0
- womm/assets/copier/official/javascript/template/eslint.config.mjs.jinja +51 -0
- womm/assets/copier/official/javascript/template/index.html.jinja +12 -0
- womm/assets/copier/official/javascript/template/package.json.jinja +88 -0
- womm/assets/copier/official/javascript/template/prettier.config.mjs.jinja +8 -0
- womm/assets/copier/official/javascript/template/src/App.jsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/App.tsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/App.vue.jinja +18 -0
- womm/assets/copier/official/javascript/template/src/index.jsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/index.tsx.jinja +11 -0
- womm/assets/copier/official/javascript/template/src/main.js.jinja +21 -0
- womm/assets/copier/official/javascript/template/src/main.ts.jinja +21 -0
- womm/assets/copier/official/javascript/template/tsconfig.json.jinja +35 -0
- womm/assets/copier/official/javascript/template/vite.config.mjs.jinja +10 -0
- womm/assets/copier/official/javascript/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +63 -0
- womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.js.jinja +12 -0
- womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.ts.jinja +12 -0
- womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +4 -0
- womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +27 -0
- womm/assets/copier/official/python/copier.yml +107 -0
- womm/assets/copier/official/python/template/.gitignore.jinja +40 -0
- womm/assets/copier/official/python/template/.pre-commit-config.yaml.jinja +19 -0
- womm/assets/copier/official/python/template/.python-version.jinja +1 -0
- womm/assets/copier/official/python/template/README.md.jinja +83 -0
- womm/assets/copier/official/python/template/pyproject.toml.jinja +114 -0
- womm/assets/copier/official/python/template/{% if framework == 'django' %}manage.py{% endif %}.jinja +23 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/__init__.py.jinja +3 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/asgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/__init__.py.jinja +0 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/apps.py.jinja +10 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/models.py.jinja +1 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/views.py.jinja +8 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/py.typed +0 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/settings.py.jinja +81 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/urls.py.jinja +11 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/wsgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/__init__.py.jinja +3 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/asgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/__init__.py.jinja +0 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/apps.py.jinja +10 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/models.py.jinja +1 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/views.py.jinja +8 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/py.typed +0 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/settings.py.jinja +81 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/urls.py.jinja +11 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/wsgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +78 -0
- womm/assets/copier/official/python/template/{% if with_tests %}tests{% endif %}/test_smoke.py.jinja +16 -0
- womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +8 -0
- womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +28 -0
- womm/bin/refresh_env.cmd +130 -0
- womm/cli.py +111 -0
- womm/commands/__init__.py +30 -0
- womm/commands/core/__init__.py +29 -0
- womm/commands/core/doctor.py +52 -0
- womm/commands/core/path.py +337 -0
- womm/commands/project/__init__.py +31 -0
- womm/commands/project/create.py +128 -0
- womm/commands/project/setup.py +438 -0
- womm/commands/project/template.py +160 -0
- womm/commands/system/__init__.py +31 -0
- womm/commands/system/context/__init__.py +82 -0
- womm/commands/system/context/backup.py +344 -0
- womm/commands/system/context/inventory.py +111 -0
- womm/commands/system/context/registration.py +290 -0
- womm/commands/system/deps.py +165 -0
- womm/commands/system/system.py +130 -0
- womm/exceptions/__init__.py +69 -0
- womm/exceptions/common/__init__.py +55 -0
- womm/exceptions/common/command_service.py +91 -0
- womm/exceptions/common/file_service.py +60 -0
- womm/exceptions/common/security_service.py +44 -0
- womm/exceptions/common/validation_service.py +70 -0
- womm/exceptions/context/__init__.py +27 -0
- womm/exceptions/context/context_service.py +55 -0
- womm/exceptions/project/__init__.py +29 -0
- womm/exceptions/project/project_service.py +59 -0
- womm/exceptions/system/__init__.py +25 -0
- womm/exceptions/system/system_service.py +53 -0
- womm/interfaces/__init__.py +71 -0
- womm/interfaces/context/__init__.py +34 -0
- womm/interfaces/context/menu_interface.py +686 -0
- womm/interfaces/context/registry_interface.py +562 -0
- womm/interfaces/context/script_detector_interface.py +208 -0
- womm/interfaces/context/script_registrar.py +264 -0
- womm/interfaces/core/__init__.py +26 -0
- womm/interfaces/core/doctor_interface.py +102 -0
- womm/interfaces/dependencies/__init__.py +28 -0
- womm/interfaces/dependencies/deps_interface.py +160 -0
- womm/interfaces/project/__init__.py +36 -0
- womm/interfaces/project/create_interface.py +162 -0
- womm/interfaces/project/detection_interface.py +181 -0
- womm/interfaces/project/manager_interface.py +99 -0
- womm/interfaces/project/setup_interface.py +477 -0
- womm/interfaces/project/template_store_interface.py +196 -0
- womm/interfaces/system/__init__.py +32 -0
- womm/interfaces/system/detector_interface.py +84 -0
- womm/interfaces/system/environment_interface.py +110 -0
- womm/interfaces/system/path_interface.py +570 -0
- womm/services/__init__.py +70 -0
- womm/services/common/__init__.py +33 -0
- womm/services/common/base_validation_service.py +450 -0
- womm/services/common/command_runner_service.py +647 -0
- womm/services/common/file_scanner_service.py +483 -0
- womm/services/common/security_validator_service.py +348 -0
- womm/services/context/__init__.py +37 -0
- womm/services/context/backup_entries.py +148 -0
- womm/services/context/parameters.py +515 -0
- womm/services/context/registry_paths.py +56 -0
- womm/services/context/registry_service.py +573 -0
- womm/services/context/validation_service.py +691 -0
- womm/services/dependencies/__init__.py +29 -0
- womm/services/dependencies/probe.py +102 -0
- womm/services/project/__init__.py +48 -0
- womm/services/project/copier_project_creation_service.py +111 -0
- womm/services/project/destination_guard.py +96 -0
- womm/services/project/detection_service.py +354 -0
- womm/services/project/env_utils.py +333 -0
- womm/services/project/javascript_environment_service.py +348 -0
- womm/services/project/python_environment_service.py +245 -0
- womm/services/project/setup_profile_resolver.py +146 -0
- womm/services/project/template_store_service.py +344 -0
- womm/services/project/validation_service.py +418 -0
- womm/services/system/__init__.py +32 -0
- womm/services/system/detector_service.py +704 -0
- womm/services/system/environment_service.py +494 -0
- womm/services/system/path_service.py +642 -0
- womm/shared/__init__.py +30 -0
- womm/shared/configs/__init__.py +51 -0
- womm/shared/configs/context/__init__.py +43 -0
- womm/shared/configs/context/context_config.py +125 -0
- womm/shared/configs/context/context_file_types_config.py +159 -0
- womm/shared/configs/context/context_limits_config.py +187 -0
- womm/shared/configs/context/context_paths_config.py +115 -0
- womm/shared/configs/context/context_types_config.py +65 -0
- womm/shared/configs/context/script_config.py +219 -0
- womm/shared/configs/dependencies/__init__.py +32 -0
- womm/shared/configs/dependencies/runtime_config.py +46 -0
- womm/shared/configs/dependencies/runtime_package_manager_config.py +48 -0
- womm/shared/configs/logging_config.py +89 -0
- womm/shared/configs/project/__init__.py +33 -0
- womm/shared/configs/project/project_config.py +109 -0
- womm/shared/configs/project/project_structure_config.py +88 -0
- womm/shared/configs/project/python_project_config.py +165 -0
- womm/shared/configs/security/__init__.py +26 -0
- womm/shared/configs/security/security_patterns_config.py +242 -0
- womm/shared/configs/system/__init__.py +28 -0
- womm/shared/configs/system/system_detector_config.py +210 -0
- womm/shared/configs/system/system_environment_config.py +101 -0
- womm/shared/models/__init__.py +13 -0
- womm/shared/models/template_source.py +65 -0
- womm/shared/paths.py +192 -0
- womm/shared/results/__init__.py +138 -0
- womm/shared/results/base.py +85 -0
- womm/shared/results/command_results.py +61 -0
- womm/shared/results/context_results.py +345 -0
- womm/shared/results/dependency_results.py +110 -0
- womm/shared/results/doctor_results.py +41 -0
- womm/shared/results/file_results.py +97 -0
- womm/shared/results/project_results.py +163 -0
- womm/shared/results/security_results.py +128 -0
- womm/shared/results/system_results.py +268 -0
- womm/shared/results/template_results.py +43 -0
- womm/shared/runtime.py +36 -0
- womm/ui/__init__.py +31 -0
- womm/ui/common/__init__.py +39 -0
- womm/ui/common/interactive_menu.py +246 -0
- womm/ui/common/logging.py +184 -0
- womm/ui/common/prompts.py +93 -0
- womm/ui/context/__init__.py +31 -0
- womm/ui/context/display.py +485 -0
- womm/ui/context/menu_display.py +189 -0
- womm/ui/context/wizard.py +557 -0
- womm/ui/project/__init__.py +42 -0
- womm/ui/project/create/create_completion_summaries.py +55 -0
- womm/ui/project/project_wizard.py +174 -0
- womm/ui/project/setup/setup_completion_summaries.py +111 -0
- womm/ui/project/templates/template_store_display.py +128 -0
- womm/ui/system/__init__.py +60 -0
- womm/ui/system/display.py +531 -0
- womm/ui/system/path_display.py +387 -0
- womm/utils/__init__.py +23 -0
- womm/utils/common/__init__.py +49 -0
- womm/utils/common/file_scanner_utils.py +110 -0
- womm/utils/common/path_resolver_utils.py +127 -0
- womm/utils/common/safe_fs_utils.py +135 -0
- womm/utils/context/__init__.py +54 -0
- womm/utils/context/core_utils.py +345 -0
- womm/utils/context/icon_utils.py +259 -0
- womm/utils/project/__init__.py +106 -0
- womm/utils/project/asset_utils.py +154 -0
- womm/utils/project/core_utils.py +391 -0
- womm/utils/project/file_utils.py +494 -0
- womm/utils/project/platform_utils.py +170 -0
- womm/utils/project/validation_utils.py +273 -0
- womm/utils/security/__init__.py +46 -0
- womm/utils/security/security_validation_utils.py +258 -0
- womm/utils/system/__init__.py +69 -0
- womm/utils/system/detector_utils.py +299 -0
- womm/utils/system/environment_utils.py +172 -0
- womm/utils/system/path_utils.py +101 -0
- womm_cli-4.0.0.dist-info/METADATA +203 -0
- womm_cli-4.0.0.dist-info/RECORD +218 -0
- womm_cli-4.0.0.dist-info/WHEEL +4 -0
- womm_cli-4.0.0.dist-info/entry_points.txt +2 -0
- womm_cli-4.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# PROJECT VALIDATION UTILS - Pure Project Validation Functions
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure utility functions for project validation.
|
|
9
|
+
|
|
10
|
+
This module provides stateless functions for:
|
|
11
|
+
- Project name validation and suggestion
|
|
12
|
+
- Project path validation
|
|
13
|
+
- Project type validation
|
|
14
|
+
- Project configuration validation
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# IMPORTS
|
|
21
|
+
# ///////////////////////////////////////////////////////////////
|
|
22
|
+
# Standard library imports
|
|
23
|
+
import re
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
# Local imports
|
|
27
|
+
from ...shared.configs.project import ProjectConfig
|
|
28
|
+
|
|
29
|
+
# ///////////////////////////////////////////////////////////////
|
|
30
|
+
# VALIDATION FUNCTIONS
|
|
31
|
+
# ///////////////////////////////////////////////////////////////
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def suggest_project_name(base_name: str) -> str:
|
|
35
|
+
"""Suggest a valid project name based on input.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
base_name: Base name to suggest from
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
str: Valid project name suggestion
|
|
42
|
+
"""
|
|
43
|
+
if not base_name:
|
|
44
|
+
return "my-project"
|
|
45
|
+
|
|
46
|
+
# Remove invalid characters
|
|
47
|
+
suggested = re.sub(ProjectConfig.INVALID_CHARS, "-", base_name)
|
|
48
|
+
|
|
49
|
+
# Remove leading/trailing dots
|
|
50
|
+
suggested = suggested.strip(".")
|
|
51
|
+
|
|
52
|
+
# Convert to lowercase
|
|
53
|
+
suggested = suggested.lower()
|
|
54
|
+
|
|
55
|
+
# Replace spaces with hyphens
|
|
56
|
+
suggested = re.sub(r"\s+", "-", suggested)
|
|
57
|
+
|
|
58
|
+
# Remove multiple consecutive hyphens
|
|
59
|
+
suggested = re.sub(r"-+", "-", suggested)
|
|
60
|
+
|
|
61
|
+
# Remove any character not allowed in a valid project name
|
|
62
|
+
suggested = re.sub(r"[^a-zA-Z0-9._-]", "", suggested)
|
|
63
|
+
|
|
64
|
+
# Ensure it's not empty
|
|
65
|
+
if not suggested:
|
|
66
|
+
suggested = "my-project"
|
|
67
|
+
|
|
68
|
+
# Ensure it's not too long
|
|
69
|
+
if len(suggested) > ProjectConfig.MAX_PROJECT_NAME_LENGTH:
|
|
70
|
+
suggested = suggested[: ProjectConfig.MAX_PROJECT_NAME_LENGTH].rstrip("-")
|
|
71
|
+
|
|
72
|
+
# Ensure it doesn't start with a number
|
|
73
|
+
if suggested and suggested[0].isdigit():
|
|
74
|
+
suggested = f"project-{suggested}"
|
|
75
|
+
|
|
76
|
+
return suggested
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def validate_project_name(project_name: str) -> None:
|
|
80
|
+
"""Validate a project name.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
project_name: Name to validate
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
ValueError: If project name is invalid
|
|
87
|
+
"""
|
|
88
|
+
if not project_name:
|
|
89
|
+
raise ValueError("Project name cannot be empty")
|
|
90
|
+
|
|
91
|
+
if len(project_name) > ProjectConfig.MAX_PROJECT_NAME_LENGTH:
|
|
92
|
+
raise ValueError(
|
|
93
|
+
f"Project name is too long (max "
|
|
94
|
+
f"{ProjectConfig.MAX_PROJECT_NAME_LENGTH} characters): "
|
|
95
|
+
f"length={len(project_name)}"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
if project_name.startswith(".") or project_name.endswith("."):
|
|
99
|
+
raise ValueError("Project name cannot start or end with a dot")
|
|
100
|
+
|
|
101
|
+
if re.search(ProjectConfig.INVALID_CHARS, project_name):
|
|
102
|
+
raise ValueError(
|
|
103
|
+
f"Project name contains invalid characters: {ProjectConfig.INVALID_CHARS}"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
if project_name.upper() in ProjectConfig.RESERVED_NAMES:
|
|
107
|
+
raise ValueError(f"Project name '{project_name}' is reserved on Windows")
|
|
108
|
+
|
|
109
|
+
if not re.match(r"^[a-zA-Z0-9._-]+$", project_name):
|
|
110
|
+
raise ValueError(
|
|
111
|
+
"Project name can only contain letters, numbers, dots, "
|
|
112
|
+
"underscores, and hyphens"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def validate_project_path(
|
|
117
|
+
project_path: Path,
|
|
118
|
+
*,
|
|
119
|
+
must_exist: bool = False,
|
|
120
|
+
require_empty: bool = True,
|
|
121
|
+
) -> None:
|
|
122
|
+
"""Validate a project path.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
project_path: Path to validate
|
|
126
|
+
must_exist: Whether the project directory must already exist
|
|
127
|
+
require_empty: Whether an existing project directory must be empty
|
|
128
|
+
|
|
129
|
+
Raises:
|
|
130
|
+
ValueError: If project path is invalid
|
|
131
|
+
OSError: If the parent directory cannot be accessed
|
|
132
|
+
"""
|
|
133
|
+
if not project_path:
|
|
134
|
+
raise ValueError("Project path cannot be None")
|
|
135
|
+
|
|
136
|
+
# Check if path is absolute
|
|
137
|
+
if not project_path.is_absolute():
|
|
138
|
+
project_path = project_path.resolve()
|
|
139
|
+
|
|
140
|
+
# Check if parent directory exists and is writable
|
|
141
|
+
parent_dir = project_path.parent
|
|
142
|
+
if not parent_dir.exists():
|
|
143
|
+
raise ValueError(f"Parent directory does not exist: {parent_dir}")
|
|
144
|
+
|
|
145
|
+
if not parent_dir.is_dir():
|
|
146
|
+
raise ValueError(f"Parent path is not a directory: {parent_dir}")
|
|
147
|
+
|
|
148
|
+
# Check if we can write to parent directory
|
|
149
|
+
test_file = parent_dir / ".womm_test_write"
|
|
150
|
+
test_file.touch()
|
|
151
|
+
test_file.unlink()
|
|
152
|
+
|
|
153
|
+
if must_exist and not project_path.exists():
|
|
154
|
+
raise ValueError(f"Project directory does not exist: {project_path}")
|
|
155
|
+
|
|
156
|
+
# Check if project directory already exists
|
|
157
|
+
if project_path.exists():
|
|
158
|
+
if not project_path.is_dir():
|
|
159
|
+
raise ValueError(f"Path exists but is not a directory: {project_path}")
|
|
160
|
+
|
|
161
|
+
# Check if directory is empty
|
|
162
|
+
if require_empty and any(project_path.iterdir()):
|
|
163
|
+
raise ValueError(f"Directory is not empty: {project_path}")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def validate_project_type(project_type: str) -> None:
|
|
167
|
+
"""Validate a project type.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
project_type: Type to validate
|
|
171
|
+
|
|
172
|
+
Raises:
|
|
173
|
+
ValueError: If project type is invalid
|
|
174
|
+
"""
|
|
175
|
+
if not project_type:
|
|
176
|
+
raise ValueError("Project type cannot be empty")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def validate_project_config(config: dict[str, str]) -> None:
|
|
180
|
+
"""Validate a project configuration.
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
config: Configuration dictionary to validate
|
|
184
|
+
|
|
185
|
+
Raises:
|
|
186
|
+
ValueError: If project configuration is invalid
|
|
187
|
+
"""
|
|
188
|
+
if not config:
|
|
189
|
+
raise ValueError("Project configuration cannot be None")
|
|
190
|
+
|
|
191
|
+
required_fields = ["project_name", "project_type"]
|
|
192
|
+
|
|
193
|
+
for field in required_fields:
|
|
194
|
+
if field not in config:
|
|
195
|
+
raise ValueError(
|
|
196
|
+
f"Missing required field: {field}. "
|
|
197
|
+
f"Required fields: {', '.join(required_fields)}"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
# Validate individual fields
|
|
201
|
+
validate_project_name(config["project_name"])
|
|
202
|
+
validate_project_type(config["project_type"])
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def check_project_name(project_name: str) -> tuple[bool, str | None]:
|
|
206
|
+
"""Check if a project name is valid (non-raising version for UI).
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
project_name: Name to check
|
|
210
|
+
|
|
211
|
+
Returns:
|
|
212
|
+
tuple[bool, str | None]: (is_valid, error_message)
|
|
213
|
+
"""
|
|
214
|
+
try:
|
|
215
|
+
validate_project_name(project_name)
|
|
216
|
+
return (True, None)
|
|
217
|
+
except ValueError as e:
|
|
218
|
+
return (False, str(e))
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def get_validation_summary(
|
|
222
|
+
project_name: str, project_path: Path, project_type: str
|
|
223
|
+
) -> dict[str, bool]:
|
|
224
|
+
"""Get validation summary for all project components.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
project_name: Project name to validate
|
|
228
|
+
project_path: Project path to validate
|
|
229
|
+
project_type: Project type to validate
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
dict[str, bool]: Validation results for each component
|
|
233
|
+
"""
|
|
234
|
+
summary = {
|
|
235
|
+
"project_name": True,
|
|
236
|
+
"project_path": True,
|
|
237
|
+
"project_type": True,
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
# Validate project name
|
|
241
|
+
try:
|
|
242
|
+
validate_project_name(project_name)
|
|
243
|
+
except ValueError:
|
|
244
|
+
summary["project_name"] = False
|
|
245
|
+
|
|
246
|
+
# Validate project path
|
|
247
|
+
try:
|
|
248
|
+
validate_project_path(project_path)
|
|
249
|
+
except (ValueError, OSError):
|
|
250
|
+
summary["project_path"] = False
|
|
251
|
+
|
|
252
|
+
# Validate project type
|
|
253
|
+
try:
|
|
254
|
+
validate_project_type(project_type)
|
|
255
|
+
except ValueError:
|
|
256
|
+
summary["project_type"] = False
|
|
257
|
+
|
|
258
|
+
return summary
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
# ///////////////////////////////////////////////////////////////
|
|
262
|
+
# PUBLIC API
|
|
263
|
+
# ///////////////////////////////////////////////////////////////
|
|
264
|
+
|
|
265
|
+
__all__ = [
|
|
266
|
+
"check_project_name",
|
|
267
|
+
"get_validation_summary",
|
|
268
|
+
"suggest_project_name",
|
|
269
|
+
"validate_project_config",
|
|
270
|
+
"validate_project_name",
|
|
271
|
+
"validate_project_path",
|
|
272
|
+
"validate_project_type",
|
|
273
|
+
]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# UTILS SECURITY - Security Utilities
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure utility functions for security validation operations.
|
|
9
|
+
|
|
10
|
+
This package contains stateless utility functions for security
|
|
11
|
+
validation and command/path validation operations.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Local imports
|
|
20
|
+
from .security_validation_utils import (
|
|
21
|
+
has_dangerous_command_patterns,
|
|
22
|
+
has_dangerous_file_patterns,
|
|
23
|
+
has_excessive_traversal,
|
|
24
|
+
is_dangerous_argument,
|
|
25
|
+
is_system_directory,
|
|
26
|
+
resolve_backup_name,
|
|
27
|
+
validate_chmod_permissions,
|
|
28
|
+
validate_chown_owner,
|
|
29
|
+
validate_permission_command,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# ///////////////////////////////////////////////////////////////
|
|
33
|
+
# PUBLIC API
|
|
34
|
+
# ///////////////////////////////////////////////////////////////
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"has_dangerous_command_patterns",
|
|
38
|
+
"has_dangerous_file_patterns",
|
|
39
|
+
"has_excessive_traversal",
|
|
40
|
+
"is_dangerous_argument",
|
|
41
|
+
"is_system_directory",
|
|
42
|
+
"resolve_backup_name",
|
|
43
|
+
"validate_chmod_permissions",
|
|
44
|
+
"validate_chown_owner",
|
|
45
|
+
"validate_permission_command",
|
|
46
|
+
]
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# SECURITY VALIDATION UTILS - Pure Security Validation Functions
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure security validation functions for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This module contains stateless utility functions for security validation
|
|
11
|
+
that can be used independently without class instantiation.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Standard library imports
|
|
20
|
+
import re
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
# Local imports
|
|
24
|
+
from ...shared.configs.security import SecurityPatternsConfig
|
|
25
|
+
|
|
26
|
+
# ///////////////////////////////////////////////////////////////
|
|
27
|
+
# BACKUP NAME CONTAINMENT
|
|
28
|
+
# ///////////////////////////////////////////////////////////////
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def resolve_backup_name(backup_dir: Path, name: str) -> Path | None:
|
|
32
|
+
"""Resolve a backup name inside a backup directory.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
backup_dir: Directory the name must stay inside.
|
|
36
|
+
name: Bare file name, as listed by a backup listing.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
The resolved path, or None when the name is unsafe, absent, or
|
|
40
|
+
not a regular file. Callers must not disclose the resolved path.
|
|
41
|
+
"""
|
|
42
|
+
# These checks intentionally overlap (e.g. an absolute POSIX path is
|
|
43
|
+
# also caught by the "/" check; a Windows drive-relative name is
|
|
44
|
+
# also caught by ":"): a containment filter must not depend on the
|
|
45
|
+
# ordering of its own sub-clauses to stay correct, so each is kept
|
|
46
|
+
# even where another already covers the same input.
|
|
47
|
+
if (
|
|
48
|
+
not name
|
|
49
|
+
or "\x00" in name
|
|
50
|
+
or ".." in name
|
|
51
|
+
or "/" in name
|
|
52
|
+
or "\\" in name
|
|
53
|
+
or ":" in name
|
|
54
|
+
):
|
|
55
|
+
return None
|
|
56
|
+
if Path(name).is_absolute() or Path(name).drive:
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
candidate = (backup_dir / name).resolve()
|
|
61
|
+
root = backup_dir.resolve()
|
|
62
|
+
except OSError:
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
if not candidate.is_relative_to(root):
|
|
66
|
+
return None
|
|
67
|
+
if not candidate.is_file():
|
|
68
|
+
return None
|
|
69
|
+
# resolve() followed the symlink; is_relative_to already rejected any
|
|
70
|
+
# target outside root, so reaching here means the file is contained.
|
|
71
|
+
return candidate
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# ///////////////////////////////////////////////////////////////
|
|
75
|
+
# COMMAND VALIDATION FUNCTIONS
|
|
76
|
+
# ///////////////////////////////////////////////////////////////
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def has_dangerous_command_patterns(command: str) -> bool:
|
|
80
|
+
"""Check if a command contains dangerous patterns.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
command: Command to check
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
bool: True if dangerous patterns found
|
|
87
|
+
"""
|
|
88
|
+
for pattern in SecurityPatternsConfig.DANGEROUS_COMMAND_PATTERNS:
|
|
89
|
+
if re.search(pattern, command, re.IGNORECASE):
|
|
90
|
+
return True
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def is_dangerous_argument(command: str, argument: str) -> bool:
|
|
95
|
+
"""Check if an argument is dangerous for a specific command.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
command: Base command (lowercase)
|
|
99
|
+
argument: Argument to check
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
bool: True if argument is dangerous
|
|
103
|
+
"""
|
|
104
|
+
command_lower = command.lower()
|
|
105
|
+
argument_lower = argument.lower()
|
|
106
|
+
|
|
107
|
+
# Check against dangerous command patterns
|
|
108
|
+
if command_lower in SecurityPatternsConfig.DANGEROUS_COMMANDS:
|
|
109
|
+
dangerous_args = SecurityPatternsConfig.DANGEROUS_COMMANDS[command_lower]
|
|
110
|
+
for dangerous_arg in dangerous_args:
|
|
111
|
+
if dangerous_arg in argument_lower:
|
|
112
|
+
return True
|
|
113
|
+
|
|
114
|
+
# Check for shell injection patterns
|
|
115
|
+
return any(
|
|
116
|
+
re.search(pattern, argument_lower)
|
|
117
|
+
for pattern in SecurityPatternsConfig.SHELL_INJECTION_PATTERNS
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def validate_chmod_permissions(permissions: str) -> bool:
|
|
122
|
+
"""Validate chmod permission string.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
permissions: Permission string to validate
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
bool: True if permissions are valid
|
|
129
|
+
"""
|
|
130
|
+
return any(
|
|
131
|
+
re.match(pattern, permissions)
|
|
132
|
+
for pattern in SecurityPatternsConfig.CHMOD_ALLOWED_PATTERNS
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def validate_chown_owner(owner: str) -> bool:
|
|
137
|
+
"""Validate chown owner string.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
owner: Owner string to validate
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
bool: True if owner is valid
|
|
144
|
+
"""
|
|
145
|
+
return any(
|
|
146
|
+
re.match(pattern, owner)
|
|
147
|
+
for pattern in SecurityPatternsConfig.CHOWN_ALLOWED_PATTERNS
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def validate_permission_command(command: list[str]) -> bool:
|
|
152
|
+
"""Validate permission-related commands (chmod, chown).
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
command: Command to validate
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
bool: True if command is valid
|
|
159
|
+
"""
|
|
160
|
+
if len(command) < 2:
|
|
161
|
+
return False
|
|
162
|
+
|
|
163
|
+
base_command = command[0].lower()
|
|
164
|
+
|
|
165
|
+
if base_command == "chmod":
|
|
166
|
+
permissions = command[1]
|
|
167
|
+
return validate_chmod_permissions(permissions)
|
|
168
|
+
|
|
169
|
+
if base_command == "chown":
|
|
170
|
+
owner = command[1]
|
|
171
|
+
return validate_chown_owner(owner)
|
|
172
|
+
|
|
173
|
+
return False
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# ///////////////////////////////////////////////////////////////
|
|
177
|
+
# PATH VALIDATION FUNCTIONS
|
|
178
|
+
# ///////////////////////////////////////////////////////////////
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def has_dangerous_file_patterns(file_path: str) -> bool:
|
|
182
|
+
"""Check if a file path contains dangerous patterns.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
file_path: File path to check
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
bool: True if dangerous patterns found
|
|
189
|
+
"""
|
|
190
|
+
return any(
|
|
191
|
+
re.search(pattern, file_path, re.IGNORECASE)
|
|
192
|
+
for pattern in SecurityPatternsConfig.DANGEROUS_FILE_PATTERNS
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def has_excessive_traversal(file_path: str, max_traversal: int = 2) -> bool:
|
|
197
|
+
"""Check if a file path has excessive directory traversal.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
file_path: File path to check
|
|
201
|
+
max_traversal: Maximum allowed traversal levels
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
bool: True if traversal is excessive
|
|
205
|
+
"""
|
|
206
|
+
if ".." not in file_path:
|
|
207
|
+
return False
|
|
208
|
+
traversal_count = file_path.count("..")
|
|
209
|
+
return traversal_count > max_traversal
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def is_system_directory(path: Path) -> bool:
|
|
213
|
+
"""Check if a path is a system directory.
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
path: Path to check
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
bool: True if it's a system directory
|
|
220
|
+
"""
|
|
221
|
+
try:
|
|
222
|
+
path_str = str(path.resolve())
|
|
223
|
+
path_normalized = path_str.replace("\\", "/")
|
|
224
|
+
|
|
225
|
+
for system_dir in SecurityPatternsConfig.SYSTEM_DIRECTORIES:
|
|
226
|
+
system_dir_normalized = system_dir.replace("\\", "/")
|
|
227
|
+
|
|
228
|
+
# For root directories like "C:\\" or "/", check that the path
|
|
229
|
+
# is actually in a system subdirectory, not just on the same drive
|
|
230
|
+
if system_dir_normalized in ("C:/", "/"):
|
|
231
|
+
# Only match if path is exactly the root or in a known system subdirectory
|
|
232
|
+
if path_normalized == system_dir_normalized.rstrip("/"):
|
|
233
|
+
return True
|
|
234
|
+
# Check for known system subdirectories
|
|
235
|
+
system_subdirs = [
|
|
236
|
+
"Windows",
|
|
237
|
+
"System32",
|
|
238
|
+
"Program Files",
|
|
239
|
+
"Program Files (x86)",
|
|
240
|
+
]
|
|
241
|
+
if any(
|
|
242
|
+
path_normalized.startswith(
|
|
243
|
+
(
|
|
244
|
+
f"{system_dir_normalized.rstrip('/')}/{subdir}/",
|
|
245
|
+
f"{system_dir_normalized.rstrip('/')}\\{subdir}\\",
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
for subdir in system_subdirs
|
|
249
|
+
):
|
|
250
|
+
return True
|
|
251
|
+
# For specific system directories, use startswith
|
|
252
|
+
elif path_normalized.startswith(system_dir_normalized):
|
|
253
|
+
return True
|
|
254
|
+
|
|
255
|
+
return False
|
|
256
|
+
except Exception:
|
|
257
|
+
# If path resolution fails, be conservative
|
|
258
|
+
return True
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# UTILS SYSTEM - System Utilities
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure utility functions for system operations.
|
|
9
|
+
|
|
10
|
+
This package contains stateless utility functions for system path
|
|
11
|
+
and environment management operations.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Local imports
|
|
20
|
+
from .detector_utils import (
|
|
21
|
+
create_editor_entry,
|
|
22
|
+
create_package_manager_entry,
|
|
23
|
+
create_shell_entry,
|
|
24
|
+
extract_version_first_line,
|
|
25
|
+
extract_version_from_stdout,
|
|
26
|
+
generate_editor_recommendation,
|
|
27
|
+
generate_package_manager_recommendation,
|
|
28
|
+
generate_recommendations,
|
|
29
|
+
get_best_package_manager,
|
|
30
|
+
get_editor_name,
|
|
31
|
+
get_package_manager_metadata,
|
|
32
|
+
get_shell_name,
|
|
33
|
+
)
|
|
34
|
+
from .environment_utils import (
|
|
35
|
+
combine_paths,
|
|
36
|
+
get_environment_info,
|
|
37
|
+
get_shell_config_files,
|
|
38
|
+
is_command_accessible,
|
|
39
|
+
read_windows_registry_path,
|
|
40
|
+
refresh_path_from_registry,
|
|
41
|
+
)
|
|
42
|
+
from .path_utils import deduplicate_path_entries, extract_path_from_reg_output
|
|
43
|
+
|
|
44
|
+
# ///////////////////////////////////////////////////////////////
|
|
45
|
+
# PUBLIC API
|
|
46
|
+
# ///////////////////////////////////////////////////////////////
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"combine_paths",
|
|
50
|
+
"create_editor_entry",
|
|
51
|
+
"create_package_manager_entry",
|
|
52
|
+
"create_shell_entry",
|
|
53
|
+
"deduplicate_path_entries",
|
|
54
|
+
"extract_path_from_reg_output",
|
|
55
|
+
"extract_version_first_line",
|
|
56
|
+
"extract_version_from_stdout",
|
|
57
|
+
"generate_editor_recommendation",
|
|
58
|
+
"generate_package_manager_recommendation",
|
|
59
|
+
"generate_recommendations",
|
|
60
|
+
"get_best_package_manager",
|
|
61
|
+
"get_editor_name",
|
|
62
|
+
"get_environment_info",
|
|
63
|
+
"get_package_manager_metadata",
|
|
64
|
+
"get_shell_config_files",
|
|
65
|
+
"get_shell_name",
|
|
66
|
+
"is_command_accessible",
|
|
67
|
+
"read_windows_registry_path",
|
|
68
|
+
"refresh_path_from_registry",
|
|
69
|
+
]
|