Class NagReportReader
<PackName>-<StackName>-NagReport.json files back off disk after
app.synth() completes, implementing ComplianceMode.ENFORCE's "blocks CDK
synthesis" behavior. app.synth() itself never throws for a cdk-nag
violation regardless of severity, so a caller has to inspect findings explicitly; this is
that inspection point.
Deliberately file-based, not an INagLogger callback. Every NagPack in SecurityRules.mapFrameworkToNagPack(String, boolean) already sets reports(true), which enables cdk-nag's
own built-in report logger (writing these exact files) with no extra registration needed.
Registering an additional INagLogger alongside that built-in one triggers a
jsii/cdk-nag runtime bug (a StackOverflowError from reentrant kernel calls, independent
of what the extra logger's callbacks do), so reading the generated report after synthesis has
already finished is both simpler and the only path that avoids it.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne row from aNagReport'slines[]array. -
Method Summary
Modifier and TypeMethodDescriptionEvery line across all*-NagReport.jsonfiles cdk-nag wrote forstackName, regardless of compliance/level -- compliant, suppressed, and warning-level lines included.readErrors(Path assemblyDirectory, String stackName) EveryNon-Compliant,Error-level line across all*-NagReport.jsonfiles cdk-nag wrote forstackNameintoassemblyDirectory-- one file per applied framework/pack, hence scanning the whole directory rather than guessing a single exact filename.
-
Method Details
-
readErrors
public static List<NagReportReader.ComplianceFinding> readErrors(Path assemblyDirectory, String stackName) EveryNon-Compliant,Error-level line across all*-NagReport.jsonfiles cdk-nag wrote forstackNameintoassemblyDirectory-- one file per applied framework/pack, hence scanning the whole directory rather than guessing a single exact filename. Compliant, suppressed, and warning-level lines are intentionally excluded -- only whatComplianceMode.ENFORCEactually needs to block on.Best-effort: a missing or unparseable report file is treated as "no findings from that file" rather than failing synthesis over a reporting problem — the same fail-soft posture the rest of this codebase's optional/best-effort reads already take.
-
readAll
public static List<NagReportReader.ComplianceFinding> readAll(Path assemblyDirectory, String stackName) Every line across all*-NagReport.jsonfiles cdk-nag wrote forstackName, regardless of compliance/level -- compliant, suppressed, and warning-level lines included. UnlikereadErrors(Path, String)(which exists to answer "must synthesis be blocked"), this exists to answer "what does a full compliance report for this stack look like", for a caller (an on-demand advisory check, not a real deploy) that wants to show the user everything cdk-nag has to say, not just what would fail an enforce-mode deploy.
-