diff options
author | Wim <wim@42.be> | 2019-09-09 23:48:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-09 23:48:00 +0200 |
commit | 28783a4146361381e57419aa4bcf623f7ab7b80d (patch) | |
tree | c796df65d6b02e7151c4d4c7b6714b99df676171 /gateway/gateway.go | |
parent | f92927eae5b460e768f6cf5fb97e237640dfbd44 (diff) | |
download | matterbridge-msglm-28783a4146361381e57419aa4bcf623f7ab7b80d.tar.gz matterbridge-msglm-28783a4146361381e57419aa4bcf623f7ab7b80d.tar.bz2 matterbridge-msglm-28783a4146361381e57419aa4bcf623f7ab7b80d.zip |
Do configuration validation on start-up. Fixes #888 (#889)
Fail if:
* we don't have any gateways configured
* we have gateways configured but with non-existing bridge configuration
* we have gateways configured without any configuration
Diffstat (limited to 'gateway/gateway.go')
-rw-r--r-- | gateway/gateway.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go index b875ccae..af8aecd8 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -85,6 +85,7 @@ func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string { func (gw *Gateway) AddBridge(cfg *config.Bridge) error { br := gw.Router.getBridge(cfg.Account) if br == nil { + gw.checkConfig(cfg) br = bridge.New(cfg) br.Config = gw.Router.Config br.General = &gw.BridgeValues().General @@ -104,6 +105,19 @@ func (gw *Gateway) AddBridge(cfg *config.Bridge) error { return nil } +func (gw *Gateway) checkConfig(cfg *config.Bridge) { + match := false + for _, key := range gw.Router.Config.Viper().AllKeys() { + if strings.HasPrefix(key, cfg.Account) { + match = true + break + } + } + if !match { + gw.logger.Fatalf("Account %s defined in gateway %s but no configuration found, exiting.", cfg.Account, gw.Name) + } +} + // AddConfig associates a new configuration with the gateway object. func (gw *Gateway) AddConfig(cfg *config.Gateway) error { gw.Name = cfg.Name |