-
Notifications
You must be signed in to change notification settings - Fork 221
/
structure_secret_v2.go
88 lines (76 loc) · 1.98 KB
/
structure_secret_v2.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
package rancher2
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
//"k8s.io/api/core/v1"
)
// Flatteners
func flattenSecretV2(d *schema.ResourceData, in *SecretV2) error {
if in == nil {
return nil
}
if len(in.ID) > 0 {
d.SetId(d.Get("cluster_id").(string) + secretV2ClusterIDsep + in.ID)
}
d.Set("name", in.ObjectMeta.Name)
d.Set("namespace", in.ObjectMeta.Namespace)
err := d.Set("annotations", toMapInterface(in.ObjectMeta.Annotations))
if err != nil {
return err
}
err = d.Set("labels", toMapInterface(in.ObjectMeta.Labels))
if err != nil {
return err
}
d.Set("resource_version", in.ObjectMeta.ResourceVersion)
if in.Immutable != nil {
d.Set("immutable", *in.Immutable)
}
if len(in.K8SType) > 0 {
d.Set("type", string(in.K8SType))
}
if len(in.Data) > 0 {
result := make(map[string]string, len(in.Data))
for k, v := range in.Data {
result[k] = string(v)
}
err = d.Set("data", toMapInterface(result))
if err != nil {
return err
}
}
return nil
}
// Expanders
func expandSecretV2(in *schema.ResourceData) *SecretV2 {
if in == nil {
return nil
}
obj := &SecretV2{}
if len(in.Id()) > 0 {
_, obj.ID = splitID(in.Id())
}
obj.TypeMeta.Kind = secretV2Kind
obj.TypeMeta.APIVersion = secretV2APIVersion
obj.ObjectMeta.Name = in.Get("name").(string)
obj.ObjectMeta.Namespace = in.Get("namespace").(string)
if v, ok := in.Get("annotations").(map[string]interface{}); ok && len(v) > 0 {
obj.ObjectMeta.Annotations = toMapString(v)
}
if v, ok := in.Get("labels").(map[string]interface{}); ok && len(v) > 0 {
obj.ObjectMeta.Labels = toMapString(v)
}
if v, ok := in.Get("resource_version").(string); ok {
obj.ObjectMeta.ResourceVersion = v
}
if v, ok := in.Get("immutable").(bool); ok {
obj.Immutable = &v
}
if v, ok := in.Get("type").(string); ok && len(v) > 0 {
obj.Resource.Type = v
obj.K8SType = v
}
if v, ok := in.Get("data").(map[string]interface{}); ok && len(v) > 0 {
obj.StringData = toMapString(v)
}
return obj
}