mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: jp items function (#6196)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
78016a5a51
commit
8f2f263694
1 changed files with 4 additions and 4 deletions
|
@ -994,13 +994,13 @@ func jpItems(arguments []interface{}) (interface{}, error) {
|
||||||
}
|
}
|
||||||
switch input := arguments[0].(type) {
|
switch input := arguments[0].(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
var keys []string
|
keys := make([]string, 0, len(input))
|
||||||
// Sort the keys so that the output is deterministic
|
// Sort the keys so that the output is deterministic
|
||||||
for key := range input {
|
for key := range input {
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
}
|
}
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
var arrayOfObj []map[string]interface{}
|
arrayOfObj := make([]map[string]interface{}, 0, len(input))
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
arrayOfObj = append(arrayOfObj, map[string]interface{}{
|
arrayOfObj = append(arrayOfObj, map[string]interface{}{
|
||||||
keyName: key,
|
keyName: key,
|
||||||
|
@ -1009,7 +1009,7 @@ func jpItems(arguments []interface{}) (interface{}, error) {
|
||||||
}
|
}
|
||||||
return arrayOfObj, nil
|
return arrayOfObj, nil
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
var arrayOfObj []map[string]interface{}
|
arrayOfObj := make([]map[string]interface{}, 0, len(input))
|
||||||
for index, value := range input {
|
for index, value := range input {
|
||||||
arrayOfObj = append(arrayOfObj, map[string]interface{}{
|
arrayOfObj = append(arrayOfObj, map[string]interface{}{
|
||||||
keyName: float64(index),
|
keyName: float64(index),
|
||||||
|
@ -1018,7 +1018,7 @@ func jpItems(arguments []interface{}) (interface{}, error) {
|
||||||
}
|
}
|
||||||
return arrayOfObj, nil
|
return arrayOfObj, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf(invalidArgumentTypeError, arguments, 0, "Object")
|
return nil, fmt.Errorf(invalidArgumentTypeError, arguments, 0, "Object or Array")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue