From bd933669ef1dcc8933bbf631194091fd8c06f228 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:23:49 +0200 Subject: [PATCH] Fix snake_case env vars (#4267) --- pipeline/frontend/yaml/compiler/settings/params.go | 3 ++- pipeline/frontend/yaml/compiler/settings/params_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pipeline/frontend/yaml/compiler/settings/params.go b/pipeline/frontend/yaml/compiler/settings/params.go index 08cdf26e9..f078643e6 100644 --- a/pipeline/frontend/yaml/compiler/settings/params.go +++ b/pipeline/frontend/yaml/compiler/settings/params.go @@ -44,8 +44,9 @@ func ParamsToEnv(from map[string]any, to map[string]string, prefix string, upper // sanitizeParamKey formats the environment variable key. func sanitizeParamKey(prefix string, upper bool, k string) string { - r := strings.ReplaceAll(strings.ReplaceAll(k, ".", "_"), "-", "_") + r := k if upper { + r = strings.ReplaceAll(strings.ReplaceAll(k, ".", "_"), "-", "_") r = strings.ToUpper(r) } return prefix + r diff --git a/pipeline/frontend/yaml/compiler/settings/params_test.go b/pipeline/frontend/yaml/compiler/settings/params_test.go index 5e3e6da12..386b58d02 100644 --- a/pipeline/frontend/yaml/compiler/settings/params_test.go +++ b/pipeline/frontend/yaml/compiler/settings/params_test.go @@ -110,8 +110,9 @@ func TestSanitizeParamKey(t *testing.T) { assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry-run")) assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry_Run")) assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry.run")) - assert.EqualValues(t, "PLUGIN_dry_run", sanitizeParamKey("PLUGIN_", false, "dry-run")) + assert.EqualValues(t, "PLUGIN_dry-run", sanitizeParamKey("PLUGIN_", false, "dry-run")) assert.EqualValues(t, "PLUGIN_dry_Run", sanitizeParamKey("PLUGIN_", false, "dry_Run")) + assert.EqualValues(t, "PLUGIN_dry.run", sanitizeParamKey("PLUGIN_", false, "dry.run")) } func TestYAMLToParamsToEnv(t *testing.T) {