mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-08 10:04:25 +00:00
Merge pull request #1724 from MarcelMue/fix-apipath-validation
Make validateAPICall work with special characters in variables
This commit is contained in:
commit
4d70013e22
2 changed files with 10 additions and 1 deletions
|
@ -18,6 +18,11 @@ func IsVariable(element string) bool {
|
|||
return len(groups) != 0
|
||||
}
|
||||
|
||||
//ReplaceAllVars replaces all variables with the value defined in the replacement function
|
||||
func ReplaceAllVars(src string, repl func(string) string) string {
|
||||
return regexVariables.ReplaceAllStringFunc(src, repl)
|
||||
}
|
||||
|
||||
//SubstituteVars replaces the variables with the values defined in the context
|
||||
// - if any variable is invalid or has nil value, it is considered as a failed variable substitution
|
||||
func SubstituteVars(log logr.Logger, ctx context.EvalInterface, pattern interface{}) (interface{}, error) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/jmespath/go-jmespath"
|
||||
"github.com/kyverno/kyverno/pkg/engine"
|
||||
"github.com/kyverno/kyverno/pkg/engine/variables"
|
||||
"github.com/kyverno/kyverno/pkg/kyverno/common"
|
||||
|
||||
kyverno "github.com/kyverno/kyverno/pkg/api/kyverno/v1"
|
||||
|
@ -681,7 +682,10 @@ func validateAPICall(entry kyverno.ContextEntry) error {
|
|||
return fmt.Errorf("both configMap and apiCall are not allowed in a context entry")
|
||||
}
|
||||
|
||||
if _, err := engine.NewAPIPath(entry.APICall.URLPath); err != nil {
|
||||
// Replace all variables to prevent validation failing on variable keys.
|
||||
urlPath := variables.ReplaceAllVars(entry.APICall.URLPath, func(s string) string { return "kyvernoapicallvariable" })
|
||||
|
||||
if _, err := engine.NewAPIPath(urlPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue