Coverage for src \ sec_report_kit \ parsers \ tfsec.py: 100%
16 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 08:06 +0530
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 08:06 +0530
1from __future__ import annotations
3from sec_report_kit.models import Finding
4from sec_report_kit.services.normalize import normalize_severity
7def parse_tfsec_json(data: dict) -> list[Finding]:
8 findings: list[Finding] = []
10 for issue in data.get("results", []) if isinstance(data, dict) else []:
11 location = issue.get("location") if isinstance(issue.get("location"), dict) else {}
12 filename = str(location.get("filename") or issue.get("location") or "infrastructure-code")
13 start_line = location.get("start_line")
14 title = str(issue.get("description") or issue.get("rule_description") or "tfsec finding")
15 if isinstance(start_line, int):
16 title = f"{title} ({filename}:{start_line})"
18 links = issue.get("links") if isinstance(issue.get("links"), list) else []
19 primary_url = str(links[0]) if links else ""
21 findings.append(
22 Finding(
23 source_type="tfsec-iac",
24 target=filename,
25 severity=normalize_severity(issue.get("severity")),
26 vulnerability_id=str(issue.get("rule_id") or "-"),
27 package=str(issue.get("rule_id") or "tfsec-rule"),
28 installed_version="-",
29 fixed_version="-",
30 title=title,
31 primary_url=primary_url,
32 )
33 )
35 return findings