Skip to content

Commit

Permalink
chore: Add docker and env-no-quotes mount formats
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-blunden committed Jan 17, 2025
1 parent 9282a9e commit ec5e67f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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"
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,
}

0 comments on commit ec5e67f

Please sign in to comment.