forked from rancher/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
90 lines (79 loc) · 1.79 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
package config
import (
"crypto/x509"
"encoding/pem"
"github.com/golang/glog"
configuration "github.com/rancher/agent/utilities/config"
"io/ioutil"
"os"
"strconv"
)
type config struct {
DockerURL string
Systemd bool
NumStats int
Auth bool
HaProxyMonitor bool
Key string
HostUUID string
Port int
IP string
ParsedPublicKey interface{}
HostUUIDCheck bool
EventsPoolSize int
CattleURL string
CattleAccessKey string
CattleSecretKey string
PidFile string
LogFile string
}
var Config config
func ParsedPublicKey() error {
keyBytes, err := ioutil.ReadFile(Config.Key)
if err != nil {
glog.Error("Error reading file")
return err
}
block, _ := pem.Decode(keyBytes)
pubKey, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return err
}
Config.ParsedPublicKey = pubKey
return nil
}
func Parse() error {
uuid, err := configuration.DockerUUID()
if err != nil {
return err
}
port, err := strconv.Atoi(configuration.HostAPIPort())
if err != nil {
return err
}
Config.HaProxyMonitor = false
Config.Port = port
Config.IP = configuration.HostAPIIP()
Config.DockerURL = "unix:///var/run/docker.sock"
Config.Auth = true
Config.HostUUID = uuid
Config.HostUUIDCheck = true
Config.Key = configuration.JwtPublicKeyFile()
Config.EventsPoolSize = 10
Config.CattleURL = configuration.APIURL("")
Config.CattleAccessKey = configuration.AccessKey()
Config.CattleSecretKey = configuration.SecretKey()
if len(Config.Key) > 0 {
if err := ParsedPublicKey(); err != nil {
glog.Error("Error reading file")
return err
}
}
s, err := os.Stat("/run/systemd/system")
if err != nil || !s.IsDir() {
Config.Systemd = false
} else {
Config.Systemd = true
}
return nil
}