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

Allow variables to be set to empty string in envFiles #3797

Merged
merged 1 commit into from
Jul 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/taskresource/envFiles/envfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,11 @@ func (envfile *EnvironmentFileResource) readEnvVarsFromFile(envfilePath string)
// only read the line that has "="
if strings.Contains(line, envVariableDelimiter) {
variables := strings.SplitN(line, envVariableDelimiter, 2)
// verify that there is at least a character on each side
if len(variables[0]) > 0 && len(variables[1]) > 0 {
// verify that the key is non-empty, the value can be empty
if len(variables[0]) > 0 {
envVars[variables[0]] = variables[1]
} else {
seelog.Infof("Not applying line %d of environment file %s, key or value is empty.", lineNum, envfilePath)
seelog.Infof("Not applying line %d of environment file %s, key is empty.", lineNum, envfilePath)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions agent/taskresource/envFiles/envfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {

envfileContentLine1 := "key1=value"
envFileContentLine2 := "key2=val1=val2"
envFileContentLine3 := "key3="

tempOpen := open
open = func(name string) (oswrapper.File, error) {
Expand All @@ -333,6 +334,8 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {
mockScanner.EXPECT().Text().Return(envfileContentLine1),
mockScanner.EXPECT().Scan().Return(true),
mockScanner.EXPECT().Text().Return(envFileContentLine2),
mockScanner.EXPECT().Scan().Return(true),
mockScanner.EXPECT().Text().Return(envFileContentLine3),
mockScanner.EXPECT().Scan().Return(false),
mockScanner.EXPECT().Err().Return(nil),
)
Expand All @@ -343,6 +346,9 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {
assert.Equal(t, 1, len(envVarsList))
assert.Equal(t, "value", envVarsList[0]["key1"])
assert.Equal(t, "val1=val2", envVarsList[0]["key2"])
key3Value, ok := envVarsList[0]["key3"]
assert.True(t, ok)
assert.Equal(t, "", key3Value)
}

func TestReadEnvVarsCommentFromEnvfiles(t *testing.T) {
Expand Down