Files
polaris/pkg/config/exemptions.go
hgoscenski-vailandGitHub 0a0720a26c Adds option to exempt an entire controller from checks via config file (#350)
This adds the ability to exempt a controller from all checks similar to
the annotation for "exempt" which exempts all checks.

I added the tests to go with this as well as for the IsActionable
function.
2020-06-22 14:18:23 -04:00

37 lines
806 B
Go

package config
import (
"strings"
)
// IsActionable determines whether a check is actionable given the current configuration
func (conf Configuration) IsActionable(ruleID, controllerName string) bool {
if severity, ok := conf.Checks[ruleID]; !ok || !severity.IsActionable() {
return false
}
if conf.DisallowExemptions {
return true
}
for _, example := range conf.Exemptions {
for _, rule := range example.Rules {
if rule != ruleID {
continue
}
for _, controller := range example.ControllerNames {
if strings.HasPrefix(controllerName, controller) {
return false
}
}
}
if len(example.Rules) == 0 {
for _, controller := range example.ControllerNames {
if strings.HasPrefix(controllerName, controller) {
return false
}
}
}
}
return true
}