This repository has been archived by the owner on Dec 6, 2019. It is now read-only.
/
config.go
68 lines (60 loc) · 2.73 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
60
61
62
63
64
65
66
67
68
package app
import (
"log"
"strings"
"time"
envstruct "code.cloudfoundry.org/go-envstruct"
"golang.org/x/net/idna"
)
// Config stores configuration settings for the adapter.
type Config struct {
SourceIndex string `env:"ADAPTER_INSTANCE_INDEX, required"`
CAFile string `env:"CA_FILE_PATH, required"`
CertFile string `env:"CERT_FILE_PATH, required"`
KeyFile string `env:"KEY_FILE_PATH, required"`
CommonName string `env:"TLS_COMMON_NAME, required"`
RLPCAFile string `env:"LOGS_API_CA_FILE, required"`
RLPCertFile string `env:"LOGS_API_CERT_FILE_PATH, required"`
RLPKeyFile string `env:"LOGS_API_KEY_FILE_PATH, required"`
RLPCommonName string `env:"LOGS_API_COMMON_NAME, required"`
LogsAPIAddr string `env:"LOGS_API_ADDR, required"`
LogsAPIAddrWithAZ string `env:"LOGS_API_ADDR_WITH_AZ, required"`
HealthHostport string `env:"HEALTH_HOSTPORT"`
AdapterHostport string `env:"HOSTPORT"`
PprofHostport string `env:"PPROF_HOSTPORT"`
SyslogKeepalive time.Duration `env:"SYSLOG_KEEPALIVE"`
SyslogDialTimeout time.Duration `env:"SYSLOG_DIAL_TIMEOUT"`
SyslogIOTimeout time.Duration `env:"SYSLOG_IO_TIMEOUT"`
SyslogSkipCertVerify bool `env:"SYSLOG_SKIP_CERT_VERIFY"`
MetricsToSyslogEnabled bool `env:"METRICS_TO_SYSLOG_ENABLED"`
MaxBindings int `env:"MAX_BINDINGS"`
MetricIngressAddr string `env:"METRIC_INGRESS_ADDR, required"`
MetricIngressCN string `env:"METRIC_INGRESS_CN, required"`
MetricEmitterInterval time.Duration `env:"METRIC_EMITTER_INTERVAL"`
}
// LoadConfig will load and validate the config from the current environment.
// If validation fails LoadConfig will log the error and exit the process with
// status code 1.
func LoadConfig() *Config {
cfg := Config{
HealthHostport: ":8080",
AdapterHostport: ":4443",
PprofHostport: "localhost:6060",
SyslogDialTimeout: 5 * time.Second,
SyslogIOTimeout: time.Minute,
SyslogSkipCertVerify: false,
MetricEmitterInterval: time.Minute,
MetricsToSyslogEnabled: false,
MaxBindings: 500,
}
err := envstruct.Load(&cfg)
if err != nil {
log.Fatalf("failed to load config from environment: %s", err)
}
cfg.LogsAPIAddrWithAZ, err = idna.ToASCII(cfg.LogsAPIAddrWithAZ)
if err != nil {
log.Fatalf("failed to IDN encode LogAPIAddrWithAZ %s", err)
}
cfg.LogsAPIAddrWithAZ = strings.Replace(cfg.LogsAPIAddrWithAZ, "@", "-", -1)
return &cfg
}