forked from pivotal-cf/cred-alert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_config.go
89 lines (73 loc) · 2.19 KB
/
api_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package config
import (
"cred-alert/cmdflag"
"errors"
yaml "gopkg.in/yaml.v2"
)
func LoadAPIConfig(bs []byte) (*APIConfig, error) {
c := &APIConfig{}
err := yaml.Unmarshal(bs, c)
if err != nil {
return nil, err
}
return c, nil
}
type APIOpts struct {
ConfigFile cmdflag.FileFlag `long:"config-file" description:"path to config file" value-name:"PATH"`
}
type APIConfig struct {
Metrics struct {
SentryDSN string `yaml:"sentry_dsn"`
Environment string `yaml:"environment"`
} `yaml:"metrics"`
MySQL struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Hostname string `yaml:"hostname"`
Port uint16 `yaml:"port"`
DBName string `yaml:"db_name"`
ServerName string `yaml:"server_name"`
CACertificatePath string `yaml:"ca_certificate_path"`
CertificatePath string `yaml:"certificate_path"`
PrivateKeyPath string `yaml:"private_key_path"`
PrivateKeyPassphrase string `yaml:"private_key_passphrase"`
} `yaml:"mysql"`
Identity struct {
CACertificatePath string `yaml:"ca_certificate_path"`
CertificatePath string `yaml:"certificate_path"`
PrivateKeyPath string `yaml:"private_key_path"`
PrivateKeyPassphrase string `yaml:"private_key_passphrase"`
} `yaml:"identity"`
API struct {
BindIP string `yaml:"bind_ip"`
BindPort uint16 `yaml:"bind_port"`
} `yaml:"rpc_server"`
}
func (c *APIConfig) Validate() []error {
var errs []error
if c.MySQL.Username == "" {
errs = append(errs, errors.New("no mysql username specified"))
}
if c.MySQL.Hostname == "" {
errs = append(errs, errors.New("no mysql hostname specified"))
}
if c.MySQL.DBName == "" {
errs = append(errs, errors.New("no mysql db name specified"))
}
if !allBlankOrAllSet(
c.MySQL.CACertificatePath,
c.MySQL.CertificatePath,
c.MySQL.PrivateKeyPath,
c.MySQL.ServerName,
) {
errs = append(errs, errors.New("all mysql tls options required if any are set"))
}
if !allBlankOrAllSet(
c.Identity.CACertificatePath,
c.Identity.CertificatePath,
c.Identity.PrivateKeyPath,
) {
errs = append(errs, errors.New("all identity options required if any are set"))
}
return nil
}