import html
import json
import sys
STYLE = """"""
def rows(results, state):
for c in results:
note = c["check_result"].get("suppress_comment", "") if state == "SKIPPED" else ""
yield (
f"
| {state} | {c['check_id']} | "
f"{html.escape(c['check_name'])} | {html.escape(c['resource'])} | "
f"{c['file_line_range'][0]}-{c['file_line_range'][1]} | {html.escape(note)} |
"
)
report_json, out, title = sys.argv[1:4]
d = json.load(open(report_json, encoding="utf-8"))
s, r = d["summary"], d["results"]
body = list(rows(r.get("failed_checks", []), "FAILED")) + list(rows(r.get("skipped_checks", []), "SKIPPED"))
page = (
f"Checkov 결과{STYLE}{html.escape(title)}
"
f"통과 {s['passed']}
실패 {s['failed']}
"
f"
예외 {s['skipped']}
"
f"| 상태 | 검사 ID | 검사 내용 | 리소스 | 줄 | 예외 사유 |
{''.join(body)}
"
)
open(out, "w", encoding="utf-8").write(page)