/
config.go
33 lines (28 loc) · 902 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package teams
import (
"net/url"
"github.com/pkg/errors"
)
type Config struct {
// Whether Teams integration is enabled.
Enabled bool `toml:"enabled" override:"enabled"`
// The incoming (to Teams) channel webhook URL.
ChannelURL string `toml:"channel-url" override:"channel-url"`
// Whether all alerts should automatically post to Teams.
Global bool `toml:"global" override:"global"`
// Whether all alerts should automatically use stateChangesOnly mode.
// Only applies if global is also set.
StateChangesOnly bool `toml:"state-changes-only" override:"state-changes-only"`
}
func NewConfig() Config {
return Config{}
}
func (c Config) Validate() error {
if c.Enabled && c.ChannelURL == "" {
return errors.New("must specify Teams channel webhook URL")
}
if _, err := url.Parse(c.ChannelURL); err != nil {
return errors.Wrapf(err, "invalid url %q", c.ChannelURL)
}
return nil
}