From ec5e67f7c23da5c435d28e34754ff6dde00e104c Mon Sep 17 00:00:00 2001 From: Ryan Blunden Date: Fri, 17 Jan 2025 14:37:57 +1000 Subject: [PATCH] chore: Add docker and env-no-quotes mount formats --- pkg/controllers/secrets.go | 4 ++++ pkg/controllers/secrets_test.go | 12 ++++++++++++ pkg/models/secrets_mount.go | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/pkg/controllers/secrets.go b/pkg/controllers/secrets.go index c94202f9..d97a07f9 100644 --- a/pkg/controllers/secrets.go +++ b/pkg/controllers/secrets.go @@ -131,6 +131,10 @@ func SecretsToBytes(secrets map[string]string, format string, templateBody strin return []byte(strings.Join(utils.MapToEnvFormat(secrets, true), "\n")), Error{} } + if format == models.EnvNoQuotesFormat || format == models.DockerFormat { + return []byte(strings.Join(utils.MapToEnvFormat(secrets, false), "\n")), Error{} + } + if format == models.JSONMountFormat { envStr, err := json.Marshal(secrets) if err != nil { diff --git a/pkg/controllers/secrets_test.go b/pkg/controllers/secrets_test.go index 22c42a28..23ab1f63 100644 --- a/pkg/controllers/secrets_test.go +++ b/pkg/controllers/secrets_test.go @@ -82,6 +82,18 @@ func TestSecretsToBytes(t *testing.T) { t.Errorf("Unable to convert secrets to byte array in %s format", format) } + format = "env" + bytes, err = SecretsToBytes(secrets, format, "") + if !err.IsNil() || string(bytes) != strings.Join([]string{`S1="foo"`, `SECRET2="bar"`}, "\n") { + t.Errorf("Unable to convert secrets to byte array in %s format", format) + } + + format = "env" + bytes, err = SecretsToBytes(secrets, format, "") + if !err.IsNil() || string(bytes) != strings.Join([]string{`S1="foo"`, `SECRET2="bar"`}, "\n") { + t.Errorf("Unable to convert secrets to byte array in %s format", format) + } + format = "json" bytes, err = SecretsToBytes(secrets, format, "") if !err.IsNil() || string(bytes) != `{"S1":"foo","SECRET2":"bar"}` { diff --git a/pkg/models/secrets_mount.go b/pkg/models/secrets_mount.go index ca4f4765..e3335cf5 100644 --- a/pkg/models/secrets_mount.go +++ b/pkg/models/secrets_mount.go @@ -19,12 +19,16 @@ const JSONMountFormat = "json" const EnvMountFormat = "env" const TemplateMountFormat = "template" const DotNETJSONMountFormat = "dotnet-json" +const EnvNoQuotesFormat = "env-no-quotes" +const DockerFormat = "docker" var SecretsMountFormats = []string{ EnvMountFormat, JSONMountFormat, DotNETJSONMountFormat, TemplateMountFormat, + EnvNoQuotesFormat, + DockerFormat, } var SecretsMountFormatMap = map[string]string{ @@ -32,4 +36,6 @@ var SecretsMountFormatMap = map[string]string{ JSONMountFormat: JSONMountFormat, DotNETJSONMountFormat: DotNETJSONMountFormat, TemplateMountFormat: TemplateMountFormat, + EnvNoQuotesFormat: EnvNoQuotesFormat, + DockerFormat: DockerFormat, }