mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-21 07:41:28 +02:00
Choosing what a report contains required editing a template. That is the wrong place for a decision made per report, and the scan launch flow already established the alternative: a saved configuration seeds the run, the run may depart from it, and the saved configuration is never touched. Three declarations put sections on the same footing as stages. SectionRole separates the content a reader asked for from the furniture around it, so a picker can offer twenty-one choices and include the cover, the contents and the reference matter without being asked. Section.order fixes the reading order, which until now was however the directories happened to sort — the executive summary came after attack paths because "a" precedes "e". Section.launch_fields names the settings worth surfacing when the report is generated rather than only in the builder, mirroring Stage.launch_fields; the findings section declares its severities, its detail depth, its roll-up and its asset cap. The estimate had to become honest for any of this to be worth showing. It counted every finding in the scan whatever the section filtered to, so dropping three severities moved nothing. It now counts through the same severity filter the section applies and prices each tier separately, from the real per-severity issue counts rather than an assumed split: 28 pages against 26 rendered for a full template, 10 against 9 for critical and high alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AW5pitnosX8LEFEYxH8gFS
90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
from reports.base import RenderContext, Section
|
|
from reports.config import SectionConfig, choice, flag, text
|
|
from shared.definitions.reports import SectionGroup, SectionRole
|
|
|
|
|
|
class CoverConfig(SectionConfig):
|
|
show_logo: bool = flag(
|
|
True, title="Show logo", description="Print the uploaded logo on the cover."
|
|
)
|
|
show_meta: bool = flag(
|
|
True,
|
|
title="Show detail block",
|
|
description="Client, author, date and document reference.",
|
|
)
|
|
show_classification: bool = flag(True, title="Show classification banner")
|
|
show_grade: bool = flag(
|
|
True,
|
|
title="Show the posture grade",
|
|
description="The letter grade and score on the cover, when vulnerabilities were assessed.",
|
|
)
|
|
kicker: str = text(
|
|
"Attack surface report",
|
|
title="Kicker",
|
|
description="The small line above the title.",
|
|
)
|
|
date_style: str = choice(
|
|
"long",
|
|
title="Date format",
|
|
options={
|
|
"long": "12 September 2026",
|
|
"short": "12 Sep 2026",
|
|
"iso": "2026-09-12",
|
|
"none": "No date",
|
|
},
|
|
)
|
|
|
|
|
|
def _grade(ctx: RenderContext) -> dict | None:
|
|
assessed = any(
|
|
c["covered"] for c in ctx.brief.coverage if c["dimension"] == "vulnerabilities"
|
|
)
|
|
if not assessed:
|
|
return None
|
|
posture = ctx.brief.posture
|
|
return {"letter": posture.grade, "score": posture.score}
|
|
|
|
|
|
class CoverSection(Section):
|
|
name = "cover"
|
|
title = "Cover"
|
|
description = "The title page. Layout and artwork come from the theme."
|
|
group = SectionGroup.FRONT_MATTER.value
|
|
order = 10
|
|
role = SectionRole.FURNITURE.value
|
|
in_toc = False
|
|
config_model = CoverConfig
|
|
|
|
def build(self, ctx: RenderContext, cfg: CoverConfig) -> dict:
|
|
branding = ctx.branding
|
|
fmt = {"long": "%d %B %Y", "short": "%d %b %Y", "iso": "%Y-%m-%d"}.get(
|
|
cfg.date_style
|
|
)
|
|
meta: list[tuple[str, str]] = []
|
|
if cfg.show_meta:
|
|
pairs = (
|
|
("Prepared for", branding.prepared_for or branding.client_name),
|
|
("Prepared by", branding.prepared_by or branding.company_name),
|
|
("Assessed", ctx.data.observed_label),
|
|
("Report date", ctx.now.strftime(fmt) if fmt else ""),
|
|
("Reference", branding.document_id),
|
|
("Version", branding.version),
|
|
)
|
|
meta = [(label, value) for label, value in pairs if value]
|
|
return {
|
|
"bare": True,
|
|
"kicker": cfg.kicker,
|
|
"meta": meta,
|
|
"logo": branding.company_logo if cfg.show_logo else "",
|
|
"classification": branding.classification
|
|
if cfg.show_classification
|
|
else "",
|
|
"art": ctx.theme.cover.art,
|
|
"background": ctx.style.cover_image,
|
|
"grade": _grade(ctx) if cfg.show_grade else None,
|
|
"layout": ctx.theme.cover.layout,
|
|
"accent_bar": ctx.theme.cover.accent_bar,
|
|
}
|