diff --git a/config/config.go b/config/config.go index 563d18956d..411573647b 100644 --- a/config/config.go +++ b/config/config.go @@ -110,11 +110,14 @@ type Dogstatsd struct { URL string `yaml:"url"` } +// DefaultAddress is used if an http_listen_addr is not provided in the config. +const DefaultAddress = ":6060" + func Validate(conf Config) error { switch strings.ToLower(conf.Mode) { case ComboMode: if conf.HTTPListenAddr == "" { - return fmt.Errorf("dev mode selected but no global HTTPListenAddr") + conf.HTTPListenAddr = DefaultAddress } if conf.Indexer.ConnString == "" { return fmt.Errorf("indexer mode requires a database connection string") @@ -124,14 +127,14 @@ func Validate(conf Config) error { } case IndexerMode: if conf.HTTPListenAddr == "" { - return fmt.Errorf("indexer mode selected but no http listen address") + conf.HTTPListenAddr = DefaultAddress } if conf.Indexer.ConnString == "" { return fmt.Errorf("indexer mode requires a database connection string") } case MatcherMode: if conf.HTTPListenAddr == "" { - return fmt.Errorf("matcher mode selected but no http listen address") + conf.HTTPListenAddr = DefaultAddress } if conf.Matcher.ConnString == "" { return fmt.Errorf("matcher mode requires a database connection string") diff --git a/config/config_test.go b/config/config_test.go index 6d886861d5..f979bdbd38 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -19,13 +19,6 @@ func Test_Config_Validate_Failure(t *testing.T) { Mode: "", }, }, - { - name: "ComboMode, No Global HTTP Listen Addr", - conf: config.Config{ - Mode: config.ComboMode, - HTTPListenAddr: "", - }, - }, { name: "ComboMode, Malformed Global HTTP Listen Addr", conf: config.Config{ @@ -33,18 +26,6 @@ func Test_Config_Validate_Failure(t *testing.T) { HTTPListenAddr: "xyz", }, }, - // Indexer and Matcher modes require both a listen http addr and a database connection string - // other fields will use defaults defined in claircore. Matcher mode requires an address to a remote Indexer. - { - name: "IndexerMode, No HTTPListenAddr", - conf: config.Config{ - Mode: config.IndexerMode, - HTTPListenAddr: "", - Indexer: config.Indexer{ - ConnString: "example@example/db", - }, - }, - }, { name: "IndexerMode, No ConnString", conf: config.Config{ @@ -55,16 +36,6 @@ func Test_Config_Validate_Failure(t *testing.T) { }, }, }, - { - name: "MatcherMode, No HTTPListenAddr", - conf: config.Config{ - Mode: config.MatcherMode, - HTTPListenAddr: "", - Matcher: config.Matcher{ - ConnString: "example@example/db", - }, - }, - }, { name: "MatcherMode, No ConnString", conf: config.Config{