From d0f0fa2795020afc4d4d61cbdd90511d791f6867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barahona=20Jos=C3=A9=20Luis=20=28IT-PTR-BDE16=29?= Date: Thu, 30 May 2024 15:23:19 +0200 Subject: [PATCH] fix: separate DetectSopsYaml function to unhide marshalling errors --- helm_wrapper.go | 6 +++--- utils_test.go | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/helm_wrapper.go b/helm_wrapper.go index 8c72949..9558226 100644 --- a/helm_wrapper.go +++ b/helm_wrapper.go @@ -185,13 +185,13 @@ func (c *HelmWrapper) RunHelm() { } var encrypted bool - file, err := ReadAndUnmarshalYaml(filename) + fileData, err := ReadAndUnmarshalYaml(filename) if err != nil { c.ExitCode = 1 - _ = c.errorf("failed to read file '%s': %s", filename, err) + _ = c.errorf("failed to read or unmarshal file '%s': %s", filename, err) return } - encrypted = DetectSopsKey(file) + encrypted = DetectSopsKey(fileData) if err != nil { return } diff --git a/utils_test.go b/utils_test.go index aef3a5a..ac0097a 100644 --- a/utils_test.go +++ b/utils_test.go @@ -1,9 +1,9 @@ package main import ( - "testing" - "io/ioutil" - "os" + "io/ioutil" + "os" + "testing" ) func TestDetectSopsFile(t *testing.T) { @@ -18,7 +18,8 @@ func TestDetectSopsFile(t *testing.T) { tmp.WriteString(`--- secret: hello `) - res, err := DetectSopsYaml(tmp.Name()) + fileData, err := ReadAndUnmarshalYaml(tmp.Name()) + res := DetectSopsKey(fileData) if res != false || err != nil { t.Errorf("DetectSopsYaml(tmp) = %t, %v; want false, ", res, err) } @@ -36,7 +37,8 @@ sops: pgp: [] version: 3.6.1 `) - res, err = DetectSopsYaml(tmp.Name()) + fileData, err = ReadAndUnmarshalYaml(tmp.Name()) + res = DetectSopsKey(fileData) if res != true || err != nil { t.Errorf("DetectSopsYaml(tmp) = %t, %v; want true, ", res, err) }