mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
28 lines
859 B
Go
28 lines
859 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/kubescape/go-logger/helpers"
|
|
"github.com/kubescape/kubescape/v2/core/cautils"
|
|
reporthandlingapis "github.com/kubescape/opa-utils/reporthandling/apis"
|
|
)
|
|
|
|
var ErrUnknownSeverity = fmt.Errorf("unknown severity. Supported severities are: %s", strings.Join(reporthandlingapis.GetSupportedSeverities(), ", "))
|
|
|
|
// validateSeverity returns an error if a given severity is not known, nil otherwise
|
|
func ValidateSeverity(severity string) error {
|
|
for _, val := range reporthandlingapis.GetSupportedSeverities() {
|
|
if strings.EqualFold(severity, val) {
|
|
return nil
|
|
}
|
|
}
|
|
return ErrUnknownSeverity
|
|
|
|
}
|
|
|
|
func TerminateOnExceedingSeverity(scanInfo *cautils.ScanInfo, l helpers.ILogger) {
|
|
l.Fatal("result exceeds severity threshold", helpers.String("Set severity threshold", scanInfo.FailThresholdSeverity))
|
|
}
|