mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
c8a3b19d2c
Signed-off-by: ShutingZhao <shuting@nirmata.com>
30 lines
735 B
Go
30 lines
735 B
Go
package regex
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// IsVariable returns true if the element contains a 'valid' variable {{}}
|
|
func IsVariable(value string) bool {
|
|
groups := RegexVariables.FindAllStringSubmatch(value, -1)
|
|
return len(groups) != 0
|
|
}
|
|
|
|
// IsReference returns true if the element contains a 'valid' reference $()
|
|
func IsReference(value string) bool {
|
|
groups := RegexReferences.FindAllStringSubmatch(value, -1)
|
|
return len(groups) != 0
|
|
}
|
|
|
|
func ObjectHasVariables(object interface{}) error {
|
|
var err error
|
|
objectJSON, err := json.Marshal(object)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(RegexVariables.FindAllStringSubmatch(string(objectJSON), -1)) > 0 {
|
|
return fmt.Errorf("variables are not allowed")
|
|
}
|
|
return nil
|
|
}
|