diff --git a/resultshandling/printer/jsonprinter.go b/resultshandling/printer/jsonprinter.go index 26c4958d..ff80feb8 100644 --- a/resultshandling/printer/jsonprinter.go +++ b/resultshandling/printer/jsonprinter.go @@ -21,7 +21,7 @@ func (jsonPrinter *JsonPrinter) SetWriter(outputFile string) { } func (jsonPrinter *JsonPrinter) Score(score float32) { - fmt.Printf("\nFinal score: %d\n", int(score)) + fmt.Printf("\nFinal score: %d", int(score*100)) } func (jsonPrinter *JsonPrinter) ActionPrint(opaSessionObj *cautils.OPASessionObj) { diff --git a/resultshandling/printer/junit.go b/resultshandling/printer/junit.go index f778c972..ac03753d 100644 --- a/resultshandling/printer/junit.go +++ b/resultshandling/printer/junit.go @@ -22,7 +22,7 @@ func (junitPrinter *JunitPrinter) SetWriter(outputFile string) { } func (junitPrinter *JunitPrinter) Score(score float32) { - fmt.Printf("\nFinal score: %d\n", int(score)) + fmt.Printf("\nFinal score: %d", int(score*100)) } func (junitPrinter *JunitPrinter) ActionPrint(opaSessionObj *cautils.OPASessionObj) { diff --git a/resultshandling/results.go b/resultshandling/results.go index 25ddd3b2..1ba9aacf 100644 --- a/resultshandling/results.go +++ b/resultshandling/results.go @@ -38,14 +38,19 @@ func (resultsHandler *ResultsHandler) HandleResults(scanInfo *cautils.ScanInfo) // CalculatePostureScore calculate final score func CalculatePostureScore(postureReport *reporthandling.PostureReport) float32 { - totalResources := 0 - totalFailed := 0 + lowestScore := float32(100) for _, frameworkReport := range postureReport.FrameworkReports { - totalFailed += frameworkReport.GetNumberOfFailedResources() - totalResources += frameworkReport.GetNumberOfResources() + totalFailed := frameworkReport.GetNumberOfFailedResources() + totalResources := frameworkReport.GetNumberOfResources() + + frameworkScore := float32(0) + if float32(totalResources) > 0 { + frameworkScore = (float32(totalResources) - float32(totalFailed)) / float32(totalResources) + } + if lowestScore > frameworkScore { + lowestScore = frameworkScore + } } - if totalResources == 0 { - return float32(0) - } - return (float32(totalResources) - float32(totalFailed)) / float32(totalResources) + + return lowestScore }