...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package config
18
19 import (
20 "errors"
21 "os"
22 )
23
24
25 func FromEnvironment() (*Config, error) {
26 remoteURL := os.Getenv("RELIC_URL")
27 if remoteURL == "" {
28 return nil, nil
29 }
30 clientCert := os.Getenv("RELIC_CLIENT_CERT")
31 clientKey := os.Getenv("RELIC_CLIENT_KEY")
32 if clientCert == "" {
33 return nil, errors.New("RELIC_CLIENT_CERT must be set when RELIC_URL is set")
34 }
35 if clientKey == "" {
36 clientKey = clientCert
37 }
38 cfg := &Config{
39 Remote: &RemoteConfig{
40 DirectoryURL: remoteURL,
41 KeyFile: clientKey,
42 CertFile: clientCert,
43 CaCert: os.Getenv("RELIC_CACERT"),
44 },
45 }
46 return cfg, cfg.Normalize("<env>")
47 }
48
View as plain text