taipanstack 0.3.3__tar.gz → 0.3.4__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.
- {taipanstack-0.3.3 → taipanstack-0.3.4}/PKG-INFO +1 -1
- {taipanstack-0.3.3 → taipanstack-0.3.4}/pyproject.toml +1 -1
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/__init__.py +1 -10
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/config/generators.py +13 -16
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/core/__init__.py +0 -22
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/core/optimizations.py +0 -1
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/core/result.py +0 -1
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/security/__init__.py +3 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/security/decorators.py +0 -1
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/security/guards.py +0 -1
- taipanstack-0.3.4/src/taipanstack/security/password.py +87 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/security/sanitizers.py +0 -1
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/security/validators.py +1 -1
- taipanstack-0.3.4/src/taipanstack/utils/__init__.py +20 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/utils/circuit_breaker.py +0 -1
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/utils/logging.py +2 -3
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/utils/metrics.py +4 -5
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/utils/retry.py +1 -2
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/utils/subprocess.py +1 -2
- taipanstack-0.3.3/src/taipanstack/utils/__init__.py +0 -24
- {taipanstack-0.3.3 → taipanstack-0.3.4}/LICENSE +0 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/README.md +0 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/config/__init__.py +0 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/config/models.py +0 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/config/version_config.py +0 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/core/compat.py +0 -0
- {taipanstack-0.3.3 → taipanstack-0.3.4}/src/taipanstack/utils/filesystem.py +0 -0
|
@@ -5,7 +5,7 @@ A modular, secure, and scalable Python stack for robust development.
|
|
|
5
5
|
Supports Python 3.11+ with version-aware optimizations for 3.13/3.14.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "0.3.
|
|
8
|
+
__version__ = "0.3.4"
|
|
9
9
|
|
|
10
10
|
from taipanstack.config.version_config import (
|
|
11
11
|
VersionRecommendations,
|
|
@@ -19,11 +19,6 @@ from taipanstack.core.compat import (
|
|
|
19
19
|
get_features,
|
|
20
20
|
get_python_info,
|
|
21
21
|
)
|
|
22
|
-
from taipanstack.core.optimizations import apply_optimizations, get_optimization_profile
|
|
23
|
-
from taipanstack.security.guards import (
|
|
24
|
-
guard_command_injection,
|
|
25
|
-
guard_path_traversal,
|
|
26
|
-
)
|
|
27
22
|
from taipanstack.security.validators import (
|
|
28
23
|
validate_email,
|
|
29
24
|
validate_project_name,
|
|
@@ -36,13 +31,9 @@ __all__ = [
|
|
|
36
31
|
"PY314",
|
|
37
32
|
"PY_VERSION",
|
|
38
33
|
"VersionRecommendations",
|
|
39
|
-
"apply_optimizations",
|
|
40
34
|
"get_features",
|
|
41
|
-
"get_optimization_profile",
|
|
42
35
|
"get_python_info",
|
|
43
36
|
"get_version_recommendations",
|
|
44
|
-
"guard_command_injection",
|
|
45
|
-
"guard_path_traversal",
|
|
46
37
|
"validate_email",
|
|
47
38
|
"validate_project_name",
|
|
48
39
|
"validate_python_version",
|
|
@@ -5,13 +5,10 @@ This module generates configuration files (pyproject.toml, pre-commit, etc.)
|
|
|
5
5
|
with proper validation and templating.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from __future__ import annotations
|
|
9
8
|
|
|
10
9
|
from pathlib import Path
|
|
11
|
-
from typing import TYPE_CHECKING
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
from taipanstack.config.models import StackConfig
|
|
11
|
+
from taipanstack.config.models import StackConfig
|
|
15
12
|
|
|
16
13
|
|
|
17
14
|
def _generate_ruff_config(target_version: str) -> str:
|
|
@@ -167,48 +164,48 @@ def generate_pre_commit_config(config: StackConfig) -> str:
|
|
|
167
164
|
Pre-commit configuration YAML string.
|
|
168
165
|
|
|
169
166
|
"""
|
|
170
|
-
security_hooks =
|
|
167
|
+
security_hooks: list[str] = []
|
|
171
168
|
|
|
172
169
|
if config.security.enable_bandit:
|
|
173
170
|
severity = config.security.bandit_severity[0].upper()
|
|
174
|
-
security_hooks
|
|
171
|
+
security_hooks.append(f"""
|
|
175
172
|
- repo: https://github.com/PyCQA/bandit
|
|
176
173
|
rev: '1.8.0'
|
|
177
174
|
hooks:
|
|
178
175
|
- id: bandit
|
|
179
176
|
args: ["-r", ".", "-l{severity}"]
|
|
180
|
-
"""
|
|
177
|
+
""")
|
|
181
178
|
|
|
182
179
|
if config.security.enable_safety:
|
|
183
|
-
security_hooks
|
|
180
|
+
security_hooks.append("""
|
|
184
181
|
- repo: https://github.com/pyupio/safety
|
|
185
182
|
rev: '3.2.11'
|
|
186
183
|
hooks:
|
|
187
184
|
- id: safety
|
|
188
185
|
args: ["check", "--json"]
|
|
189
|
-
"""
|
|
186
|
+
""")
|
|
190
187
|
|
|
191
188
|
if config.security.enable_semgrep:
|
|
192
|
-
security_hooks
|
|
189
|
+
security_hooks.append("""
|
|
193
190
|
- repo: https://github.com/semgrep/pre-commit
|
|
194
191
|
rev: 'v1.99.0'
|
|
195
192
|
hooks:
|
|
196
193
|
- id: semgrep
|
|
197
194
|
args: ['--config=auto']
|
|
198
|
-
"""
|
|
195
|
+
""")
|
|
199
196
|
|
|
200
197
|
if config.security.enable_detect_secrets:
|
|
201
|
-
security_hooks
|
|
198
|
+
security_hooks.append("""
|
|
202
199
|
- repo: https://github.com/Yelp/detect-secrets
|
|
203
200
|
rev: 'v1.5.0'
|
|
204
201
|
hooks:
|
|
205
202
|
- id: detect-secrets
|
|
206
203
|
args: ['--baseline', '.secrets.baseline']
|
|
207
|
-
"""
|
|
204
|
+
""")
|
|
208
205
|
|
|
209
206
|
# Add pip-audit for paranoid mode
|
|
210
207
|
if config.security.level == "paranoid":
|
|
211
|
-
security_hooks
|
|
208
|
+
security_hooks.append("""
|
|
212
209
|
- repo: https://github.com/trailofbits/pip-audit
|
|
213
210
|
rev: 'v2.7.3'
|
|
214
211
|
hooks:
|
|
@@ -223,7 +220,7 @@ def generate_pre_commit_config(config: StackConfig) -> str:
|
|
|
223
220
|
rev: 'v2.3.3'
|
|
224
221
|
hooks:
|
|
225
222
|
- id: tryceratops
|
|
226
|
-
"""
|
|
223
|
+
""")
|
|
227
224
|
|
|
228
225
|
return f"""# Stack v2.0 Pre-commit Configuration
|
|
229
226
|
# Security Level: {config.security.level}
|
|
@@ -251,7 +248,7 @@ repos:
|
|
|
251
248
|
hooks:
|
|
252
249
|
- id: mypy
|
|
253
250
|
additional_dependencies: [types-all, pydantic]
|
|
254
|
-
{security_hooks}"""
|
|
251
|
+
{"".join(security_hooks)}"""
|
|
255
252
|
|
|
256
253
|
|
|
257
254
|
def generate_dependabot_config() -> str:
|
|
@@ -4,18 +4,6 @@ Provides core functionality including Result types, version compatibility,
|
|
|
4
4
|
and optimization utilities.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
from taipanstack.core.compat import (
|
|
8
|
-
PY311,
|
|
9
|
-
PY312,
|
|
10
|
-
PY313,
|
|
11
|
-
PY314,
|
|
12
|
-
PY_VERSION,
|
|
13
|
-
PythonFeatures,
|
|
14
|
-
VersionTier,
|
|
15
|
-
get_features,
|
|
16
|
-
get_python_info,
|
|
17
|
-
is_experimental_enabled,
|
|
18
|
-
)
|
|
19
7
|
from taipanstack.core.optimizations import (
|
|
20
8
|
OptimizationProfile,
|
|
21
9
|
OptimizationResult,
|
|
@@ -26,22 +14,12 @@ from taipanstack.core.optimizations import (
|
|
|
26
14
|
from taipanstack.core.result import Err, Ok, Result
|
|
27
15
|
|
|
28
16
|
__all__ = [
|
|
29
|
-
"PY311",
|
|
30
|
-
"PY312",
|
|
31
|
-
"PY313",
|
|
32
|
-
"PY314",
|
|
33
|
-
"PY_VERSION",
|
|
34
17
|
"Err",
|
|
35
18
|
"Ok",
|
|
36
19
|
"OptimizationProfile",
|
|
37
20
|
"OptimizationResult",
|
|
38
|
-
"PythonFeatures",
|
|
39
21
|
"Result",
|
|
40
|
-
"VersionTier",
|
|
41
22
|
"apply_optimizations",
|
|
42
|
-
"get_features",
|
|
43
23
|
"get_optimization_profile",
|
|
44
|
-
"get_python_info",
|
|
45
24
|
"get_recommended_thread_pool_size",
|
|
46
|
-
"is_experimental_enabled",
|
|
47
25
|
]
|
|
@@ -16,6 +16,7 @@ from taipanstack.security.guards import (
|
|
|
16
16
|
guard_path_traversal,
|
|
17
17
|
guard_ssrf,
|
|
18
18
|
)
|
|
19
|
+
from taipanstack.security.password import hash_password, verify_password
|
|
19
20
|
from taipanstack.security.sanitizers import (
|
|
20
21
|
sanitize_filename,
|
|
21
22
|
sanitize_path,
|
|
@@ -40,7 +41,9 @@ __all__ = [
|
|
|
40
41
|
"guard_file_extension",
|
|
41
42
|
"guard_path_traversal",
|
|
42
43
|
"guard_ssrf",
|
|
44
|
+
"hash_password",
|
|
43
45
|
"require_type",
|
|
46
|
+
"verify_password",
|
|
44
47
|
# Sanitizers
|
|
45
48
|
"sanitize_filename",
|
|
46
49
|
"sanitize_path",
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Password hashing and verification utilities.
|
|
3
|
+
|
|
4
|
+
This module provides functions for secure password management using
|
|
5
|
+
PBKDF2-HMAC-SHA256.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
import secrets
|
|
10
|
+
|
|
11
|
+
from pydantic import SecretStr
|
|
12
|
+
|
|
13
|
+
# Constants for PBKDF2
|
|
14
|
+
ITERATIONS = 600_000
|
|
15
|
+
SALT_SIZE = 16
|
|
16
|
+
HASH_ALGORITHM = "sha256"
|
|
17
|
+
FORMAT = "pbkdf2_sha256"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def hash_password(password: str | SecretStr) -> str:
|
|
21
|
+
"""
|
|
22
|
+
Hash a password using PBKDF2-HMAC-SHA256.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
password: The plaintext password to hash.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
The hashed password in the format:
|
|
29
|
+
pbkdf2_sha256$<iterations>$<salt_hex>$<hash_hex>
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
if isinstance(password, SecretStr):
|
|
33
|
+
password_str = password.get_secret_value()
|
|
34
|
+
else:
|
|
35
|
+
password_str = password
|
|
36
|
+
|
|
37
|
+
salt = secrets.token_bytes(SALT_SIZE)
|
|
38
|
+
hash_bytes = hashlib.pbkdf2_hmac(
|
|
39
|
+
HASH_ALGORITHM,
|
|
40
|
+
password_str.encode("utf-8"),
|
|
41
|
+
salt,
|
|
42
|
+
ITERATIONS,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return f"{FORMAT}${ITERATIONS}${salt.hex()}${hash_bytes.hex()}"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def verify_password(password: str | SecretStr, password_hash: str) -> bool:
|
|
49
|
+
"""
|
|
50
|
+
Verify a password against a PBKDF2-HMAC-SHA256 hash.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
password: The plaintext password to verify.
|
|
54
|
+
password_hash: The stored password hash.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
True if the password matches the hash, False otherwise.
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
if isinstance(password, SecretStr):
|
|
61
|
+
password_str = password.get_secret_value()
|
|
62
|
+
else:
|
|
63
|
+
password_str = password
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
parts = password_hash.split("$")
|
|
67
|
+
if len(parts) != 4:
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
algorithm, iterations_str, salt_hex, hash_hex = parts
|
|
71
|
+
if algorithm != FORMAT:
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
iterations = int(iterations_str)
|
|
75
|
+
salt = bytes.fromhex(salt_hex)
|
|
76
|
+
stored_hash = bytes.fromhex(hash_hex)
|
|
77
|
+
|
|
78
|
+
new_hash = hashlib.pbkdf2_hmac(
|
|
79
|
+
HASH_ALGORITHM,
|
|
80
|
+
password_str.encode("utf-8"),
|
|
81
|
+
salt,
|
|
82
|
+
iterations,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
return secrets.compare_digest(new_hash, stored_hash)
|
|
86
|
+
except (ValueError, TypeError):
|
|
87
|
+
return False
|
|
@@ -5,7 +5,6 @@ Provides validation functions for common input types like email,
|
|
|
5
5
|
project names, URLs, etc. All validators raise ValueError on invalid input.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from __future__ import annotations
|
|
9
8
|
|
|
10
9
|
import re
|
|
11
10
|
from ipaddress import IPv4Address, IPv6Address, ip_address
|
|
@@ -283,6 +282,7 @@ def validate_url(
|
|
|
283
282
|
|
|
284
283
|
try:
|
|
285
284
|
parsed = urlparse(url)
|
|
285
|
+
_ = parsed.port
|
|
286
286
|
except ValueError as e:
|
|
287
287
|
msg = f"Invalid URL format: {e}"
|
|
288
288
|
raise ValueError(msg) from e
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Utility modules for Stack."""
|
|
2
|
+
|
|
3
|
+
from .filesystem import ensure_dir, safe_read, safe_write
|
|
4
|
+
from .logging import get_logger, setup_logging
|
|
5
|
+
from .retry import Retrier, RetryConfig, RetryError, retry
|
|
6
|
+
from .subprocess import SafeCommandResult, run_safe_command
|
|
7
|
+
|
|
8
|
+
__all__ = (
|
|
9
|
+
"Retrier",
|
|
10
|
+
"RetryConfig",
|
|
11
|
+
"RetryError",
|
|
12
|
+
"SafeCommandResult",
|
|
13
|
+
"ensure_dir",
|
|
14
|
+
"get_logger",
|
|
15
|
+
"retry",
|
|
16
|
+
"run_safe_command",
|
|
17
|
+
"safe_read",
|
|
18
|
+
"safe_write",
|
|
19
|
+
"setup_logging",
|
|
20
|
+
)
|
|
@@ -5,7 +5,6 @@ Provides a configured logger with support for structured output,
|
|
|
5
5
|
context propagation, and proper formatting.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from __future__ import annotations
|
|
9
8
|
|
|
10
9
|
import logging
|
|
11
10
|
import sys
|
|
@@ -68,7 +67,7 @@ class StackLogger:
|
|
|
68
67
|
self._logger.setLevel(getattr(logging, level.upper()))
|
|
69
68
|
self._structured = False
|
|
70
69
|
|
|
71
|
-
def bind(self, **context: Any) -> StackLogger:
|
|
70
|
+
def bind(self, **context: Any) -> "StackLogger":
|
|
72
71
|
"""Add context to logger.
|
|
73
72
|
|
|
74
73
|
Args:
|
|
@@ -83,7 +82,7 @@ class StackLogger:
|
|
|
83
82
|
self._logger = self._logger.bind(**context)
|
|
84
83
|
return self
|
|
85
84
|
|
|
86
|
-
def unbind(self, *keys: str) -> StackLogger:
|
|
85
|
+
def unbind(self, *keys: str) -> "StackLogger":
|
|
87
86
|
"""Remove context keys.
|
|
88
87
|
|
|
89
88
|
Args:
|
|
@@ -6,7 +6,6 @@ application performance and health. Compatible with any
|
|
|
6
6
|
Python framework.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
from __future__ import annotations
|
|
10
9
|
|
|
11
10
|
import functools
|
|
12
11
|
import logging
|
|
@@ -84,11 +83,11 @@ class MetricsCollector:
|
|
|
84
83
|
|
|
85
84
|
"""
|
|
86
85
|
|
|
87
|
-
_instance: MetricsCollector | None = None
|
|
86
|
+
_instance: "MetricsCollector | None" = None
|
|
88
87
|
_lock = threading.Lock()
|
|
89
88
|
_initialized: bool
|
|
90
89
|
|
|
91
|
-
def __new__(cls) -> MetricsCollector:
|
|
90
|
+
def __new__(cls) -> "MetricsCollector":
|
|
92
91
|
"""Singleton pattern for global metrics access."""
|
|
93
92
|
if cls._instance is None:
|
|
94
93
|
with cls._lock:
|
|
@@ -130,7 +129,7 @@ class MetricsCollector:
|
|
|
130
129
|
"""Record a timing measurement."""
|
|
131
130
|
self._timers[name].record(duration)
|
|
132
131
|
|
|
133
|
-
def timer(self, name: str) -> Timer:
|
|
132
|
+
def timer(self, name: str) -> "Timer":
|
|
134
133
|
"""Create a context manager timer."""
|
|
135
134
|
return Timer(name, self)
|
|
136
135
|
|
|
@@ -183,7 +182,7 @@ class Timer:
|
|
|
183
182
|
self.collector = collector
|
|
184
183
|
self.start_time: float = 0.0
|
|
185
184
|
|
|
186
|
-
def __enter__(self) -> Timer:
|
|
185
|
+
def __enter__(self) -> "Timer":
|
|
187
186
|
"""Start the timer."""
|
|
188
187
|
self.start_time = time.perf_counter()
|
|
189
188
|
return self
|
|
@@ -6,7 +6,6 @@ with configurable backoff strategies. Compatible with any
|
|
|
6
6
|
Python framework (sync and async).
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
from __future__ import annotations
|
|
10
9
|
|
|
11
10
|
import functools
|
|
12
11
|
import logging
|
|
@@ -301,7 +300,7 @@ class Retrier:
|
|
|
301
300
|
self.attempt = 0
|
|
302
301
|
self.last_exception: Exception | None = None
|
|
303
302
|
|
|
304
|
-
def __enter__(self) -> Retrier:
|
|
303
|
+
def __enter__(self) -> "Retrier":
|
|
305
304
|
"""Enter the retry context."""
|
|
306
305
|
self.attempt = 0
|
|
307
306
|
self.last_exception = None
|
|
@@ -5,7 +5,6 @@ Provides secure wrappers around subprocess execution with
|
|
|
5
5
|
command validation, timeout handling, and retry logic.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from __future__ import annotations
|
|
9
8
|
|
|
10
9
|
import shutil
|
|
11
10
|
import subprocess
|
|
@@ -42,7 +41,7 @@ class SafeCommandResult:
|
|
|
42
41
|
"""Check if command succeeded."""
|
|
43
42
|
return self.returncode == 0
|
|
44
43
|
|
|
45
|
-
def raise_on_error(self) -> SafeCommandResult:
|
|
44
|
+
def raise_on_error(self) -> "SafeCommandResult":
|
|
46
45
|
"""Raise an exception if command failed.
|
|
47
46
|
|
|
48
47
|
Returns:
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"""Utility modules for Stack."""
|
|
2
|
-
|
|
3
|
-
from taipanstack.utils.filesystem import ensure_dir, safe_read, safe_write
|
|
4
|
-
from taipanstack.utils.logging import get_logger, setup_logging
|
|
5
|
-
from taipanstack.utils.retry import Retrier, RetryConfig, RetryError, retry
|
|
6
|
-
from taipanstack.utils.subprocess import SafeCommandResult, run_safe_command
|
|
7
|
-
|
|
8
|
-
__all__ = [
|
|
9
|
-
# Retry
|
|
10
|
-
"Retrier",
|
|
11
|
-
"RetryConfig",
|
|
12
|
-
"RetryError",
|
|
13
|
-
# Subprocess
|
|
14
|
-
"SafeCommandResult",
|
|
15
|
-
# Filesystem
|
|
16
|
-
"ensure_dir",
|
|
17
|
-
# Logging
|
|
18
|
-
"get_logger",
|
|
19
|
-
"retry",
|
|
20
|
-
"run_safe_command",
|
|
21
|
-
"safe_read",
|
|
22
|
-
"safe_write",
|
|
23
|
-
"setup_logging",
|
|
24
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|