-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
80 lines (67 loc) · 2 KB
/
init.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
package main
import (
"flag"
"fmt"
"os"
"strconv"
clog "github.com/urlund/docker-node-identities/log"
)
// ...
var (
DockerAPIVersion float64
DockerCertPath string
DockerHost string
DockerTLSVerify bool
Debug bool
GroupLabel string
UserLabel string
Version bool
)
func init() {
// ...
if _default := os.Getenv("GROUP_LABEL"); _default == "" {
GroupLabel = "docker.node.identities.group"
}
// ...
if _default := os.Getenv("USER_LABEL"); _default == "" {
UserLabel = "docker.node.identities.user"
}
// ...
if _default := os.Getenv("DOCKER_API_VERSION"); _default == "" {
DockerAPIVersion = 1.24
}
// ...
if _default := os.Getenv("DOCKER_CERT_PATH"); _default == "" {
DockerCertPath = ""
}
// ...
if _default := os.Getenv("DOCKER_HOST"); _default == "" {
DockerHost = "unix:///var/run/docker.sock"
}
// ...
if _default := os.Getenv("DOCKER_TLS_VERIFY"); _default == "" {
DockerTLSVerify = false
}
// ...
flag.StringVar(&GroupLabel, "group-label", GroupLabel, "Label containing group config")
flag.StringVar(&UserLabel, "user-label", UserLabel, "Label containing user config")
flag.Float64Var(&DockerAPIVersion, "docker-api-version", DockerAPIVersion, "Docker API version")
flag.StringVar(&DockerCertPath, "docker-cert-path", DockerCertPath, "Path to TLS files")
flag.StringVar(&DockerHost, "docker-host", DockerHost, "Daemon socket to connect to")
flag.BoolVar(&DockerTLSVerify, "docker-tls-verify", DockerTLSVerify, "Use TLS and verify the remote")
flag.BoolVar(&Version, "version", Version, "Show version")
flag.BoolVar(&Debug, "debug", Debug, "Show debug info")
flag.Parse()
if Version {
fmt.Println("version: 1.0.4")
os.Exit(0)
}
clog.Settings = &clog.LogSettings{
Debug: Debug,
}
// ...
os.Setenv("DOCKER_API_VERSION", strconv.FormatFloat(DockerAPIVersion, 'f', 2, 64))
os.Setenv("DOCKER_CERT_PATH", DockerCertPath)
os.Setenv("DOCKER_HOST", DockerHost)
os.Setenv("DOCKER_TLS_VERIFY", strconv.FormatBool(DockerTLSVerify))
}