config: support environment variable macros in apiKeys (#467)

Add substituteEnvMacros support for apiKeys configuration field,
allowing API keys to be loaded from environment variables using
the ${env.VAR_NAME} syntax.

- Apply env macro substitution before validation
- Add tests for env macro substitution in apiKeys
This commit is contained in:
Benson Wong
2026-01-16 22:41:14 -08:00
committed by GitHub
parent 124007cc98
commit 8f2137c72b
2 changed files with 46 additions and 2 deletions
+8 -2
View File
@@ -485,8 +485,14 @@ func LoadConfigFromReader(r io.Reader) (Config, error) {
config.Hooks.OnStartup.Preload = toPreload
}
// check api keys validatity
for _, apikey := range config.RequiredAPIKeys {
// check api keys validity and substitute env macros
for i, apikey := range config.RequiredAPIKeys {
apikey, err = substituteEnvMacros(apikey)
if err != nil {
return Config{}, fmt.Errorf("apiKeys[%d]: %w", i, err)
}
config.RequiredAPIKeys[i] = apikey
if apikey == "" {
return Config{}, fmt.Errorf("empty api key found in apiKeys")
}