forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tls.go
61 lines (48 loc) · 1.01 KB
/
tls.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
package app
import (
"io/ioutil"
"github.com/rancher/types/apis/management.cattle.io/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func ReadTLSConfig(config *Config) error {
var err error
if config.ListenConfig != nil {
return nil
}
lc := &v3.ListenConfig{
TypeMeta: metav1.TypeMeta{
Kind: "ListenConfig",
APIVersion: "management.cattle.io/v3",
},
ObjectMeta: metav1.ObjectMeta{
Name: "cli-config",
},
Enabled: true,
}
lc.CACerts, err = readPEM("/etc/rancher/ssl/cacerts.pem")
if err != nil {
return err
}
lc.Key, err = readPEM("/etc/rancher/ssl/key.pem")
if err != nil {
return err
}
lc.Cert, err = readPEM("/etc/rancher/ssl/cert.pem")
if err != nil {
return err
}
lc.Mode = "https"
if len(config.ACMEDomains) > 0 {
lc.Mode = "acme"
lc.Domains = config.ACMEDomains
}
config.ListenConfig = lc
return nil
}
func readPEM(path string) (string, error) {
content, err := ioutil.ReadFile(path)
if err != nil {
return "", nil
}
return string(content), nil
}