Skip to content

Commit 004319e

Browse files
committed
Barbican V1: Allow multiple ACL types in one request
1 parent 20a03f8 commit 004319e

3 files changed

Lines changed: 41 additions & 18 deletions

File tree

acceptance/openstack/keymanager/v1/acls_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ func TestACLCRUD(t *testing.T) {
3030
users := []string{user}
3131
iFalse := false
3232
setOpts := acls.SetOpts{
33-
Type: "read",
34-
Users: &users,
35-
ProjectAccess: &iFalse,
33+
acls.SetOpt{
34+
Type: "read",
35+
Users: &users,
36+
ProjectAccess: &iFalse,
37+
},
3638
}
3739

3840
aclRef, err := acls.SetSecretACL(client, secretID, setOpts).Extract()
@@ -55,8 +57,10 @@ func TestACLCRUD(t *testing.T) {
5557

5658
newUsers := []string{}
5759
updateOpts := acls.SetOpts{
58-
Type: "read",
59-
Users: &newUsers,
60+
acls.SetOpt{
61+
Type: "read",
62+
Users: &newUsers,
63+
},
6064
}
6165

6266
aclRef, err = acls.UpdateSecretACL(client, secretID, updateOpts).Extract()

openstack/keymanager/v1/acls/requests.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type SetOptsBuilder interface {
2222
ToACLSetMap() (map[string]interface{}, error)
2323
}
2424

25-
// SetOpts represents options to set an ACL on a resource.
26-
type SetOpts struct {
25+
// SetOpt represents options to set a particular ACL type on a resource.
26+
type SetOpt struct {
2727
// Type is the type of ACL to set. ie: read.
2828
Type string `json:"-" required:"true"`
2929

@@ -34,9 +34,20 @@ type SetOpts struct {
3434
ProjectAccess *bool `json:"project-access,omitempty"`
3535
}
3636

37+
// SetOpts represents options to set an ACL on a resource.
38+
type SetOpts []SetOpt
39+
3740
// ToACLSetMap formats a SetOpts into a set request.
3841
func (opts SetOpts) ToACLSetMap() (map[string]interface{}, error) {
39-
return gophercloud.BuildRequestBody(opts, opts.Type)
42+
b := make(map[string]interface{})
43+
for _, v := range opts {
44+
m, err := gophercloud.BuildRequestBody(v, v.Type)
45+
if err != nil {
46+
return nil, err
47+
}
48+
b[v.Type] = m[v.Type]
49+
}
50+
return b, nil
4051
}
4152

4253
// SetContainerACL will set an ACL on a container.

openstack/keymanager/v1/acls/testing/requests_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ func TestSetSecretACL(t *testing.T) {
3636
users := []string{"GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW"}
3737
iFalse := false
3838
setOpts := acls.SetOpts{
39-
Type: "read",
40-
Users: &users,
41-
ProjectAccess: &iFalse,
39+
acls.SetOpt{
40+
Type: "read",
41+
Users: &users,
42+
ProjectAccess: &iFalse,
43+
},
4244
}
4345

4446
actual, err := acls.SetSecretACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", setOpts).Extract()
@@ -54,9 +56,11 @@ func TestSetContainerACL(t *testing.T) {
5456
users := []string{"GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW"}
5557
iFalse := false
5658
setOpts := acls.SetOpts{
57-
Type: "read",
58-
Users: &users,
59-
ProjectAccess: &iFalse,
59+
acls.SetOpt{
60+
Type: "read",
61+
Users: &users,
62+
ProjectAccess: &iFalse,
63+
},
6064
}
6165

6266
actual, err := acls.SetContainerACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", setOpts).Extract()
@@ -89,8 +93,10 @@ func TestUpdateSecretACL(t *testing.T) {
8993

9094
newUsers := []string{}
9195
updateOpts := acls.SetOpts{
92-
Type: "read",
93-
Users: &newUsers,
96+
acls.SetOpt{
97+
Type: "read",
98+
Users: &newUsers,
99+
},
94100
}
95101

96102
actual, err := acls.UpdateSecretACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", updateOpts).Extract()
@@ -105,8 +111,10 @@ func TestUpdateContainerACL(t *testing.T) {
105111

106112
newUsers := []string{}
107113
updateOpts := acls.SetOpts{
108-
Type: "read",
109-
Users: &newUsers,
114+
acls.SetOpt{
115+
Type: "read",
116+
Users: &newUsers,
117+
},
110118
}
111119

112120
actual, err := acls.UpdateContainerACL(client.ServiceClient(), "1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c", updateOpts).Extract()

0 commit comments

Comments
 (0)