2020-01-07 15:13:57 -08:00
|
|
|
package operator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/golang/glog"
|
|
|
|
kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1"
|
|
|
|
"github.com/nirmata/kyverno/pkg/engine/context"
|
|
|
|
)
|
|
|
|
|
2020-01-24 12:05:53 -08:00
|
|
|
//OperatorHandler provides interface to manage types
|
2020-01-07 15:13:57 -08:00
|
|
|
type OperatorHandler interface {
|
|
|
|
Evaluate(key, value interface{}) bool
|
|
|
|
validateValuewithBoolPattern(key bool, value interface{}) bool
|
|
|
|
validateValuewithIntPattern(key int64, value interface{}) bool
|
|
|
|
validateValuewithFloatPattern(key float64, value interface{}) bool
|
|
|
|
validateValueWithMapPattern(key map[string]interface{}, value interface{}) bool
|
|
|
|
validateValueWithSlicePattern(key []interface{}, value interface{}) bool
|
|
|
|
}
|
|
|
|
|
2020-01-24 12:05:53 -08:00
|
|
|
//VariableSubstitutionHandler defines the handler function for variable substitution
|
2020-02-14 11:59:28 -08:00
|
|
|
type VariableSubstitutionHandler = func(ctx context.EvalInterface, pattern interface{}) (interface{}, error)
|
2020-01-07 15:13:57 -08:00
|
|
|
|
2020-01-24 12:05:53 -08:00
|
|
|
//CreateOperatorHandler returns the operator handler based on the operator used in condition
|
2020-01-07 15:13:57 -08:00
|
|
|
func CreateOperatorHandler(ctx context.EvalInterface, op kyverno.ConditionOperator, subHandler VariableSubstitutionHandler) OperatorHandler {
|
|
|
|
switch op {
|
|
|
|
case kyverno.Equal:
|
|
|
|
return NewEqualHandler(ctx, subHandler)
|
|
|
|
case kyverno.NotEqual:
|
|
|
|
return NewNotEqualHandler(ctx, subHandler)
|
|
|
|
default:
|
|
|
|
glog.Errorf("unsupported operator: %s", string(op))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|