feat(config): only read file sub-keys from files

This removes reading config values from _file and instead only reads from file sub keys. This should make it easier to not accidentally specify the same value twice.
The syntax via env does not change, but via a config file this:

database:
  password_file: foo

becomes

database:
  password:
    file: foo
This commit is contained in:
kolaente
2024-11-18 08:52:21 +01:00
parent fef19c5c1d
commit 3479fa1228

View File

@@ -440,17 +440,9 @@ func getConfigValueFromFile(configKey string) string {
return ""
}
func readConfigvaluesFromFiles() {
func readConfigValuesFromFiles() {
keys := viper.AllKeys()
for _, key := range keys {
if strings.HasSuffix(key, "_file") {
value := getConfigValueFromFile(key)
if value != "" {
viper.Set(strings.TrimSuffix(key, "_file"), value)
}
continue
}
// Env is evaluated manually at runtime, so we need to check this for each key
value := getConfigValueFromFile(key + ".file")
if value != "" {
@@ -503,7 +495,7 @@ func InitConfig() {
log.Info("No config file found, using default or config from environment variables.")
}
readConfigvaluesFromFiles()
readConfigValuesFromFiles()
if RateLimitStore.GetString() == "keyvalue" {
RateLimitStore.Set(KeyvalueType.GetString())