Skip to content

Commit 7e12785

Browse files
Merge pull request kubescape#103 from kubescape/compliance-score
support SummaryDetails risk score for backward compatibility
2 parents bfaae1e + 4cd9101 commit 7e12785

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

reporthandling/results/v1/reportsummary/datastructures.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type SummaryDetails struct {
2121
ControlsSeverityCounters SeverityCounters `json:"controlsSeverityCounters,omitempty"`
2222
StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility
2323
Score float32 `json:"score"`
24+
ComplianceScore float32 `json:"complianceScore"`
2425
}
2526

2627
// FrameworkSummary summary of scanning from a single framework perspective

reporthandling/v2/datastructures.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,18 @@ type ScanMetadata struct {
108108
// `Formats` field instead.
109109
Format string `json:"format,omitempty"`
110110
// Formats that have been requested for the output results.
111-
Formats []string `json:"formats,omitempty"`
112-
UseExceptions string `json:"useExceptions,omitempty"`
113-
Logger string `json:"logger,omitempty"`
114-
ExcludedNamespaces []string `json:"excludedNamespaces,omitempty"`
115-
IncludeNamespaces []string `json:"includeNamespaces,omitempty"`
116-
TargetNames []string `json:"targetNames,omitempty"`
117-
FailThreshold float32 `json:"failThreshold,omitempty"`
118-
ScanningTarget ScanningTarget `json:"scanningTarget,omitempty"`
119-
HostScanner bool `json:"hostScanner,omitempty"`
120-
Submit bool `json:"submit,omitempty"`
121-
VerboseMode bool `json:"verboseMode,omitempty"`
111+
Formats []string `json:"formats,omitempty"`
112+
UseExceptions string `json:"useExceptions,omitempty"`
113+
Logger string `json:"logger,omitempty"`
114+
ExcludedNamespaces []string `json:"excludedNamespaces,omitempty"`
115+
IncludeNamespaces []string `json:"includeNamespaces,omitempty"`
116+
TargetNames []string `json:"targetNames,omitempty"`
117+
FailThreshold float32 `json:"failThreshold,omitempty"`
118+
ComplianceThreshold float32 `json:"complianceThreshold,omitempty"`
119+
ScanningTarget ScanningTarget `json:"scanningTarget,omitempty"`
120+
HostScanner bool `json:"hostScanner,omitempty"`
121+
Submit bool `json:"submit,omitempty"`
122+
VerboseMode bool `json:"verboseMode,omitempty"`
122123
}
123124

124125
// Moved to apis/cloudmetadata.go

score/score.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ func max32(a, b float32) float32 {
352352

353353
// SetPostureReportComplianceScores calculates and populates scores for all controls, frameworks and whole scan.
354354
func (su *ScoreUtil) SetPostureReportComplianceScores(report *v2.PostureReport) error {
355-
// call CalculatePostureReportV2 to set frameworks.score for backward compatibility
356-
// afterwards we will override the controls.score and summeryDetails.score
357-
// and set frameworks.complianceScore
358-
// TODO: remove CalculatePostureReportV2 call after we deprecate frameworks.score
355+
// call CalculatePostureReportV2 to set frameworks.score and summaryDetails.score for backward compatibility
356+
// afterwards we will override the controls.score
357+
// and set frameworks.complianceScore and summaryDetails.complianceScore
358+
// TODO: remove CalculatePostureReportV2 call after we deprecate frameworks.score and summaryDetails.score
359359
if err := su.CalculatePostureReportV2(report); err != nil {
360360
return err
361361
}
@@ -372,7 +372,7 @@ func (su *ScoreUtil) SetPostureReportComplianceScores(report *v2.PostureReport)
372372
if len(report.SummaryDetails.Controls) > 0 {
373373
summaryScore = sumScore / float32(len(report.SummaryDetails.Controls))
374374
}
375-
report.SummaryDetails.Score = summaryScore
375+
report.SummaryDetails.ComplianceScore = summaryScore
376376
return nil
377377
}
378378

score/score_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ func TestSetPostureReportComplianceScores(t *testing.T) {
945945
})
946946

947947
t.Run("assert final score", func(t *testing.T) {
948-
assert.InDeltaf(t, expectedSummary, report.SummaryDetails.Score, 1e-6,
948+
assert.InDeltaf(t, expectedSummary, report.SummaryDetails.ComplianceScore, 1e-6,
949949
"unexpected summarized final score",
950950
)
951951
})

0 commit comments

Comments
 (0)