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:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user