diff --git a/api/config.go b/api/config.go index 29a3208..20db480 100644 --- a/api/config.go +++ b/api/config.go @@ -58,6 +58,12 @@ func configParse() error { "GITLAB_SECRET": "", } + if os.Getenv("COMMENTO_CONFIG_FILE") != "" { + if err := configFileLoad(os.Getenv("COMMENTO_CONFIG_FILE")); err != nil { + return err + } + } + for key, value := range defaults { if os.Getenv("COMMENTO_"+key) == "" { os.Setenv(key, value) @@ -66,12 +72,6 @@ func configParse() error { } } - if os.Getenv("CONFIG_FILE") != "" { - if err := configFileLoad(os.Getenv("CONFIG_FILE")); err != nil { - return err - } - } - // Mandatory config parameters for _, env := range []string{"POSTGRES", "PORT", "ORIGIN", "FORBID_NEW_OWNERS", "MAX_IDLE_PG_CONNECTIONS"} { if os.Getenv(env) == "" { diff --git a/api/config_file.go b/api/config_file.go index 8303c6b..24febd2 100644 --- a/api/config_file.go +++ b/api/config_file.go @@ -41,11 +41,12 @@ func configFileLoad(filepath string) error { continue } - if os.Getenv(key[9:]) != "" { + if os.Getenv(key) != "" { + // Config files have lower precedence. continue } - os.Setenv(key[9:], value) + os.Setenv(key, value) } return nil diff --git a/api/config_file_test.go b/api/config_file_test.go index bac20da..4c4a56b 100644 --- a/api/config_file_test.go +++ b/api/config_file_test.go @@ -37,19 +37,19 @@ func TestConfigFileLoadBasics(t *testing.T) { return } - os.Setenv("PORT", "9000") + os.Setenv("COMMENTO_PORT", "9000") if err := configFileLoad(f.Name()); err != nil { t.Errorf("unexpected error loading config file: %v", err) return } - if os.Getenv("PORT") != "9000" { - t.Errorf("expected PORT=9000 got PORT=%s", os.Getenv("PORT")) + if os.Getenv("COMMENTO_PORT") != "9000" { + t.Errorf("expected COMMENTO_PORT=9000 got COMMENTO_PORT=%s", os.Getenv("COMMENTO_PORT")) return } - if os.Getenv("GZIP_STATIC") != "true" { - t.Errorf("expected GZIP_STATIC=true got GZIP_STATIC=%s", os.Getenv("GZIP_STATIC")) + if os.Getenv("COMMENTO_GZIP_STATIC") != "true" { + t.Errorf("expected COMMENTO_GZIP_STATIC=true got COMMENTO_GZIP_STATIC=%s", os.Getenv("COMMENTO_GZIP_STATIC")) return } } diff --git a/api/config_test.go b/api/config_test.go index bb11a73..df54cc3 100644 --- a/api/config_test.go +++ b/api/config_test.go @@ -21,6 +21,7 @@ func TestConfigParseBasics(t *testing.T) { os.Setenv("COMMENTO_BIND_ADDRESS", "192.168.1.100") + os.Setenv("COMMENTO_PORT", "") if err := configParse(); err != nil { t.Errorf("unexpected error when parsing config: %v", err) return