forked from rancher/terraform-provider-rke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structure_rke_cluster_certificates.go
57 lines (49 loc) · 1.28 KB
/
structure_rke_cluster_certificates.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
package rke
import (
"sort"
"github.com/rancher/rke/pki"
)
const (
rkeClusterCertificatesKubeAdminCertName = pki.KubeAdminCertName
)
// Flatteners
func flattenRKEClusterCertificates(in map[string]pki.CertificatePKI) (string, string, string, []interface{}) {
var caCrt, clientCrt, clientKey string
outLen := len(in)
if in == nil || outLen == 0 {
return caCrt, clientCrt, clientKey, []interface{}{}
}
sortedKeys := make([]string, 0, outLen)
for k := range in {
sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys)
out := make([]interface{}, outLen)
for i, k := range sortedKeys {
v := in[k]
if k == pki.CACertName {
caCrt = v.CertificatePEM
}
if k == pki.KubeAdminCertName {
clientCrt = v.CertificatePEM
clientKey = v.KeyPEM
}
obj := map[string]interface{}{
"id": k,
"certificate": v.CertificatePEM,
"key": v.KeyPEM,
"config": v.Config,
"name": v.Name,
"common_name": v.CommonName,
"ou_name": v.OUName,
"env_name": v.EnvName,
"path": v.Path,
"key_env_name": v.KeyEnvName,
"key_path": v.KeyPath,
"config_env_name": v.ConfigEnvName,
"config_path": v.ConfigPath,
}
out[i] = obj
}
return caCrt, clientCrt, clientKey, out
}