-
Notifications
You must be signed in to change notification settings - Fork 10
/
config.go
62 lines (57 loc) · 1.68 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
package main
// nolint: lll
import (
"net"
"github.com/brigadecore/brigade-foundations/http"
"github.com/brigadecore/brigade-foundations/os"
"github.com/brigadecore/brigade/sdk/v3/restmachinery"
)
// apiClientConfig populates the Brigade SDK's APIClientOptions from
// environment variables.
func apiClientConfig() (string, string, restmachinery.APIClientOptions, error) {
opts := restmachinery.APIClientOptions{}
address, err := os.GetRequiredEnvVar("API_ADDRESS")
if err != nil {
return address, "", opts, err
}
token, err := os.GetRequiredEnvVar("API_TOKEN")
if err != nil {
return address, token, opts, err
}
opts.AllowInsecureConnections, err =
os.GetBoolFromEnvVar("API_IGNORE_CERT_WARNINGS", false)
return address, token, opts, err
}
// ipFilterConfig populates configuration for the IP web request filter.
func ipFilterConfig() (http.IPFilterConfig, error) {
config := http.IPFilterConfig{}
var err error
config.AllowedRanges, err =
os.GetIPNetSliceFromEnvVar("ALLOWED_CLIENT_IPS", []net.IPNet{})
return config, err
}
// serverConfig populates configuration for the HTTP/S server from environment
// variables.
func serverConfig() (http.ServerConfig, error) {
config := http.ServerConfig{}
var err error
config.Port, err = os.GetIntFromEnvVar("PORT", 8080)
if err != nil {
return config, err
}
config.TLSEnabled, err = os.GetBoolFromEnvVar("TLS_ENABLED", false)
if err != nil {
return config, err
}
if config.TLSEnabled {
config.TLSCertPath, err = os.GetRequiredEnvVar("TLS_CERT_PATH")
if err != nil {
return config, err
}
config.TLSKeyPath, err = os.GetRequiredEnvVar("TLS_KEY_PATH")
if err != nil {
return config, err
}
}
return config, nil
}