forked from pivotal-cf/cred-alert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker_config.go
143 lines (117 loc) · 3.75 KB
/
worker_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package config
import (
"cred-alert/cmdflag"
"errors"
"time"
yaml "gopkg.in/yaml.v2"
)
func LoadWorkerConfig(bs []byte) (*WorkerConfig, error) {
c := &WorkerConfig{}
err := yaml.Unmarshal(bs, c)
if err != nil {
return nil, err
}
return c, nil
}
type WorkerOpts struct {
ConfigFile cmdflag.FileFlag `long:"config-file" description:"path to config file" value-name:"PATH" required:"true"`
}
type WorkerConfig struct {
WorkDir string `yaml:"work_dir"`
CredentialCounterInterval time.Duration `yaml:"credential_counter_interval"`
Whitelist []string `yaml:"whitelist"`
GitHub struct {
AccessToken string `yaml:"access_token"`
PrivateKeyPath string `yaml:"private_key_path"`
PublicKeyPath string `yaml:"public_key_path"`
} `yaml:"github"`
RepositoryDiscovery struct {
Interval time.Duration `yaml:"interval"`
Organizations []string `yaml:"organizations"`
Users []string `yaml:"users"`
} `yaml:"repository_discovery"`
PubSub struct {
ProjectName string `yaml:"project_name"`
PublicKeyPath string `yaml:"public_key_path"`
FetchHint struct {
Subscription string `yaml:"subscription"`
} `yaml:"fetch_hint"`
} `yaml:"pubsub"`
Trace struct {
ProjectName string `yaml:"project_name"`
} `yaml:"trace"`
Metrics struct {
SentryDSN string `yaml:"sentry_dsn"`
DatadogAPIKey string `yaml:"datadog_api_key"`
Environment string `yaml:"environment"`
} `yaml:"metrics"`
Slack struct {
DefaultURL string `yaml:"default_webhook_url"`
DefaultChannel string `yaml:"default_channel"`
TeamURLs map[string]string `yaml:"team_webhook_urls"`
} `yaml:"slack"`
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"`
Rolodex struct {
ServerAddress string `yaml:"server_address"`
ServerPort uint16 `yaml:"server_port"`
} `yaml:"rolodex"`
}
func (c *WorkerConfig) Validate() []error {
var errs []error
if c.WorkDir == "" {
errs = append(errs, errors.New("no workdir specified"))
}
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.Identity.CACertificatePath,
c.Identity.CertificatePath,
c.Identity.PrivateKeyPath,
) {
errs = append(errs, errors.New("all identity options required if any are set"))
}
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.PubSub.ProjectName,
c.PubSub.FetchHint.Subscription,
c.PubSub.PublicKeyPath,
) {
errs = append(errs, errors.New("all pubsub options required if any are set"))
}
return errs
}