Skip to content

Commit

Permalink
config: set a canonical default port
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Mar 27, 2020
1 parent 0778606 commit b2666e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
9 changes: 6 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
29 changes: 0 additions & 29 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,13 @@ 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{
Mode: config.ComboMode,
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{
Expand All @@ -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{
Expand Down

0 comments on commit b2666e5

Please sign in to comment.