config: validate databroker settings (#1260)

* config: validate databroker settings

* fix test
This commit is contained in:
Caleb Doxsey 2020-08-12 11:32:34 -06:00 committed by GitHub
parent 877edde0be
commit bd5c784670
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View file

@ -74,12 +74,6 @@ func (src *ConfigSource) rebuild(firstTime bool) {
defer src.mu.Unlock() defer src.mu.Unlock()
cfg := src.underlyingConfig.Clone() cfg := src.underlyingConfig.Clone()
defer func() {
src.computedConfig = cfg
if !firstTime {
src.Trigger(cfg)
}
}()
// start the updater // start the updater
src.runUpdater(cfg) src.runUpdater(cfg)
@ -105,6 +99,7 @@ func (src *ConfigSource) rebuild(firstTime bool) {
log.Warn().Err(err). log.Warn().Err(err).
Str("policy", policy.String()). Str("policy", policy.String()).
Msg("databroker: invalid policy, ignoring") Msg("databroker: invalid policy, ignoring")
continue
} }
routeID := policy.RouteID() routeID := policy.RouteID()
@ -119,6 +114,17 @@ func (src *ConfigSource) rebuild(firstTime bool) {
cfg.Options.Policies = append(cfg.Options.Policies, *policy) cfg.Options.Policies = append(cfg.Options.Policies, *policy)
} }
err := cfg.Options.Validate()
if err != nil {
log.Warn().Err(err).Msg("databroker: invalid config detected, ignoring")
return
}
}
src.computedConfig = cfg
if !firstTime {
src.Trigger(cfg)
} }
} }

View file

@ -33,11 +33,13 @@ func TestConfigSource(t *testing.T) {
cfgs := make(chan *config.Config, 10) cfgs := make(chan *config.Config, 10)
base := config.NewDefaultOptions()
base.DataBrokerURL = mustParse("http://" + li.Addr().String())
base.InsecureServer = true
base.GRPCInsecure = true
src := NewConfigSource(config.NewStaticSource(&config.Config{ src := NewConfigSource(config.NewStaticSource(&config.Config{
Options: &config.Options{ Options: base,
DataBrokerURL: mustParse("http://" + li.Addr().String()),
GRPCInsecure: true,
},
}), func(cfg *config.Config) { }), func(cfg *config.Config) {
cfgs <- cfg cfgs <- cfg
}) })