Implement ENV variable resolution in team configuration
- Add `resolveTeamConfigENV` function to process and replace environment variables in team configuration settings, including robot email domains, whitelist entries, and invite configuration. - Enhance `loadTeamConfigs` to call the new function, ensuring that team configurations are properly resolved before storage. This change improves the flexibility of team configurations by allowing dynamic environment variable substitution.
This commit is contained in:
parent
bf8d82f022
commit
3bbc11604c
1 changed files with 46 additions and 0 deletions
|
|
@ -269,6 +269,9 @@ func loadTeamConfigs(_ string) error {
|
|||
return fmt.Errorf("failed to parse team config %s: %v", filename, err)
|
||||
}
|
||||
|
||||
// Resolve $ENV. variables in team configuration
|
||||
resolveTeamConfigENV(&teamConfig)
|
||||
|
||||
// Store team configuration
|
||||
teamConfigs[locale] = &teamConfig
|
||||
|
||||
|
|
@ -402,6 +405,49 @@ func extractEnvVarName(value string) string {
|
|||
return "unknown"
|
||||
}
|
||||
|
||||
// resolveTeamConfigENV resolves $ENV. variables in team configuration
|
||||
func resolveTeamConfigENV(config *TeamConfig) {
|
||||
if config == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Resolve robot config
|
||||
if config.Robot != nil {
|
||||
// Resolve email domains
|
||||
for _, domain := range config.Robot.EmailDomains {
|
||||
if domain == nil {
|
||||
continue
|
||||
}
|
||||
domain.Domain = replaceENVVar(domain.Domain)
|
||||
domain.Messenger = replaceENVVar(domain.Messenger)
|
||||
|
||||
// Resolve whitelist
|
||||
if domain.Whitelist != nil {
|
||||
for i, d := range domain.Whitelist.Domains {
|
||||
domain.Whitelist.Domains[i] = replaceENVVar(d)
|
||||
}
|
||||
for i, s := range domain.Whitelist.Senders {
|
||||
domain.Whitelist.Senders[i] = replaceENVVar(s)
|
||||
}
|
||||
for i, ip := range domain.Whitelist.IPs {
|
||||
domain.Whitelist.IPs[i] = replaceENVVar(ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve defaults
|
||||
if config.Robot.Defaults != nil {
|
||||
config.Robot.Defaults.LLM = replaceENVVar(config.Robot.Defaults.LLM)
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve invite config
|
||||
if config.Invite != nil {
|
||||
config.Invite.BaseURL = replaceENVVar(config.Invite.BaseURL)
|
||||
config.Invite.Channel = replaceENVVar(config.Invite.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
// replaceENVVar replaces environment variables in a string
|
||||
func replaceENVVar(value string) string {
|
||||
if value == "" {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue