mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
* initial commit * variable substitution * update tests * update test * refactor engine packages for validate & generate * update vendor * update toml * support variable substitution in overlay mutation * missing update * fix indentation in logs * store context values as single JSON document using merge patches. * remove duplicate functions * fix message string * Handle processing of policies in background (#569) * remove condition check while generating mutation patch as conditions are verified in the first iteration * initial commit * background policy validation * correct message * skip non-background policy process for add/update * fix order to correct policy registration * update comment Co-authored-by: shuting <shutting06@gmail.com> * refactor Co-authored-by: shuting <shutting06@gmail.com>
67 lines
No EOL
1.3 KiB
Go
67 lines
No EOL
1.3 KiB
Go
package anchor
|
|
|
|
// Anchor function type
|
|
type IsAnchor func(str string) bool
|
|
|
|
func IsConditionAnchor(str string) bool {
|
|
if len(str) < 2 {
|
|
return false
|
|
}
|
|
|
|
return (str[0] == '(' && str[len(str)-1] == ')')
|
|
}
|
|
|
|
func IsNegationAnchor(str string) bool {
|
|
left := "X("
|
|
right := ")"
|
|
if len(str) < len(left)+len(right) {
|
|
return false
|
|
}
|
|
//TODO: trim spaces ?
|
|
return (str[:len(left)] == left && str[len(str)-len(right):] == right)
|
|
}
|
|
|
|
func IsAddingAnchor(key string) bool {
|
|
const left = "+("
|
|
const right = ")"
|
|
|
|
if len(key) < len(left)+len(right) {
|
|
return false
|
|
}
|
|
|
|
return left == key[:len(left)] && right == key[len(key)-len(right):]
|
|
}
|
|
|
|
func IsEqualityAnchor(str string) bool {
|
|
left := "=("
|
|
right := ")"
|
|
if len(str) < len(left)+len(right) {
|
|
return false
|
|
}
|
|
//TODO: trim spaces ?
|
|
return (str[:len(left)] == left && str[len(str)-len(right):] == right)
|
|
}
|
|
|
|
func IsExistanceAnchor(str string) bool {
|
|
left := "^("
|
|
right := ")"
|
|
|
|
if len(str) < len(left)+len(right) {
|
|
return false
|
|
}
|
|
|
|
return (str[:len(left)] == left && str[len(str)-len(right):] == right)
|
|
}
|
|
|
|
|
|
func removeAnchor(key string) string {
|
|
if IsConditionAnchor(key) {
|
|
return key[1 : len(key)-1]
|
|
}
|
|
|
|
if IsExistanceAnchor(key) || IsAddingAnchor(key) || IsEqualityAnchor(key) || IsNegationAnchor(key) {
|
|
return key[2 : len(key)-1]
|
|
}
|
|
|
|
return key
|
|
} |