Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/controllers/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions pkg/controllers/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ func TestSecretsToBytes(t *testing.T) {
t.Errorf("Unable to convert secrets to byte array in %s format", format)
}

format = "env"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check/copy-pasta: These look identical to the env tests above. I assume this is supposed to be testing the new formats?

diff --git a/pkg/controllers/secrets_test.go b/pkg/controllers/secrets_test.go
index 23ab1f6..bccb47c 100644
--- a/pkg/controllers/secrets_test.go
+++ b/pkg/controllers/secrets_test.go
@@ -82,15 +82,15 @@ func TestSecretsToBytes(t *testing.T) {
 		t.Errorf("Unable to convert secrets to byte array in %s format", format)
 	}
 
-	format = "env"
+	format = "env-no-quotes"
 	bytes, err = SecretsToBytes(secrets, format, "")
-	if !err.IsNil() || string(bytes) != strings.Join([]string{`S1="foo"`, `SECRET2="bar"`}, "\n") {
+	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"
+	format = "docker"
 	bytes, err = SecretsToBytes(secrets, format, "")
-	if !err.IsNil() || string(bytes) != strings.Join([]string{`S1="foo"`, `SECRET2="bar"`}, "\n") {
+	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)
 	}
 

(You can apply by copying the patch and doing pbpaste | git apply or pasting manually)

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"}` {
Expand Down
6 changes: 6 additions & 0 deletions pkg/models/secrets_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ 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{
EnvMountFormat: EnvMountFormat,
JSONMountFormat: JSONMountFormat,
DotNETJSONMountFormat: DotNETJSONMountFormat,
TemplateMountFormat: TemplateMountFormat,
EnvNoQuotesFormat: EnvNoQuotesFormat,
DockerFormat: DockerFormat,
}