mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-08 10:04:25 +00:00
Ensure JSON strings are properly escaped
Ensure multiple policies can be tested with variables in same files Signed-off-by: Trey Dockendorf <tdockendorf@osc.edu>
This commit is contained in:
parent
d7886bddc9
commit
00b8da9219
2 changed files with 13 additions and 1 deletions
pkg
|
@ -103,7 +103,7 @@ func VariableToJSON(key, value string) []byte {
|
|||
}
|
||||
}
|
||||
|
||||
midString := fmt.Sprintf(`"%s"`, value)
|
||||
midString := fmt.Sprintf(`"%s"`, strings.Replace(value, `"`, `\"`, -1))
|
||||
finalString := startString + midString + endString
|
||||
var jsonData = []byte(finalString)
|
||||
return jsonData
|
||||
|
|
|
@ -329,6 +329,18 @@ func applyPoliciesFromPath(fs billy.Filesystem, policyBytes []byte, valuesFile s
|
|||
continue
|
||||
}
|
||||
for _, resource := range resources {
|
||||
var resourcePolicy string
|
||||
for polName, values := range valuesMap {
|
||||
for resName := range values {
|
||||
if resName == resource.GetName() {
|
||||
resourcePolicy = polName
|
||||
}
|
||||
}
|
||||
}
|
||||
if resourcePolicy != policy.GetName() {
|
||||
log.Log.V(3).Info(fmt.Sprintf("Skipping resource, policy names do not match %s != %s", resourcePolicy, policy.GetName()))
|
||||
continue
|
||||
}
|
||||
thisPolicyResourceValues := make(map[string]string)
|
||||
if len(valuesMap[policy.GetName()]) != 0 && !reflect.DeepEqual(valuesMap[policy.GetName()][resource.GetName()], Resource{}) {
|
||||
thisPolicyResourceValues = valuesMap[policy.GetName()][resource.GetName()].Values
|
||||
|
|
Loading…
Add table
Reference in a new issue