forked from matrix-org/complement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
42 lines (38 loc) · 1017 Bytes
/
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
package config
import (
"os"
"strconv"
"strings"
)
type Complement struct {
BaseImageURI string
BaseImageArgs []string
DebugLoggingEnabled bool
BestEffort bool
VersionCheckIterations int
KeepBlueprints []string
}
func NewConfigFromEnvVars() *Complement {
cfg := &Complement{}
cfg.BaseImageURI = os.Getenv("COMPLEMENT_BASE_IMAGE")
cfg.BaseImageArgs = strings.Split(os.Getenv("COMPLEMENT_BASE_IMAGE_ARGS"), " ")
cfg.DebugLoggingEnabled = os.Getenv("COMPLEMENT_DEBUG") == "1"
cfg.VersionCheckIterations = parseEnvWithDefault("COMPLEMENT_VERSION_CHECK_ITERATIONS", 100)
cfg.KeepBlueprints = strings.Split(os.Getenv("COMPLEMENT_KEEP_BLUEPRINTS"), " ")
if cfg.BaseImageURI == "" {
panic("COMPLEMENT_BASE_IMAGE must be set")
}
return cfg
}
func parseEnvWithDefault(key string, def int) int {
s := os.Getenv(key)
if s != "" {
i, err := strconv.Atoi(s)
if err != nil {
// Don't bother trying to report it
return def
}
return i
}
return def
}