1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

fix: jp items function ()

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-02-02 14:19:35 +01:00 committed by GitHub
parent 78016a5a51
commit 8f2f263694
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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")
} }
} }