2020-01-07 15:13:57 -08:00
|
|
|
package operator
|
|
|
|
|
|
|
|
import (
|
2020-03-17 11:05:20 -07:00
|
|
|
"github.com/go-logr/logr"
|
2020-01-07 15:13:57 -08:00
|
|
|
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-03-17 11:05:20 -07:00
|
|
|
type VariableSubstitutionHandler = func(log logr.Logger, 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-03-17 11:05:20 -07:00
|
|
|
func CreateOperatorHandler(log logr.Logger, ctx context.EvalInterface, op kyverno.ConditionOperator, subHandler VariableSubstitutionHandler) OperatorHandler {
|
2020-01-07 15:13:57 -08:00
|
|
|
switch op {
|
|
|
|
case kyverno.Equal:
|
2020-03-17 11:05:20 -07:00
|
|
|
return NewEqualHandler(log, ctx, subHandler)
|
2020-01-07 15:13:57 -08:00
|
|
|
case kyverno.NotEqual:
|
2020-03-17 11:05:20 -07:00
|
|
|
return NewNotEqualHandler(log, ctx, subHandler)
|
2020-05-06 22:43:17 +05:30
|
|
|
case kyverno.Equals:
|
|
|
|
return NewEqualHandler(log, ctx, subHandler)
|
|
|
|
case kyverno.NotEquals:
|
|
|
|
return NewNotEqualHandler(log, ctx, subHandler)
|
2020-06-12 15:48:19 +05:30
|
|
|
case kyverno.In:
|
|
|
|
return NewInHandler(log, ctx, subHandler)
|
|
|
|
case kyverno.NotIn:
|
|
|
|
return NewNotInHandler(log, ctx, subHandler)
|
2020-01-07 15:13:57 -08:00
|
|
|
default:
|
2020-03-17 11:05:20 -07:00
|
|
|
log.Info("operator not supported", "operator", string(op))
|
2020-01-07 15:13:57 -08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|