diff --git a/README.md b/README.md index 62d333d..878761c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/internal/envparser/envparser.go b/internal/envparser/envparser.go index 36245dc..cdcb0d4 100644 --- a/internal/envparser/envparser.go +++ b/internal/envparser/envparser.go @@ -12,7 +12,8 @@ import ( const ( commentToken = "#" kvSeparator = "=" - secretRegex = `^\${(?P.+)}$` + secretRegex = `^!{(?P.+)}$` + emptySecret = "!{}" ) var secretRe *regexp.Regexp @@ -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) } diff --git a/internal/envparser/envparser_test.go b/internal/envparser/envparser_test.go index a219f8b..fc783ce 100644 --- a/internal/envparser/envparser_test.go +++ b/internal/envparser/envparser_test.go @@ -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", @@ -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", @@ -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{ @@ -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{ @@ -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 {