1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/pkg/engine/variables/operator/notin.go

82 lines
2.1 KiB
Go
Raw Normal View History

2020-06-12 15:48:19 +05:30
package operator
import (
"fmt"
"github.com/go-logr/logr"
"github.com/nirmata/kyverno/pkg/engine/context"
)
//NewNotInHandler returns handler to manage NotIn operations
func NewNotInHandler(log logr.Logger, ctx context.EvalInterface, subHandler VariableSubstitutionHandler) OperatorHandler {
return NotInHandler{
ctx: ctx,
subHandler: subHandler,
log: log,
}
}
//NotInHandler provides implementation to handle NotIn Operator
type NotInHandler struct {
ctx context.EvalInterface
subHandler VariableSubstitutionHandler
log logr.Logger
}
//Evaluate evaluates expression with NotIn Operator
2020-06-24 12:27:08 +05:30
func (nin NotInHandler) Evaluate(key, value interface{}) bool {
2020-06-12 15:48:19 +05:30
var err error
// substitute the variables
2020-06-24 12:27:08 +05:30
if key, err = nin.subHandler(nin.log, nin.ctx, key); err != nil {
nin.log.Error(err, "Failed to resolve variable", "variable", key)
2020-06-12 15:48:19 +05:30
return false
}
2020-06-24 12:27:08 +05:30
if value, err = nin.subHandler(nin.log, nin.ctx, value); err != nil {
nin.log.Error(err, "Failed to resolve variable", "variable", value)
2020-06-12 15:48:19 +05:30
return false
}
2020-06-26 12:33:49 +05:30
2020-06-12 15:48:19 +05:30
switch typedKey := key.(type) {
case string:
2020-06-24 12:27:08 +05:30
return nin.validateValuewithStringPattern(typedKey, value)
2020-06-12 15:48:19 +05:30
default:
2020-06-24 12:27:08 +05:30
nin.log.Info("Unsupported type", "value", typedKey, "type", fmt.Sprintf("%T", typedKey))
2020-06-12 15:48:19 +05:30
return false
}
2020-06-24 12:27:08 +05:30
2020-06-12 15:48:19 +05:30
}
2020-06-24 12:27:08 +05:30
func (nin NotInHandler) validateValuewithStringPattern(key string, value interface{}) bool {
invalidType, keyExists := ValidateStringPattern(key, value)
if invalidType {
nin.log.Info("expected type []string", "value", value, "type", fmt.Sprintf("%T", value))
return false
2020-06-12 15:48:19 +05:30
}
2020-06-24 12:27:08 +05:30
if !keyExists {
return true
}
2020-06-26 12:33:49 +05:30
2020-06-12 15:48:19 +05:30
return false
}
2020-06-24 12:27:08 +05:30
func (nin NotInHandler) validateValuewithBoolPattern(key bool, value interface{}) bool {
2020-06-12 15:48:19 +05:30
return false
}
2020-06-24 12:27:08 +05:30
func (nin NotInHandler) validateValuewithIntPattern(key int64, value interface{}) bool {
2020-06-12 15:48:19 +05:30
return false
}
2020-06-24 12:27:08 +05:30
func (nin NotInHandler) validateValuewithFloatPattern(key float64, value interface{}) bool {
2020-06-12 15:48:19 +05:30
return false
}
2020-06-24 12:27:08 +05:30
func (nin NotInHandler) validateValueWithMapPattern(key map[string]interface{}, value interface{}) bool {
return false
2020-06-12 15:48:19 +05:30
}
2020-06-24 12:27:08 +05:30
func (nin NotInHandler) validateValueWithSlicePattern(key []interface{}, value interface{}) bool {
return false
2020-06-12 15:48:19 +05:30
}