diff --git a/changelog.md b/changelog.md index 85d7b09..e75efcd 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - support JSON logging and make it the default - support log level configuration - update dependencies +- re-order configuration precedence + 1. default config file idp.toml + 2. config files given via the `--conf` command line argument + 3. environment variables with the `IDP_` prefix ### Fixed - run deb-systemd-helper in Debian package `postinst` script diff --git a/internal/services/configuration.go b/internal/services/configuration.go index 37c905b..ac54723 100644 --- a/internal/services/configuration.go +++ b/internal/services/configuration.go @@ -32,7 +32,10 @@ import ( "github.com/spf13/pflag" ) -const defaultServerPort = 3000 +const ( + defaultServerPort = 3000 + defaultFile = "idp.toml" +) var DefaultConfig = map[string]interface{}{ "server.bind_address": "", @@ -74,6 +77,10 @@ func ConfigureApplication( _ = config.Load(confmap.Provider(defaultConfig, "."), nil) + if err = config.Load(file.Provider(defaultFile), toml.Parser()); err != nil && !os.IsNotExist(err) { + logrus.WithError(err).WithField("file", defaultFile).Fatal("error loading configuration from file") + } + cFiles, _ := f.GetStringSlice("conf") for _, c := range cFiles { if err = config.Load(file.Provider(c), toml.Parser()); err != nil { @@ -85,13 +92,6 @@ func ConfigureApplication( logger.WithError(err).Fatal("error loading configuration from command line") } - if err = config.Load( - file.Provider("idp.toml"), - toml.Parser(), - ); err != nil && !os.IsNotExist(err) { - logrus.WithError(err).Fatal("error loading configuration from resource_app.toml") - } - prefix := fmt.Sprintf("%s_", strings.ToUpper(appName)) if err = config.Load(env.Provider(prefix, ".", func(s string) string {