-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymanager_v1.go
119 lines (106 loc) · 2.68 KB
/
keymanager_v1.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package openstack
import (
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls"
)
// So far only "read" is supported.
func getSupportedACLOperations() [1]string {
return [1]string{"read"}
}
func getACLSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList, // the list, returned by Barbican, is always ordered
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"project_access": {
Type: schema.TypeBool,
Optional: true,
Default: true, // defaults to true in OpenStack Barbican code
},
"users": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
},
},
}
}
func expandKeyManagerV1ACL(v interface{}, aclType string) acls.SetOpt {
users := []string{}
iTrue := true // set default value to true
res := acls.SetOpt{
ProjectAccess: &iTrue,
Users: &users,
Type: aclType,
}
if v, ok := v.([]interface{}); ok {
for _, v := range v {
if v, ok := v.(map[string]interface{}); ok {
if v, ok := v["project_access"]; ok {
if v, ok := v.(bool); ok {
res.ProjectAccess = &v
}
}
if v, ok := v["users"]; ok {
if v, ok := v.(*schema.Set); ok {
for _, v := range v.List() {
*res.Users = append(*res.Users, v.(string))
}
}
}
}
}
}
return res
}
func expandKeyManagerV1ACLs(v interface{}) acls.SetOpts {
var res []acls.SetOpt
if v, ok := v.([]interface{}); ok {
for _, v := range v {
if v, ok := v.(map[string]interface{}); ok {
for aclType, v := range v {
acl := expandKeyManagerV1ACL(v, aclType)
res = append(res, acl)
}
}
}
}
return res
}
func flattenKeyManagerV1ACLs(acl *acls.ACL) []map[string][]map[string]interface{} {
var m []map[string][]map[string]interface{}
if acl != nil {
allAcls := *acl
for _, aclOp := range getSupportedACLOperations() {
if v, ok := allAcls[aclOp]; ok {
if m == nil {
m = make([]map[string][]map[string]interface{}, 1)
m[0] = make(map[string][]map[string]interface{})
}
if m[0][aclOp] == nil {
m[0][aclOp] = make([]map[string]interface{}, 1)
}
m[0][aclOp][0] = map[string]interface{}{
"project_access": v.ProjectAccess,
"users": v.Users,
"created_at": v.Created.UTC().Format(time.RFC3339),
"updated_at": v.Updated.UTC().Format(time.RFC3339),
}
}
}
}
return m
}