-
Notifications
You must be signed in to change notification settings - Fork 495
/
config.go
59 lines (50 loc) · 1.32 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package swarm
import (
"github.com/influxdata/kapacitor/services/swarm/client"
"github.com/influxdata/kapacitor/tlsconfig"
"github.com/pkg/errors"
)
type Config struct {
Enabled bool `toml:"enabled" override:"enabled"`
ID string `toml:"id" override:"id"`
Servers []string `toml:"servers" override:"servers"`
// Path to CA file
SSLCA string `toml:"ssl-ca" override:"ssl-ca"`
// Path to host cert file
SSLCert string `toml:"ssl-cert" override:"ssl-cert"`
// Path to cert key file
SSLKey string `toml:"ssl-key" override:"ssl-key"`
// Use SSL but skip chain & host verification
InsecureSkipVerify bool `toml:"insecure-skip-verify" override:"insecure-skip-verify"`
}
func NewConfig() Config {
return Config{}
}
func (c Config) Validate() error {
if !c.Enabled {
return nil
}
if len(c.Servers) == 0 {
return errors.New("no api-servers specified, must provide at least one server URL")
}
return nil
}
func (c Config) ClientConfig() (client.Config, error) {
t, err := tlsconfig.Create(c.SSLCA, c.SSLCert, c.SSLKey, c.InsecureSkipVerify)
if err != nil {
return client.Config{}, err
}
return client.Config{
URLs: c.Servers,
TLSConfig: t,
}, nil
}
type Configs []Config
func (cs Configs) Validate() error {
for _, c := range cs {
if err := c.Validate(); err != nil {
return err
}
}
return nil
}