forked from pivotal-cf/cred-alert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingestor_config.go
84 lines (66 loc) · 2.01 KB
/
ingestor_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
package config
import (
"cred-alert/cmdflag"
"errors"
yaml "gopkg.in/yaml.v2"
)
func LoadIngestorConfig(bs []byte) (*IngestorConfig, error) {
c := &IngestorConfig{}
err := yaml.Unmarshal(bs, c)
if err != nil {
return nil, err
}
return c, nil
}
type IngestorOpts struct {
ConfigFile cmdflag.FileFlag `long:"config-file" description:"path to config file" value-name:"PATH"`
}
type IngestorConfig struct {
Port uint16 `yaml:"port"`
GitHub struct {
WebhookSecretTokens []string `yaml:"webhook_secret_tokens"`
} `yaml:"github"`
PubSub struct {
ProjectName string `yaml:"project_name"`
Topic string `yaml:"topic"`
PrivateKeyPath string `yaml:"private_key_path"`
} `yaml:"pubsub"`
Metrics struct {
SentryDSN string `yaml:"sentry_dsn"`
DatadogAPIKey string `yaml:"datadog_api_key"`
Environment string `yaml:"environment"`
HoneycombWriteKey string `yaml:"honeycomb_write_key"`
} `yaml:"metrics"`
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"`
}
func (c *IngestorConfig) Validate() []error {
var errs []error
if len(c.GitHub.WebhookSecretTokens) == 0 {
errs = append(errs, errors.New("no github webhook secret tokens specified"))
}
if c.PubSub.ProjectName == "" {
errs = append(errs, errors.New("no pubsub project name specified"))
}
if c.PubSub.Topic == "" {
errs = append(errs, errors.New("no pubsub topic specified"))
}
if string(c.PubSub.PrivateKeyPath) == "" {
errs = append(errs, errors.New("no pubsub private key 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"))
}
return errs
}
func (c *IngestorConfig) IsSentryConfigured() bool {
return c.Metrics.SentryDSN != ""
}