fix(config): use SABLIER_ environment variable prefix#790
Conversation
The prefix should be used now, but it will still match legacy environment variables for now. They won't be documented anymore. Related to issue #786
|
There was a problem hiding this comment.
Pull request overview
This pull request introduces the SABLIER_ environment variable prefix for all configuration options, addressing issue #786. The change maintains backward compatibility by supporting both legacy (unprefixed) and new (prefixed) environment variables.
Changes:
- Updated environment variable binding to support both legacy and
SABLIER_prefixed variables - Added comprehensive test coverage for legacy environment variable support
- Updated all documentation to reflect the new
SABLIER_prefix requirement
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/sabliercmd/root.go | Modified bindFlags to bind both legacy and new prefixed environment variables |
| pkg/sabliercmd/cmd_test.go | Added test case for legacy environment variable backward compatibility |
| pkg/sabliercmd/testdata/config.env | Updated to use SABLIER_ prefix for all environment variables |
| pkg/sabliercmd/testdata/config.legacy.env | New test data file with legacy (unprefixed) environment variables |
| README.md | Updated documentation to show SABLIER_ prefix in environment variable examples |
| docs/configuration.md | Updated to document the SABLIER_ prefix requirement |
| docs/providers/docker.md | Updated environment variable examples with SABLIER_ prefix |
| docs/providers/docker_swarm.md | Updated environment variable examples with SABLIER_ prefix |
| docs/providers/kubernetes.md | Updated environment variable examples with SABLIER_ prefix |
| docs/providers/podman.md | Updated environment variable examples with SABLIER_ prefix |
Comments suppressed due to low confidence (1)
pkg/sabliercmd/cmd_test.go:115
- The tests verify that legacy and new environment variables work independently, but there's no test case that verifies the precedence behavior when both legacy (PROVIDER_NAME) and new (SABLIER_PROVIDER_NAME) environment variables are set simultaneously. Consider adding a test case to verify which variable takes precedence in this scenario.
t.Run("legacy env var", func(t *testing.T) {
setEnvsFromFile(filepath.Join(testDir, "testdata", "config.legacy.env"))
defer unsetEnvsFromFile(filepath.Join(testDir, "testdata", "config.legacy.env"))
wantConfig, err := os.ReadFile(filepath.Join(testDir, "testdata", "config_env_wanted.json"))
require.NoError(t, err, "error reading test config file")
sabliercmd.ResetConfig()
cmd := sabliercmd.NewRootCommand()
output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{
"--configFile", filepath.Join(testDir, "testdata", "config.yml"),
"start",
})
_ = cmd.Execute()
gotOutput := output.String()
assert.Equal(t, string(wantConfig), gotOutput)
})
t.Run("env var", func(t *testing.T) {
setEnvsFromFile(filepath.Join(testDir, "testdata", "config.env"))
defer unsetEnvsFromFile(filepath.Join(testDir, "testdata", "config.env"))
wantConfig, err := os.ReadFile(filepath.Join(testDir, "testdata", "config_env_wanted.json"))
require.NoError(t, err, "error reading test config file")
sabliercmd.ResetConfig()
cmd := sabliercmd.NewRootCommand()
output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{
"--configFile", filepath.Join(testDir, "testdata", "config.yml"),
"start",
})
_ = cmd.Execute()
gotOutput := output.String()
assert.Equal(t, string(wantConfig), gotOutput)
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _ = v.BindEnv(f.Name, envVarSuffix) | ||
| envVar := strings.ToUpper(strings.ReplaceAll(f.Name, "-", "_")) | ||
| envVar = strings.ToUpper(strings.ReplaceAll(envVar, ".", "_")) | ||
| _ = v.BindEnv(f.Name, envVar, "SABLIER_"+envVar) |
There was a problem hiding this comment.
The order of environment variables in BindEnv determines precedence when both are set. Currently, the legacy variable (without SABLIER_ prefix) takes precedence over the new prefixed variable. For a proper migration path, the new prefixed variable should take precedence. Consider reversing the order to: v.BindEnv(f.Name, "SABLIER_"+envVar, envVar)
| envVarSuffix = strings.ToUpper(strings.ReplaceAll(envVarSuffix, ".", "_")) | ||
| _ = v.BindEnv(f.Name, envVarSuffix) | ||
| envVar := strings.ToUpper(strings.ReplaceAll(f.Name, "-", "_")) | ||
| envVar = strings.ToUpper(strings.ReplaceAll(envVar, ".", "_")) |
There was a problem hiding this comment.
The second call to strings.ToUpper is redundant since the result from line 138 is already fully uppercase. Line 139 should just be: envVar = strings.ReplaceAll(envVar, ".", "_")
|
✅ All tests successful. No failed tests were found. 📣 Thoughts on this report? Let Codecov know! | Powered by Codecov |
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
|


The prefix should be used now, but it will still match legacy environment variables for non breaking change. They won't be documented anymore.
Related to issue #786