-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.go
98 lines (74 loc) · 1.69 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"strings"
"time"
clientv3 "go.etcd.io/etcd/client/v3"
)
type globalConfig struct {
endpoints []string
useClusterEndpoints bool
excludeLocalhost bool
dialTimeout time.Duration
commandTimeout time.Duration
keepAliveTime time.Duration
keepAliveTimeout time.Duration
insecure bool
insecureDiscovery bool
insecureSkepVerify bool
certFile string
keyFile string
caFile string
dnsDomain string
dnsService string
username string
password string
compaction bool
continueOnError bool
dbQuotaBytes int
defragRule string
printVersion bool
dryRun bool
}
func clientConfigWithoutEndpoints(gcfg globalConfig) *clientv3.ConfigSpec {
cfg := &clientv3.ConfigSpec{
DialTimeout: gcfg.dialTimeout,
KeepAliveTime: gcfg.keepAliveTime,
KeepAliveTimeout: gcfg.keepAliveTimeout,
Secure: secureConfig(gcfg),
Auth: authConfig(gcfg),
}
return cfg
}
func secureConfig(gcfg globalConfig) *clientv3.SecureConfig {
scfg := &clientv3.SecureConfig{
Cert: gcfg.certFile,
Key: gcfg.keyFile,
Cacert: gcfg.caFile,
ServerName: gcfg.dnsDomain,
InsecureTransport: gcfg.insecure,
InsecureSkipVerify: gcfg.insecureSkepVerify,
}
if gcfg.insecureDiscovery {
scfg.ServerName = ""
}
return scfg
}
func authConfig(gcfg globalConfig) *clientv3.AuthConfig {
if gcfg.username == "" {
return nil
}
if gcfg.password == "" {
userSecret := strings.SplitN(gcfg.username, ":", 2)
if len(userSecret) < 2 {
return nil
}
return &clientv3.AuthConfig{
Username: userSecret[0],
Password: userSecret[1],
}
}
return &clientv3.AuthConfig{
Username: gcfg.username,
Password: gcfg.password,
}
}