From 772b29b91a5e8a97564906b736546d0b47f0a524 Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:18:20 -0400 Subject: [PATCH] enhance(secrets): uppercase secret target (#387) --- yaml/build_test.go | 8 ++++---- yaml/secret.go | 4 +++- yaml/secret_test.go | 16 ++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/yaml/build_test.go b/yaml/build_test.go index a1ca6cc3..dff6f171 100644 --- a/yaml/build_test.go +++ b/yaml/build_test.go @@ -246,11 +246,11 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { Secrets: StepSecretSlice{ { Source: "docker_username", - Target: "plugin_username", + Target: "PLUGIN_USERNAME", }, { Source: "docker_password", - Target: "plugin_password", + Target: "PLUGIN_PASSWORD", }, }, }, @@ -308,11 +308,11 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { Secrets: StepSecretSlice{ { Source: "docker_username", - Target: "docker_username", + Target: "DOCKER_USERNAME", }, { Source: "docker_password", - Target: "docker_password", + Target: "DOCKER_PASSWORD", }, }, }, diff --git a/yaml/secret.go b/yaml/secret.go index 7867eca9..193e63f2 100644 --- a/yaml/secret.go +++ b/yaml/secret.go @@ -239,7 +239,7 @@ func (s *StepSecretSlice) UnmarshalYAML(unmarshal func(interface{}) error) error // append the element to the step secret slice *s = append(*s, &StepSecret{ Source: secret, - Target: secret, + Target: strings.ToUpper(secret), }) } @@ -257,6 +257,8 @@ func (s *StepSecretSlice) UnmarshalYAML(unmarshal func(interface{}) error) error if len(secret.Source) == 0 || len(secret.Target) == 0 { return fmt.Errorf("no secret source or target found") } + + secret.Target = strings.ToUpper(secret.Target) } // overwrite existing StepSecretSlice diff --git a/yaml/secret_test.go b/yaml/secret_test.go index 9918b8cf..62ad3291 100644 --- a/yaml/secret_test.go +++ b/yaml/secret_test.go @@ -264,11 +264,11 @@ func TestYaml_SecretSlice_UnmarshalYAML(t *testing.T) { Secrets: StepSecretSlice{ { Source: "foo", - Target: "foo", + Target: "FOO", }, { Source: "foobar", - Target: "foobar", + Target: "FOOBAR", }, }, }, @@ -296,11 +296,11 @@ func TestYaml_SecretSlice_UnmarshalYAML(t *testing.T) { Secrets: StepSecretSlice{ { Source: "foo", - Target: "foo", + Target: "FOO", }, { Source: "foobar", - Target: "foobar", + Target: "FOOBAR", }, }, }, @@ -390,11 +390,11 @@ func TestYaml_StepSecretSlice_UnmarshalYAML(t *testing.T) { want: &StepSecretSlice{ { Source: "foo", - Target: "bar", + Target: "BAR", }, { Source: "hello", - Target: "world", + Target: "WORLD", }, }, }, @@ -404,11 +404,11 @@ func TestYaml_StepSecretSlice_UnmarshalYAML(t *testing.T) { want: &StepSecretSlice{ { Source: "foo", - Target: "foo", + Target: "FOO", }, { Source: "hello", - Target: "hello", + Target: "HELLO", }, }, },