feat(reports): store and browse report artifacts

This commit is contained in:
zwitschi committed 2026-11-06 12:27:00 +01:00
1 parent 5967a43eb5
commit 6f2e479958
13 files changed
+875 -93

No files matched your search

+16
View File
@@ -20,6 +20,7 @@ import re
import subprocess
from datetime import datetime
from typing import Any, Iterable
import hashlib
from .files import write_json
from .reporting import timestamp_name
@@ -151,6 +152,7 @@ def write_blocklist_report(report_dir: str,
firewall_changes: dict | None = None,
dry_run: bool = False,
errors: Iterable[str] = (),
scan_id: int | None = None,
) -> str:
"""Write the timestamped blocklist report to ``<report_dir>/app/``.
@@ -183,4 +185,18 @@ def write_blocklist_report(report_dir: str,
os.makedirs(app_dir, exist_ok=True)
path = os.path.join(app_dir, f"{timestamp_name()}.json")
write_json(path, payload)
try:
from ..db import get_connection
from ..db import repositories as repo
with open(path, "rb") as file:
content = file.read()
repo.insert_report_artifact(
get_connection(), source="app", report_type="blocklist_change",
generated_at=payload["generated_at"], payload=payload,
original_path=f"app/{os.path.basename(path)}",
content_sha256=hashlib.sha256(content).hexdigest(),
scan_id=scan_id,
)
except Exception as exc:
print(f"WARN: blocklist report DB write skipped ({exc})")
return path