1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

Fixed issue with checking parentheses

This commit is contained in:
Maxim Goncharenko 2019-05-16 21:36:30 +03:00
parent 7f3500a6fb
commit 354287ebb4

View file

@ -67,6 +67,10 @@ func validateMap(resourcePart, patternPart interface{}) bool {
} }
for key, value := range pattern { for key, value := range pattern {
if wrappedWithParentheses(key) {
key = key[1 : len(key)-1]
}
if !validateMapElement(resource[key], value) { if !validateMapElement(resource[key], value) {
return false return false
} }
@ -103,8 +107,9 @@ func validateArray(resourcePart, patternPart interface{}) bool {
continue continue
} }
// CHECK OBJECT WITH PATTERN WITHOUT PARENTHESES if !validateMap(resource, pattern) {
return false
}
} }
return true return true
@ -147,10 +152,6 @@ func validateMapElement(resourcePart, patternPart interface{}) bool {
return false return false
} }
if wrappedWithParentheses(pattern) {
pattern = pattern[1 : len(pattern)-2]
}
return checkSingleValue(str, pattern) return checkSingleValue(str, pattern)
default: default:
fmt.Printf("Validating error: unknown type in map: %T\n", patternPart) fmt.Printf("Validating error: unknown type in map: %T\n", patternPart)
@ -158,27 +159,21 @@ func validateMapElement(resourcePart, patternPart interface{}) bool {
} }
} }
func getAnchorsFromMap(pattern map[string]interface{}) (map[string]string, error) { func getAnchorsFromMap(pattern map[string]interface{}) (map[string]interface{}, error) {
result := make(map[string]string) result := make(map[string]interface{})
for key, value := range pattern { for key, value := range pattern {
if wrappedWithParentheses(key) { if wrappedWithParentheses(key) {
result[key] = value
str, ok := value.(string)
if !ok {
return result, fmt.Errorf("Validating error: anchors must have string value, found %T", value)
}
result[key] = str
} }
} }
return result, nil return result, nil
} }
func skipArrayObject(object map[string]interface{}, anchors map[string]string) bool { func skipArrayObject(object, anchors map[string]interface{}) bool {
for wrappedKey, pattern := range anchors { for key, pattern := range anchors {
key := wrappedKey[1 : len(wrappedKey)-2] key = key[1 : len(key)-1]
value, ok := object[key] value, ok := object[key]
if !ok { if !ok {