From 16c8f814006a13278c285b3e3c8a7d0002cbdca7 Mon Sep 17 00:00:00 2001 From: iosmanthus Date: Thu, 6 Jun 2024 16:55:38 +0800 Subject: [PATCH] test Signed-off-by: iosmanthus --- pkgs/sops-install-secrets/main.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/pkgs/sops-install-secrets/main.go b/pkgs/sops-install-secrets/main.go index 26381c6..8db7491 100644 --- a/pkgs/sops-install-secrets/main.go +++ b/pkgs/sops-install-secrets/main.go @@ -242,14 +242,26 @@ func recurseSecretKey(format FormatType, keys map[string]interface{}, wantedKey if !ok { return "", fmt.Errorf("the key '%s' cannot be found", keyUntilNow) } - var valWithWrongType map[string]interface{} - valWithWrongType, ok = val.(map[string]interface{}) - if !ok { - return "", fmt.Errorf("key '%s' does not refer to a dictionary", keyUntilNow) - } - currentData = make(map[string]interface{}) - for key, value := range valWithWrongType { - currentData[fmt.Sprintf("%v", key)] = value + if format == JSON { + var valWithWrongType map[string]interface{} + valWithWrongType, ok = val.(map[string]interface{}) + if !ok { + return "", fmt.Errorf("key '%s' does not refer to a dictionary", keyUntilNow) + } + currentData = make(map[string]interface{}) + for key, value := range valWithWrongType { + currentData[fmt.Sprintf("%v", key)] = value + } + } else { + var valWithWrongType map[interface{}]interface{} + valWithWrongType, ok = val.(map[interface{}]interface{}) + if !ok { + return "", fmt.Errorf("key '%s' does not refer to a dictionary", keyUntilNow) + } + currentData = make(map[string]interface{}) + for key, value := range valWithWrongType { + currentData[fmt.Sprintf("%v", key)] = value + } } }