Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update secret character #4

Merged
merged 3 commits into from
May 11, 2020
Merged
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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ This helps us solve two major different problems:
#Example .env file
KEY=value
NAME=Oberyn Martell
SECRET=${secret-identifier}
SECRET=!{secret-identifier}
```

### Secrets
Secrets are denoted in a `.env` file by surrounding the identifier with `${}`.
Secrets are denoted in a `.env` file by surrounding the identifier with `!{}`.
Serum will pass this identifer to the specified `SecretProvider` for decryption. If the decryption is successful,
the value will be injected into the running process' environment using the specified key.

Expand Down
5 changes: 3 additions & 2 deletions internal/envparser/envparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
const (
commentToken = "#"
kvSeparator = "="
secretRegex = `^\${(?P<secretval>.+)}$`
secretRegex = `^!{(?P<secretval>.+)}$`
emptySecret = "!{}"
)

var secretRe *regexp.Regexp
Expand Down Expand Up @@ -92,7 +93,7 @@ func parseLine(envVars *EnvVars, l string) error {
//key is first index, value is second
k := strings.TrimSpace(splits[0])
v := strings.TrimSpace(splits[1])
if k == "" {
if k == "" || v == emptySecret {
return fmt.Errorf("invalid format %q", l)
}

Expand Down
15 changes: 11 additions & 4 deletions internal/envparser/envparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestParseFile(t *testing.T) {
name: "plain and secrets",
envFile: `
PLAIN=plaintext
SECRET=${keep it secret, keep it safe}
SECRET=!{keep it secret, keep it safe}
`,
plain: map[string]string{
"PLAIN": "plaintext",
Expand All @@ -84,7 +84,7 @@ func TestParseFile(t *testing.T) {
envFile: `
#yoyo
PLAIN=plaintext
SECRET=${keep it secret, keep it safe}
SECRET=!{keep it secret, keep it safe}
`,
plain: map[string]string{
"PLAIN": "plaintext",
Expand All @@ -97,7 +97,7 @@ func TestParseFile(t *testing.T) {
name: "only secrets and comments",
envFile: `
#yoyo
SECRET=${keep it secret, keep it safe}
SECRET=!{keep it secret, keep it safe}
`,
plain: map[string]string{},
secrets: map[string]string{
Expand All @@ -107,7 +107,7 @@ func TestParseFile(t *testing.T) {
{
name: "only secrets",
envFile: `
SECRET_PASSWORD=${is it the red or the white?}
SECRET_PASSWORD=!{is it the red or the white?}
`,
plain: map[string]string{},
secrets: map[string]string{
Expand Down Expand Up @@ -163,6 +163,13 @@ func TestParseFileError(t *testing.T) {
envFile: kvSeparator,
expectedErr: errors.New("invalid format"),
},
{
name: "empty secret",
envFile: `
SECRET=!{}
`,
expectedErr: errors.New("invalid format"),
},
}

for _, tc := range tt {
Expand Down