Skip to content

Commit eba38f6

Browse files
committed
fix: correct mypy paths and fix line length issues in security scripts
1 parent c682284 commit eba38f6

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: uv run ruff check .
5757

5858
- name: Typecheck (mypy)
59-
run: uv run mypy src
59+
run: uv run mypy python_project_deployment
6060

6161
- name: Tests (pytest)
6262
run: uv run pytest --cov --cov-report=xml --cov-report=html
@@ -66,7 +66,7 @@ jobs:
6666
shell: bash
6767
run: |
6868
set -euo pipefail
69-
if grep -R --line-number -E "\beval\(|\bexec\(|pickle\.loads|yaml\.load(?!_safe)|subprocess\.(Popen|call)" src/ tests/ || true; then
69+
if grep -R --line-number -E "\beval\(|\bexec\(|pickle\.loads|yaml\.load(?!_safe)|subprocess\.(Popen|call)" python_project_deployment/ tests/ || true; then
7070
echo "⚠️ Potentially dangerous API usage detected. Please review." >&2
7171
exit 2
7272
fi

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ lint:
2929
uv run ruff check .
3030

3131
type:
32-
uv run mypy src
32+
uv run mypy python_project_deployment
3333

3434
format:
3535
uv run ruff format .

python_project_deployment/templates/Makefile.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ lint:
2929
uv run ruff check .
3030

3131
type:
32-
uv run mypy src
32+
uv run mypy {{ PKG }}
3333

3434
format:
3535
uv run ruff format .

scripts/security_bandit_check.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
"""Check Bandit security scan results against threshold."""
3+
4+
import json
5+
import os
6+
import sys
7+
from pathlib import Path
8+
9+
10+
def main() -> None:
11+
"""Check bandit results against SECURITY_FAIL_LEVEL threshold."""
12+
fail_level = os.getenv("SECURITY_FAIL_LEVEL", "MEDIUM").upper()
13+
severity_order = ["LOW", "MEDIUM", "HIGH"]
14+
15+
if fail_level not in severity_order:
16+
print(f"Invalid SECURITY_FAIL_LEVEL: {fail_level}")
17+
sys.exit(1)
18+
19+
threshold_index = severity_order.index(fail_level)
20+
21+
report_path = Path("bandit-report.json")
22+
if not report_path.exists():
23+
print("No bandit-report.json found, skipping.")
24+
return
25+
26+
with report_path.open() as f:
27+
data = json.load(f)
28+
29+
results = data.get("results", [])
30+
issues_above_threshold = [
31+
r for r in results if severity_order.index(r["issue_severity"]) >= threshold_index
32+
]
33+
34+
if issues_above_threshold:
35+
msg = (
36+
f"❌ Found {len(issues_above_threshold)} Bandit issues "
37+
f"at or above {fail_level} severity:"
38+
)
39+
print(msg)
40+
for issue in issues_above_threshold:
41+
location = f"{issue['filename']}:{issue['line_number']}"
42+
msg = f" - {issue['issue_text']} ({issue['issue_severity']}) in {location}"
43+
print(msg)
44+
sys.exit(1)
45+
else:
46+
print(f"✅ No Bandit issues at or above {fail_level} severity.")
47+
48+
49+
if __name__ == "__main__":
50+
main()

scripts/security_safety_check.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
"""Check Safety security scan results for vulnerabilities."""
3+
4+
import json
5+
import sys
6+
from pathlib import Path
7+
8+
9+
def main() -> None:
10+
"""Check safety results for any vulnerabilities."""
11+
report_path = Path("safety-report.json")
12+
if not report_path.exists():
13+
print("No safety-report.json found, skipping.")
14+
return
15+
16+
with report_path.open() as f:
17+
data = json.load(f)
18+
19+
vulnerabilities = data.get("vulnerabilities", [])
20+
21+
if vulnerabilities:
22+
print(f"❌ Found {len(vulnerabilities)} Safety vulnerabilities:")
23+
for vuln in vulnerabilities:
24+
pkg = vuln.get("package_name", "Unknown")
25+
issue = vuln.get("vulnerability", "Unknown issue")
26+
print(f" - {pkg}: {issue}")
27+
sys.exit(1)
28+
else:
29+
print("✅ No Safety vulnerabilities found.")
30+
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)