From 41dfdfd1e8c49b48738be4d32a241f51c6fdce0e Mon Sep 17 00:00:00 2001 From: dwertent Date: Mon, 25 Oct 2021 15:14:31 +0300 Subject: [PATCH] support more than score --- resultshandling/printer/jsonprinter.go | 2 +- resultshandling/printer/junit.go | 2 +- resultshandling/results.go | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) 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..80802357 100644 --- a/resultshandling/results.go +++ b/resultshandling/results.go @@ -38,14 +38,16 @@ func (resultsHandler *ResultsHandler) HandleResults(scanInfo *cautils.ScanInfo) // CalculatePostureScore calculate final score func CalculatePostureScore(postureReport *reporthandling.PostureReport) float32 { - totalResources := 0 - totalFailed := 0 + lowestScore := float32(0) for _, frameworkReport := range postureReport.FrameworkReports { - totalFailed += frameworkReport.GetNumberOfFailedResources() - totalResources += frameworkReport.GetNumberOfResources() + totalFailed := frameworkReport.GetNumberOfFailedResources() + totalResources := frameworkReport.GetNumberOfResources() + + frameworkScore := (float32(totalResources) - float32(totalFailed)) / float32(totalResources) + if lowestScore > frameworkScore || frameworkScore == 0 { + frameworkScore = lowestScore + } } - if totalResources == 0 { - return float32(0) - } - return (float32(totalResources) - float32(totalFailed)) / float32(totalResources) + + return lowestScore }