From 3479fa1228561feba4264f17c0a7ebe05bf7e206 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 18 Nov 2024 08:52:21 +0100 Subject: [PATCH] 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 --- pkg/config/config.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index aa38a4856..8357e279a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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())