From 6ae7e2cc4f65edaa6382d4df9cc8f6c968e3d39e Mon Sep 17 00:00:00 2001 From: Anbraten Date: Sat, 19 Mar 2022 12:34:32 +0100 Subject: [PATCH] Fix uppercase from_secrets (#842) Secret names where matched based on their lowercase value already just the conversion to lowercase for `from_secrets` was missing. --- pipeline/frontend/yaml/compiler/params.go | 2 +- .../frontend/yaml/compiler/params_test.go | 52 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/pipeline/frontend/yaml/compiler/params.go b/pipeline/frontend/yaml/compiler/params.go index 263412d91..88f8906be 100644 --- a/pipeline/frontend/yaml/compiler/params.go +++ b/pipeline/frontend/yaml/compiler/params.go @@ -69,7 +69,7 @@ func sanitizeParamValue(v interface{}, secrets map[string]Secret) (string, error if fromSecret, ok := v.(map[string]interface{}); ok { if secretNameI, ok := fromSecret["from_secret"]; ok { if secretName, ok := secretNameI.(string); ok { - if secret, ok := secrets[secretName]; ok { + if secret, ok := secrets[strings.ToLower(secretName)]; ok { return secret.Value, nil } return "", fmt.Errorf("no secret found for %q", secretName) diff --git a/pipeline/frontend/yaml/compiler/params_test.go b/pipeline/frontend/yaml/compiler/params_test.go index a17d60554..82edbf583 100644 --- a/pipeline/frontend/yaml/compiler/params_test.go +++ b/pipeline/frontend/yaml/compiler/params_test.go @@ -9,33 +9,35 @@ import ( func TestParamsToEnv(t *testing.T) { from := map[string]interface{}{ - "skip": nil, - "string": "stringz", - "int": 1, - "float": 1.2, - "bool": true, - "slice": []int{1, 2, 3}, - "map": map[string]string{"hello": "world"}, - "complex": []struct{ Name string }{{"Jack"}, {"Jill"}}, - "complex2": struct{ Name string }{"Jack"}, - "from.address": "noreply@example.com", - "tags": stringsToInterface("next", "latest"), - "tag": stringsToInterface("next"), - "my_secret": map[string]interface{}{"from_secret": "secret_token"}, + "skip": nil, + "string": "stringz", + "int": 1, + "float": 1.2, + "bool": true, + "slice": []int{1, 2, 3}, + "map": map[string]string{"hello": "world"}, + "complex": []struct{ Name string }{{"Jack"}, {"Jill"}}, + "complex2": struct{ Name string }{"Jack"}, + "from.address": "noreply@example.com", + "tags": stringsToInterface("next", "latest"), + "tag": stringsToInterface("next"), + "my_secret": map[string]interface{}{"from_secret": "secret_token"}, + "UPPERCASE_SECRET": map[string]interface{}{"from_secret": "SECRET_TOKEN"}, } want := map[string]string{ - "PLUGIN_STRING": "stringz", - "PLUGIN_INT": "1", - "PLUGIN_FLOAT": "1.2", - "PLUGIN_BOOL": "true", - "PLUGIN_SLICE": "1,2,3", - "PLUGIN_MAP": `{"hello":"world"}`, - "PLUGIN_COMPLEX": `[{"name":"Jack"},{"name":"Jill"}]`, - "PLUGIN_COMPLEX2": `{"name":"Jack"}`, - "PLUGIN_FROM_ADDRESS": "noreply@example.com", - "PLUGIN_TAG": "next", - "PLUGIN_TAGS": "next,latest", - "PLUGIN_MY_SECRET": "FooBar", + "PLUGIN_STRING": "stringz", + "PLUGIN_INT": "1", + "PLUGIN_FLOAT": "1.2", + "PLUGIN_BOOL": "true", + "PLUGIN_SLICE": "1,2,3", + "PLUGIN_MAP": `{"hello":"world"}`, + "PLUGIN_COMPLEX": `[{"name":"Jack"},{"name":"Jill"}]`, + "PLUGIN_COMPLEX2": `{"name":"Jack"}`, + "PLUGIN_FROM_ADDRESS": "noreply@example.com", + "PLUGIN_TAG": "next", + "PLUGIN_TAGS": "next,latest", + "PLUGIN_MY_SECRET": "FooBar", + "PLUGIN_UPPERCASE_SECRET": "FooBar", } secrets := map[string]Secret{ "secret_token": {Name: "secret_token", Value: "FooBar", Match: nil},