Files
kubescape/core/pkg/score/score.go
Matthias Bertschy 70a9380966 fix go imports
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-09 12:14:56 +01:00

43 lines
1.1 KiB
Go

package score
import (
"fmt"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/opa-utils/score"
)
/*
provides a wrapper for scoreUtils, since there's no common interface between postureReportV1 and PostureReportV2
and the need of concrete objects
I've decided to create scoreWrapper that will allow calculating score regardless (as long as opaSessionObj is there)
*/
type ScoreWrapper struct {
scoreUtil *score.ScoreUtil
opaSessionObj *cautils.OPASessionObj
}
type PostureReportVersion string
const (
EPostureReportV1 PostureReportVersion = "v1"
EPostureReportV2 PostureReportVersion = "V2"
)
func (su *ScoreWrapper) Calculate(reportVersion PostureReportVersion) error {
if reportVersion == EPostureReportV2 {
return su.scoreUtil.SetPostureReportComplianceScores(su.opaSessionObj.Report)
}
return fmt.Errorf("unsupported score calculator")
}
func NewScoreWrapper(opaSessionObj *cautils.OPASessionObj) *ScoreWrapper {
return &ScoreWrapper{
scoreUtil: score.NewScore(opaSessionObj.AllResources),
opaSessionObj: opaSessionObj,
}
}