From 2431a8ccd6c199e11f86b898e3ef94ebe0af5913 Mon Sep 17 00:00:00 2001 From: iosmanthus Date: Thu, 6 Jun 2024 17:07:28 +0800 Subject: [PATCH] nested only for json Signed-off-by: iosmanthus --- pkgs/sops-install-secrets/main.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/pkgs/sops-install-secrets/main.go b/pkgs/sops-install-secrets/main.go index 8db7491..268f2a7 100644 --- a/pkgs/sops-install-secrets/main.go +++ b/pkgs/sops-install-secrets/main.go @@ -265,28 +265,22 @@ func recurseSecretKey(format FormatType, keys map[string]interface{}, wantedKey } } - var marshaller func(interface{}) ([]byte, error) - switch format { - case JSON: - marshaller = json.Marshal - case Yaml: - marshaller = yaml.Marshal - default: - return "", fmt.Errorf("secret of type %s is not supported", format) - } - // If the value is a string, do not marshal it. if strVal, ok := val.(string); ok { return strVal, nil } - strVal, err := marshaller(val) - if err != nil { - return "", fmt.Errorf("cannot marshal the value of key '%s': %w", keyUntilNow, err) + switch format { + case JSON: + strVal, err := json.Marshal(val) + if err != nil { + return "", fmt.Errorf("cannot marshal the value of key '%s': %w", keyUntilNow, err) + } + strVal = bytes.Trim(strVal, "\"") + return string(strVal), nil + default: + return "", fmt.Errorf("nested secrets are not supported for %s", format) } - strVal = bytes.TrimSpace(strVal) - - return string(strVal), nil } func decryptSecret(s *secret, sourceFiles map[string]plainData) error {