taipanstack 0.4.9__tar.gz → 0.5.0__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.4.9 → taipanstack-0.5.0}/PKG-INFO +9 -10
- {taipanstack-0.4.9 → taipanstack-0.5.0}/README.md +8 -9
- {taipanstack-0.4.9 → taipanstack-0.5.0}/pyproject.toml +11 -33
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/__init__.py +1 -1
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/bridges/db_bridge.py +23 -12
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/bridges/http_bridge.py +5 -8
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/bridges/web_bridge.py +4 -6
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/config/generators.py +9 -10
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/config/models.py +4 -4
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/core/optimizations.py +33 -20
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/core/result.py +10 -21
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/adaptive_breaker.py +5 -6
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/orchestrator.py +13 -15
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/circuit_breaker.py +37 -34
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/resilience.py +8 -10
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/retry.py +41 -24
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/config_watcher.py +15 -21
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/health_pinger.py +18 -20
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/resource_watcher.py +4 -5
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/guards.py +8 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/jwt.py +24 -4
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/types.py +5 -6
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/validators.py +1 -1
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/cache.py +23 -30
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/filesystem.py +9 -7
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/logging.py +6 -7
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/rate_limit.py +7 -2
- {taipanstack-0.4.9 → taipanstack-0.5.0}/LICENSE +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/bridges/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/bridges/_imports.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/config/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/config/version_config.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/core/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/core/compat.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/adaptive_retry.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/bulkhead.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/_base.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/decorators.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/models.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/password.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/security/sanitizers.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/__init__.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/circuit_breaker.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/concurrency.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/context.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/resilience.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/retry.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/serialization.py +0 -0
- {taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/utils/subprocess.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: taipanstack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: TaipanStack - Modular, secure, and scalable Python stack for robust development
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -87,12 +87,11 @@ Description-Content-Type: text/markdown
|
|
|
87
87
|
|
|
88
88
|
Taipan Stack is a battle-tested foundation for production-grade Python projects that combines **security**, **performance**, and **developer experience** into a single, cohesive toolkit.
|
|
89
89
|
|
|
90
|
-
### ✨ What's New in v0.
|
|
91
|
-
- **
|
|
92
|
-
- **
|
|
93
|
-
- **
|
|
94
|
-
- **
|
|
95
|
-
- **Total Stack Quality**: Expanded to **1,331 passing tests** with 100% verified genuine coverage across all modules.
|
|
90
|
+
### ✨ What's New in v0.5.0
|
|
91
|
+
- **Security Hardening**: Hardened path traversal protection (PR #741) and JWT encoding/decoding logic (PR #775) against malformed inputs; fixed IndexError on project validator (PR #768).
|
|
92
|
+
- **Resilience Enhancements**: Frozen circuit breaker configuration to prevent runtime mutations under chaos (PR #778) and resolved double-wrapping of Result objects in ResilienceOrchestrator (PR #767).
|
|
93
|
+
- **Clean Code & Type Guards**: Enforced strict isinstance type checks to replace match/case result matching (PR #746, #763, #777) and optimized modules to reduce complexity (PR #770).
|
|
94
|
+
- **QA Suite Optimization**: Consolidated and refactored the entire test suite down to **1,225 passing tests** while maintaining absolute 100% genuine code and branch coverage (PR #773, #781, #782).
|
|
96
95
|
|
|
97
96
|
<table>
|
|
98
97
|
<tr>
|
|
@@ -129,7 +128,7 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
|
|
|
129
128
|
|
|
130
129
|
### 🔧 Developer Experience
|
|
131
130
|
- Pre-configured quality tools
|
|
132
|
-
- **100% code coverage** (1,
|
|
131
|
+
- **100% code coverage** (1,225 tests)
|
|
133
132
|
- Architecture enforcement
|
|
134
133
|
- Hardened Docker template
|
|
135
134
|
|
|
@@ -171,7 +170,7 @@ make all
|
|
|
171
170
|
### Verify Installation
|
|
172
171
|
|
|
173
172
|
```bash
|
|
174
|
-
# Run tests with 100% coverage (1,
|
|
173
|
+
# Run tests with 100% coverage (1,225 tests)
|
|
175
174
|
make test
|
|
176
175
|
|
|
177
176
|
# Check architecture contracts
|
|
@@ -224,7 +223,7 @@ TaipanStack/
|
|
|
224
223
|
│ ├── config/ # ⚙️ Configuration models & generators
|
|
225
224
|
│ ├── security/ # 🛡️ Guards, sanitizers, validators
|
|
226
225
|
│ └── utils/ # 🔧 Logging, metrics, retry, filesystem
|
|
227
|
-
├── tests/ # ✅ 1,
|
|
226
|
+
├── tests/ # ✅ 1,225 tests, 100% coverage
|
|
228
227
|
├── .semgrep/ # 🔍 Custom SAST rules
|
|
229
228
|
├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
|
|
230
229
|
├── Dockerfile # 🐳 Hardened multi-stage container
|
|
@@ -30,12 +30,11 @@
|
|
|
30
30
|
|
|
31
31
|
Taipan Stack is a battle-tested foundation for production-grade Python projects that combines **security**, **performance**, and **developer experience** into a single, cohesive toolkit.
|
|
32
32
|
|
|
33
|
-
### ✨ What's New in v0.
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **Total Stack Quality**: Expanded to **1,331 passing tests** with 100% verified genuine coverage across all modules.
|
|
33
|
+
### ✨ What's New in v0.5.0
|
|
34
|
+
- **Security Hardening**: Hardened path traversal protection (PR #741) and JWT encoding/decoding logic (PR #775) against malformed inputs; fixed IndexError on project validator (PR #768).
|
|
35
|
+
- **Resilience Enhancements**: Frozen circuit breaker configuration to prevent runtime mutations under chaos (PR #778) and resolved double-wrapping of Result objects in ResilienceOrchestrator (PR #767).
|
|
36
|
+
- **Clean Code & Type Guards**: Enforced strict isinstance type checks to replace match/case result matching (PR #746, #763, #777) and optimized modules to reduce complexity (PR #770).
|
|
37
|
+
- **QA Suite Optimization**: Consolidated and refactored the entire test suite down to **1,225 passing tests** while maintaining absolute 100% genuine code and branch coverage (PR #773, #781, #782).
|
|
39
38
|
|
|
40
39
|
<table>
|
|
41
40
|
<tr>
|
|
@@ -72,7 +71,7 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
|
|
|
72
71
|
|
|
73
72
|
### 🔧 Developer Experience
|
|
74
73
|
- Pre-configured quality tools
|
|
75
|
-
- **100% code coverage** (1,
|
|
74
|
+
- **100% code coverage** (1,225 tests)
|
|
76
75
|
- Architecture enforcement
|
|
77
76
|
- Hardened Docker template
|
|
78
77
|
|
|
@@ -114,7 +113,7 @@ make all
|
|
|
114
113
|
### Verify Installation
|
|
115
114
|
|
|
116
115
|
```bash
|
|
117
|
-
# Run tests with 100% coverage (1,
|
|
116
|
+
# Run tests with 100% coverage (1,225 tests)
|
|
118
117
|
make test
|
|
119
118
|
|
|
120
119
|
# Check architecture contracts
|
|
@@ -167,7 +166,7 @@ TaipanStack/
|
|
|
167
166
|
│ ├── config/ # ⚙️ Configuration models & generators
|
|
168
167
|
│ ├── security/ # 🛡️ Guards, sanitizers, validators
|
|
169
168
|
│ └── utils/ # 🔧 Logging, metrics, retry, filesystem
|
|
170
|
-
├── tests/ # ✅ 1,
|
|
169
|
+
├── tests/ # ✅ 1,225 tests, 100% coverage
|
|
171
170
|
├── .semgrep/ # 🔍 Custom SAST rules
|
|
172
171
|
├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
|
|
173
172
|
├── Dockerfile # 🐳 Hardened multi-stage container
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "taipanstack"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
description = "TaipanStack - Modular, secure, and scalable Python stack for robust development"
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "gabrielima7", email = "gabrielima.alu.lmb@gmail.com"}
|
|
@@ -60,18 +60,13 @@ resilience = [
|
|
|
60
60
|
"psutil (>=5.9.0)",
|
|
61
61
|
]
|
|
62
62
|
all = [
|
|
63
|
-
# runtime
|
|
64
63
|
"uvloop (>=0.19.0); sys_platform != 'win32'",
|
|
65
64
|
"structlog (>=23.0.0)",
|
|
66
|
-
# bridges-web
|
|
67
65
|
"fastapi (>=0.100.0)",
|
|
68
66
|
"litestar (>=2.0.0)",
|
|
69
|
-
# bridges-http
|
|
70
67
|
"httpx (>=0.24.0)",
|
|
71
|
-
# bridges-db
|
|
72
68
|
"sqlalchemy (>=2.0.0)",
|
|
73
69
|
"redis (>=5.0.0)",
|
|
74
|
-
# resilience
|
|
75
70
|
"psutil (>=5.9.0)",
|
|
76
71
|
]
|
|
77
72
|
|
|
@@ -95,8 +90,9 @@ dev = [
|
|
|
95
90
|
"import-linter (>=2.1)",
|
|
96
91
|
"gitingest (>=0.1.0)",
|
|
97
92
|
"pytest-asyncio (>=0.23.0)",
|
|
98
|
-
"radon (>=6.0.1,<7.0.0)",
|
|
99
93
|
"pip-audit (>=2.10.0,<3.0.0)",
|
|
94
|
+
"cyclonedx-python-lib (>=11.7.0,<12.0.0)",
|
|
95
|
+
"radon (>=6.0.1,<7.0.0)",
|
|
100
96
|
# Security: CVE fix - requests <2.33.0 has insecure temp file reuse (CWE-377)
|
|
101
97
|
# Dependabot alert #17 - CVSS 4.4/10 Moderate
|
|
102
98
|
"requests (>=2.33.0)",
|
|
@@ -107,19 +103,17 @@ dev = [
|
|
|
107
103
|
"hypothesis (>=6.151.12,<7.0.0)",
|
|
108
104
|
"authlib (>=1.6.11,<2.0.0)",
|
|
109
105
|
"cryptography (>=46.0.7,<49.0.0)",
|
|
110
|
-
"nltk (>=3.9.4,<4.0.0)",
|
|
111
106
|
"mutmut (>=3.0.0,<4.0.0)",
|
|
112
|
-
"pip (>=26.1,<27.0)",
|
|
113
107
|
]
|
|
114
108
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# --- TaipanStack v2.0 Quality Configuration ---
|
|
119
109
|
docs = [
|
|
120
110
|
"mkdocs-material (>=9.7.3,<10.0.0)",
|
|
121
111
|
"mkdocstrings[python] (>=1.0.3,<2.0.0)"
|
|
122
112
|
]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
123
117
|
[tool.ruff]
|
|
124
118
|
line-length = 88
|
|
125
119
|
target-version = "py311"
|
|
@@ -202,8 +196,7 @@ plugins = ["pydantic.mypy"]
|
|
|
202
196
|
|
|
203
197
|
[[tool.mypy.overrides]]
|
|
204
198
|
module = [
|
|
205
|
-
|
|
206
|
-
"mutmut.*",
|
|
199
|
+
"mutmut.*",
|
|
207
200
|
]
|
|
208
201
|
ignore_missing_imports = true
|
|
209
202
|
ignore_errors = true
|
|
@@ -215,7 +208,7 @@ warn_required_dynamic_aliases = true
|
|
|
215
208
|
|
|
216
209
|
[tool.pytest.ini_options]
|
|
217
210
|
testpaths = ["tests"]
|
|
218
|
-
addopts = "-v
|
|
211
|
+
addopts = "-v --strict-markers --timeout=30 --cov=src --cov-report=html --cov-report=term-missing"
|
|
219
212
|
asyncio_mode = "auto"
|
|
220
213
|
asyncio_default_fixture_loop_scope = "function"
|
|
221
214
|
markers = [
|
|
@@ -223,10 +216,6 @@ markers = [
|
|
|
223
216
|
"security: marks tests as security-related",
|
|
224
217
|
"integration: marks tests as integration tests",
|
|
225
218
|
]
|
|
226
|
-
filterwarnings = [
|
|
227
|
-
|
|
228
|
-
"ignore::pytest.PytestUnraisableExceptionWarning",
|
|
229
|
-
]
|
|
230
219
|
|
|
231
220
|
[tool.coverage.run]
|
|
232
221
|
branch = true
|
|
@@ -236,36 +225,25 @@ omit = ["*/tests/*", "*/__pycache__/*", "*/conftest.py"]
|
|
|
236
225
|
[tool.coverage.report]
|
|
237
226
|
exclude_lines = [
|
|
238
227
|
|
|
239
|
-
"def __repr__",
|
|
240
|
-
"raise NotImplementedError",
|
|
241
228
|
"if TYPE_CHECKING:",
|
|
242
229
|
"if __name__ == .__main__.:",
|
|
243
230
|
"@abstractmethod",
|
|
244
231
|
"@overload",
|
|
245
232
|
"def __call__\\(.*\\) -> .*:\\s*(?:\"\"\".*?\"\"\"\\s*)?\\.\\.\\.",
|
|
246
233
|
]
|
|
247
|
-
partial_branches = [
|
|
248
|
-
|
|
249
|
-
"case Err\\(",
|
|
250
|
-
"case Ok\\(",
|
|
251
|
-
]
|
|
252
234
|
fail_under = 100
|
|
253
235
|
show_missing = true
|
|
254
236
|
|
|
255
|
-
[tool.bandit]
|
|
256
|
-
exclude_dirs = ["tests", ".venv", "venv"]
|
|
257
|
-
skips = ["B101"]
|
|
258
237
|
|
|
259
238
|
[tool.vulture]
|
|
260
239
|
min_confidence = 80
|
|
261
240
|
paths = ["src"]
|
|
262
|
-
|
|
241
|
+
|
|
263
242
|
|
|
264
243
|
|
|
265
244
|
[tool.mutmut]
|
|
266
245
|
paths_to_mutate = ["src/taipanstack/security/sanitizers.py", "src/taipanstack/security/validators.py", "src/taipanstack/security/guards.py", "src/taipanstack/resilience/retry.py", "src/taipanstack/resilience/circuit_breaker.py"]
|
|
267
|
-
tests_dir = ["tests/
|
|
246
|
+
tests_dir = ["tests/test_property_sanitizers_operations.py", "tests/test_security_validators_operations.py", "tests/test_security_guards_operations.py", "tests/test_security_ssrf_operations.py", "tests/test_utils_retry_operations.py", "tests/test_utils_circuit_breaker_operations.py"]
|
|
268
247
|
also_copy = ["src/"]
|
|
269
248
|
runner = "python -m pytest -x -q --tb=no --timeout=10 --no-cov"
|
|
270
|
-
dict_synonyms = "Struct, NamedStruct"
|
|
271
249
|
|
|
@@ -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.
|
|
8
|
+
__version__ = "0.5.0"
|
|
9
9
|
|
|
10
10
|
from taipanstack.config.version_config import (
|
|
11
11
|
VersionRecommendations,
|
|
@@ -231,6 +231,23 @@ class ResilientRedis:
|
|
|
231
231
|
self._client = client
|
|
232
232
|
self._circuit_breaker = circuit_breaker
|
|
233
233
|
|
|
234
|
+
def _check_redis_dependencies(self) -> Result[None, Exception]:
|
|
235
|
+
if not _HAS_REDIS:
|
|
236
|
+
return Err(
|
|
237
|
+
ImportError(
|
|
238
|
+
"redis is required for ResilientRedis. "
|
|
239
|
+
"Install with: pip install taipanstack[bridges-db]"
|
|
240
|
+
)
|
|
241
|
+
)
|
|
242
|
+
return Ok(None)
|
|
243
|
+
|
|
244
|
+
def _check_breaker_gate(self) -> Result[None, Exception]:
|
|
245
|
+
if self._circuit_breaker is not None:
|
|
246
|
+
cb_err = _breaker_is_open(self._circuit_breaker)
|
|
247
|
+
if cb_err is not None:
|
|
248
|
+
return Err(cb_err)
|
|
249
|
+
return Ok(None)
|
|
250
|
+
|
|
234
251
|
async def execute(
|
|
235
252
|
self,
|
|
236
253
|
command: str,
|
|
@@ -246,19 +263,13 @@ class ResilientRedis:
|
|
|
246
263
|
``Ok(result)`` on success, ``Err`` on failure.
|
|
247
264
|
|
|
248
265
|
"""
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
"redis is required for ResilientRedis. "
|
|
253
|
-
"Install with: pip install taipanstack[bridges-db]"
|
|
254
|
-
)
|
|
255
|
-
)
|
|
266
|
+
dep_result = self._check_redis_dependencies()
|
|
267
|
+
if isinstance(dep_result, Err):
|
|
268
|
+
return dep_result
|
|
256
269
|
|
|
257
|
-
|
|
258
|
-
if
|
|
259
|
-
|
|
260
|
-
if cb_err is not None:
|
|
261
|
-
return Err(cb_err)
|
|
270
|
+
cb_result = self._check_breaker_gate()
|
|
271
|
+
if isinstance(cb_result, Err):
|
|
272
|
+
return cb_result
|
|
262
273
|
|
|
263
274
|
try:
|
|
264
275
|
fn = getattr(self._client, command.lower())
|
|
@@ -126,11 +126,9 @@ def _check_ssrf(url: str, ssrf_protection: bool) -> Result[None, Exception]:
|
|
|
126
126
|
return Ok(None)
|
|
127
127
|
|
|
128
128
|
ssrf_result = guard_ssrf(url)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
case Ok():
|
|
133
|
-
return Ok(None)
|
|
129
|
+
if isinstance(ssrf_result, Err):
|
|
130
|
+
return Err(ssrf_result.err_value)
|
|
131
|
+
return Ok(None)
|
|
134
132
|
|
|
135
133
|
|
|
136
134
|
def _should_retry_status(
|
|
@@ -314,9 +312,8 @@ class SafeHttpClient:
|
|
|
314
312
|
Example:
|
|
315
313
|
>>> async with SafeHttpClient() as client:
|
|
316
314
|
... result = await client.get("https://api.example.com/data")
|
|
317
|
-
...
|
|
318
|
-
...
|
|
319
|
-
... case Err(e): print(f"Error: {e}")
|
|
315
|
+
... if isinstance(result, Ok): print(result.unwrap().json())
|
|
316
|
+
... else: print(f"Error: {result.unwrap_err()}")
|
|
320
317
|
|
|
321
318
|
"""
|
|
322
319
|
|
|
@@ -14,7 +14,7 @@ from collections.abc import Awaitable, Callable, MutableMapping
|
|
|
14
14
|
from dataclasses import dataclass
|
|
15
15
|
from typing import TypeAlias, TypeVar
|
|
16
16
|
|
|
17
|
-
from taipanstack.core.result import
|
|
17
|
+
from taipanstack.core.result import Ok, Result
|
|
18
18
|
from taipanstack.utils.rate_limit import RateLimiter
|
|
19
19
|
|
|
20
20
|
logger = logging.getLogger("taipanstack.bridges.web")
|
|
@@ -90,11 +90,9 @@ def result_to_response(
|
|
|
90
90
|
{"status": 200, "data": {"id": 1}}
|
|
91
91
|
|
|
92
92
|
"""
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
case Err(error):
|
|
97
|
-
return {"status": status_err, "error": str(error)}
|
|
93
|
+
if isinstance(result, Ok):
|
|
94
|
+
return {"status": status_ok, "data": result.ok_value}
|
|
95
|
+
return {"status": status_err, "error": str(result.err_value)}
|
|
98
96
|
|
|
99
97
|
|
|
100
98
|
async def _send_json_response(
|
|
@@ -170,19 +170,18 @@ def _generate_bandit_hook(severity: str) -> str:
|
|
|
170
170
|
"""
|
|
171
171
|
|
|
172
172
|
|
|
173
|
-
def
|
|
174
|
-
"""Generate
|
|
173
|
+
def _generate_pip_audit_hook() -> str:
|
|
174
|
+
"""Generate pip-audit pre-commit hook.
|
|
175
175
|
|
|
176
176
|
Returns:
|
|
177
|
-
|
|
177
|
+
pip-audit hook YAML string.
|
|
178
178
|
|
|
179
179
|
"""
|
|
180
180
|
return """
|
|
181
|
-
- repo: https://github.com/
|
|
182
|
-
rev: '
|
|
181
|
+
- repo: https://github.com/pypa/pip-audit
|
|
182
|
+
rev: 'v2.8.0'
|
|
183
183
|
hooks:
|
|
184
|
-
- id:
|
|
185
|
-
args: ["check", "--json"]
|
|
184
|
+
- id: pip-audit
|
|
186
185
|
"""
|
|
187
186
|
|
|
188
187
|
|
|
@@ -258,8 +257,8 @@ def generate_pre_commit_config(config: StackConfig) -> str:
|
|
|
258
257
|
if config.security.enable_bandit:
|
|
259
258
|
security_hooks.append(_generate_bandit_hook(config.security.bandit_severity))
|
|
260
259
|
|
|
261
|
-
if config.security.
|
|
262
|
-
security_hooks.append(
|
|
260
|
+
if config.security.enable_pip_audit:
|
|
261
|
+
security_hooks.append(_generate_pip_audit_hook())
|
|
263
262
|
|
|
264
263
|
if config.security.enable_semgrep:
|
|
265
264
|
security_hooks.append(_generate_semgrep_hook())
|
|
@@ -323,7 +322,7 @@ We prioritize security fixes for the latest version (Rolling Release).
|
|
|
323
322
|
This project includes multiple layers of security:
|
|
324
323
|
|
|
325
324
|
- **SAST**: Bandit for static security analysis
|
|
326
|
-
- **SCA**:
|
|
325
|
+
- **SCA**: pip-audit for dependency vulnerabilities
|
|
327
326
|
- **Secrets**: detect-secrets for preventing credential leaks
|
|
328
327
|
- **Type Safety**: Mypy + Pydantic for runtime validation
|
|
329
328
|
- **Runtime Guards**: Protection against path traversal and injection
|
|
@@ -29,7 +29,7 @@ class SecurityConfig(BaseModel):
|
|
|
29
29
|
Attributes:
|
|
30
30
|
level: Security strictness level.
|
|
31
31
|
enable_bandit: Enable Bandit SAST scanner.
|
|
32
|
-
|
|
32
|
+
enable_pip_audit: Enable pip-audit dependency checker.
|
|
33
33
|
enable_semgrep: Enable Semgrep analysis.
|
|
34
34
|
enable_detect_secrets: Enable secret detection.
|
|
35
35
|
bandit_severity: Minimum severity level for Bandit.
|
|
@@ -41,7 +41,7 @@ class SecurityConfig(BaseModel):
|
|
|
41
41
|
description="Security strictness level",
|
|
42
42
|
)
|
|
43
43
|
enable_bandit: bool = Field(default=True, description="Enable Bandit SAST")
|
|
44
|
-
|
|
44
|
+
enable_pip_audit: bool = Field(default=True, description="Enable pip-audit SCA")
|
|
45
45
|
enable_semgrep: bool = Field(default=True, description="Enable Semgrep")
|
|
46
46
|
enable_detect_secrets: bool = Field(
|
|
47
47
|
default=True, description="Enable secret detection"
|
|
@@ -78,7 +78,7 @@ class DependencyConfig(BaseModel):
|
|
|
78
78
|
"ruff",
|
|
79
79
|
"mypy",
|
|
80
80
|
"bandit",
|
|
81
|
-
"
|
|
81
|
+
"pip-audit",
|
|
82
82
|
"pre-commit",
|
|
83
83
|
"pytest",
|
|
84
84
|
"pytest-cov",
|
|
@@ -296,7 +296,7 @@ class StackConfig(BaseModel):
|
|
|
296
296
|
all_tools_enabled = all(
|
|
297
297
|
[
|
|
298
298
|
self.security.enable_bandit,
|
|
299
|
-
self.security.
|
|
299
|
+
self.security.enable_pip_audit,
|
|
300
300
|
self.security.enable_semgrep,
|
|
301
301
|
self.security.enable_detect_secrets,
|
|
302
302
|
]
|
|
@@ -228,13 +228,12 @@ def get_optimization_profile(*, force_refresh: bool = False) -> OptimizationProf
|
|
|
228
228
|
profile = _get_base_profile()
|
|
229
229
|
|
|
230
230
|
# Adjust for optimization level
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
_cached_optimization_profile = profile
|
|
231
|
+
if opt_level == OPT_LEVEL_NONE:
|
|
232
|
+
_cached_optimization_profile = _PROFILE_311
|
|
233
|
+
elif opt_level == OPT_LEVEL_AGGRESSIVE and experimental:
|
|
234
|
+
_cached_optimization_profile = _build_aggressive_profile(profile)
|
|
235
|
+
else:
|
|
236
|
+
_cached_optimization_profile = profile
|
|
238
237
|
|
|
239
238
|
return _cached_optimization_profile
|
|
240
239
|
|
|
@@ -274,14 +273,19 @@ def _apply_gc_freeze(
|
|
|
274
273
|
errors: list[str],
|
|
275
274
|
) -> None:
|
|
276
275
|
"""Apply GC freeze if supported."""
|
|
277
|
-
if profile.gc_freeze_enabled
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
applied.append("gc_freeze: enabled")
|
|
281
|
-
except Exception as e:
|
|
282
|
-
errors.append(f"gc_freeze: {e}")
|
|
283
|
-
elif profile.gc_freeze_enabled and not PY312:
|
|
276
|
+
if not profile.gc_freeze_enabled:
|
|
277
|
+
return
|
|
278
|
+
if not PY312:
|
|
284
279
|
skipped.append("gc_freeze: requires Python 3.12+")
|
|
280
|
+
return
|
|
281
|
+
if not freeze_after:
|
|
282
|
+
return
|
|
283
|
+
|
|
284
|
+
try:
|
|
285
|
+
gc.freeze()
|
|
286
|
+
applied.append("gc_freeze: enabled")
|
|
287
|
+
except Exception as e:
|
|
288
|
+
errors.append(f"gc_freeze: {e}")
|
|
285
289
|
|
|
286
290
|
|
|
287
291
|
def _apply_experimental(
|
|
@@ -303,6 +307,20 @@ def _apply_experimental(
|
|
|
303
307
|
skipped.append("experimental: requires STACK_ENABLE_EXPERIMENTAL=1")
|
|
304
308
|
|
|
305
309
|
|
|
310
|
+
def _log_optimization_summary(
|
|
311
|
+
applied: list[str],
|
|
312
|
+
skipped: list[str],
|
|
313
|
+
errors: list[str],
|
|
314
|
+
) -> None:
|
|
315
|
+
"""Log the summary of applied optimizations."""
|
|
316
|
+
if applied:
|
|
317
|
+
logger.debug("Applied optimizations: %s", ", ".join(applied))
|
|
318
|
+
if skipped:
|
|
319
|
+
logger.debug("Skipped optimizations: %s", ", ".join(skipped))
|
|
320
|
+
if errors:
|
|
321
|
+
logger.warning("Optimization errors: %s", ", ".join(errors))
|
|
322
|
+
|
|
323
|
+
|
|
306
324
|
def apply_optimizations(
|
|
307
325
|
*,
|
|
308
326
|
profile: OptimizationProfile | None = None,
|
|
@@ -352,12 +370,7 @@ def apply_optimizations(
|
|
|
352
370
|
|
|
353
371
|
# Log summary
|
|
354
372
|
success = len(errors) == 0
|
|
355
|
-
|
|
356
|
-
logger.debug("Applied optimizations: %s", ", ".join(applied))
|
|
357
|
-
if skipped:
|
|
358
|
-
logger.debug("Skipped optimizations: %s", ", ".join(skipped))
|
|
359
|
-
if errors:
|
|
360
|
-
logger.warning("Optimization errors: %s", ", ".join(errors))
|
|
373
|
+
_log_optimization_summary(applied, skipped, errors)
|
|
361
374
|
|
|
362
375
|
return OptimizationResult(
|
|
363
376
|
success=success,
|
|
@@ -13,11 +13,10 @@ Example:
|
|
|
13
13
|
... raise ValueError("division by zero")
|
|
14
14
|
... return a / b
|
|
15
15
|
>>> result = divide(10, 0)
|
|
16
|
-
>>>
|
|
17
|
-
...
|
|
18
|
-
...
|
|
19
|
-
...
|
|
20
|
-
... print(f"Result: {value}")
|
|
16
|
+
>>> if isinstance(result, Err):
|
|
17
|
+
... print(f"Error: {result.err_value}")
|
|
18
|
+
... else:
|
|
19
|
+
... print(f"Result: {result.unwrap()}")
|
|
21
20
|
Error: division by zero
|
|
22
21
|
|
|
23
22
|
"""
|
|
@@ -281,14 +280,9 @@ async def map_async(
|
|
|
281
280
|
Err('fail')
|
|
282
281
|
|
|
283
282
|
"""
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
case Err(e):
|
|
288
|
-
_ = e
|
|
289
|
-
return result
|
|
290
|
-
case _:
|
|
291
|
-
return result
|
|
283
|
+
if isinstance(result, Ok):
|
|
284
|
+
return Ok(await func(result.ok_value))
|
|
285
|
+
return result
|
|
292
286
|
|
|
293
287
|
|
|
294
288
|
@overload
|
|
@@ -341,11 +335,6 @@ async def and_then_async(
|
|
|
341
335
|
Err(ValueError('No DB'))
|
|
342
336
|
|
|
343
337
|
"""
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
case Err(e):
|
|
348
|
-
_ = e
|
|
349
|
-
return result
|
|
350
|
-
case _:
|
|
351
|
-
return result
|
|
338
|
+
if isinstance(result, Ok):
|
|
339
|
+
return await func(result.ok_value)
|
|
340
|
+
return result
|
{taipanstack-0.4.9 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/adaptive_breaker.py
RENAMED
|
@@ -17,7 +17,7 @@ from collections import deque
|
|
|
17
17
|
from dataclasses import dataclass
|
|
18
18
|
from typing import TypeVar
|
|
19
19
|
|
|
20
|
-
from taipanstack.core.result import
|
|
20
|
+
from taipanstack.core.result import Ok, Result
|
|
21
21
|
from taipanstack.resilience.circuit_breaker import CircuitState
|
|
22
22
|
|
|
23
23
|
logger = logging.getLogger("taipanstack.resilience.adaptive.breaker")
|
|
@@ -171,11 +171,10 @@ class AdaptiveCircuitBreaker:
|
|
|
171
171
|
The original Result.
|
|
172
172
|
|
|
173
173
|
"""
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
self.record_failure(error)
|
|
174
|
+
if isinstance(result, Ok):
|
|
175
|
+
self.record_success()
|
|
176
|
+
else:
|
|
177
|
+
self.record_failure(result.err_value)
|
|
179
178
|
return result
|
|
180
179
|
|
|
181
180
|
def should_allow(self) -> bool:
|
|
@@ -310,15 +310,14 @@ class ResilienceOrchestrator(Generic[T]):
|
|
|
310
310
|
last_error: Exception | None = None
|
|
311
311
|
for attempt in range(1, max_attempts + 1):
|
|
312
312
|
result = await self._execute_with_timeout(fn, *args, **kwargs)
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
break
|
|
313
|
+
if isinstance(result, Ok):
|
|
314
|
+
self._record_success_outcome(attempt)
|
|
315
|
+
return result
|
|
316
|
+
|
|
317
|
+
last_error = result.err_value
|
|
318
|
+
if await self._handle_retry_failure(last_error, attempt, max_attempts):
|
|
319
|
+
continue
|
|
320
|
+
break
|
|
322
321
|
|
|
323
322
|
final_result: Result[T, Exception] = Err(
|
|
324
323
|
last_error or RuntimeError("Execution failed")
|
|
@@ -350,6 +349,9 @@ class ResilienceOrchestrator(Generic[T]):
|
|
|
350
349
|
)
|
|
351
350
|
else:
|
|
352
351
|
result = await fn(*args, **kwargs)
|
|
352
|
+
|
|
353
|
+
if isinstance(result, (Ok, Err)):
|
|
354
|
+
return cast(Result[T, Exception], result)
|
|
353
355
|
return Ok(result)
|
|
354
356
|
except TimeoutError:
|
|
355
357
|
return Err(
|
|
@@ -371,12 +373,8 @@ class ResilienceOrchestrator(Generic[T]):
|
|
|
371
373
|
Original result or ``Ok(fallback_value)``.
|
|
372
374
|
|
|
373
375
|
"""
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if self._fallback_value is not _SENTINEL:
|
|
377
|
-
return Ok(cast(T, self._fallback_value))
|
|
378
|
-
case Ok():
|
|
379
|
-
pass
|
|
376
|
+
if isinstance(result, Err) and self._fallback_value is not _SENTINEL:
|
|
377
|
+
return Ok(cast(T, self._fallback_value))
|
|
380
378
|
return result
|
|
381
379
|
|
|
382
380
|
|