matching env secrets with config file
This commit is contained in:
parent
815b7e0808
commit
bfcba9a464
30
main.go
30
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
|
@ -18,6 +19,35 @@ func main() {
|
|||
logger.Error(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
type Credentials struct {
|
||||
Password string
|
||||
AccessKey string
|
||||
}
|
||||
credentials := make(map[string]Credentials)
|
||||
for i := 0; i < len(config.Bots); i++ {
|
||||
user := getParam(fmt.Sprintf("MATRIX_BOT%d_ID", i), "")
|
||||
if user == "" {
|
||||
logger.Error("missing user id", slog.Int("user", i))
|
||||
os.Exit(1)
|
||||
}
|
||||
credentials[user] = Credentials{
|
||||
Password: getParam(fmt.Sprintf("MATRIX_BOT%d_PASSWORD", i), ""),
|
||||
AccessKey: getParam(fmt.Sprintf("MATRIX_BOT%d_ACCESSKEY", i), ""),
|
||||
}
|
||||
}
|
||||
for i, bc := range config.Bots {
|
||||
creds, ok := credentials[bc.UserID]
|
||||
if !ok {
|
||||
logger.Error("missing credentials", slog.Int("user", i))
|
||||
os.Exit(1)
|
||||
}
|
||||
config.Bots[i].UserPassword = creds.Password
|
||||
config.Bots[i].UserAccessKey = creds.AccessKey
|
||||
}
|
||||
|
||||
config.OpenAI = bot.ConfigOpenAI{
|
||||
APIKey: getParam("OPENAI_API_KEY", ""),
|
||||
}
|
||||
logger.Info("loaded config", slog.Int("bots", len(config.Bots)))
|
||||
|
||||
for _, bc := range config.Bots {
|
||||
|
|
Loading…
Reference in New Issue