Skip to content

fix: allow all environment variables to fallback prefix to HOMEBREW_ #10050

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

Merged
merged 2 commits into from
Oct 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cli/clibase/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ func (optSet *OptionSet) ParseEnv(vs []EnvVar) error {
}

envVal, ok := envs[opt.Env]
if !ok {
// Homebrew strips all environment variables that do not start with `HOMEBREW_`.
// This prevented using brew to invoke the Coder agent, because the environment
// variables to not get passed down.
//
// A customer wanted to use their custom tap inside a workspace, which was failing
// because the agent lacked the environment variables to authenticate with Git.
envVal, ok = envs[`HOMEBREW_`+opt.Env]
}
// Currently, empty values are treated as if the environment variable is
// unset. This behavior is technically not correct as there is now no
// way for a user to change a Default value to an empty string from
Expand Down
20 changes: 20 additions & 0 deletions cli/clibase/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,26 @@ func TestOptionSet_ParseEnv(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, expected, actual.Value)
})

t.Run("Homebrew", func(t *testing.T) {
t.Parallel()

var agentToken clibase.String

os := clibase.OptionSet{
clibase.Option{
Name: "Agent Token",
Value: &agentToken,
Env: "AGENT_TOKEN",
},
}

err := os.ParseEnv([]clibase.EnvVar{
{Name: "HOMEBREW_AGENT_TOKEN", Value: "foo"},
})
require.NoError(t, err)
require.EqualValues(t, "foo", agentToken)
})
}

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