forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 2
/
notin.go
81 lines (66 loc) · 2.13 KB
/
notin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
func (nin NotInHandler) Evaluate(key, value interface{}) bool {
var err error
// substitute the variables
if key, err = nin.subHandler(nin.log, nin.ctx, key); err != nil {
nin.log.Error(err, "Failed to resolve variable", "variable", key)
return false
}
if value, err = nin.subHandler(nin.log, nin.ctx, value); err != nil {
nin.log.Error(err, "Failed to resolve variable", "variable", value)
return false
}
switch typedKey := key.(type) {
case string:
return nin.validateValuewithStringPattern(typedKey, value)
default:
nin.log.Info("Unsupported type", "value", typedKey, "type", fmt.Sprintf("%T", typedKey))
return false
}
}
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
}
if !keyExists {
return true
}
return false
}
func (nin NotInHandler) validateValuewithBoolPattern(key bool, value interface{}) bool {
return false
}
func (nin NotInHandler) validateValuewithIntPattern(key int64, value interface{}) bool {
return false
}
func (nin NotInHandler) validateValuewithFloatPattern(key float64, value interface{}) bool {
return false
}
func (nin NotInHandler) validateValueWithMapPattern(key map[string]interface{}, value interface{}) bool {
return false
}
func (nin NotInHandler) validateValueWithSlicePattern(key []interface{}, value interface{}) bool {
return false
}