github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/keymanager/v1/acls/requests.go (about) 1 package acls 2 3 import ( 4 "context" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 ) 8 9 // GetContainerACL retrieves the ACL of a container. 10 func GetContainerACL(ctx context.Context, client *gophercloud.ServiceClient, containerID string) (r ACLResult) { 11 resp, err := client.Get(ctx, containerURL(client, containerID), &r.Body, nil) 12 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 13 return 14 } 15 16 // GetSecretACL retrieves the ACL of a secret. 17 func GetSecretACL(ctx context.Context, client *gophercloud.ServiceClient, secretID string) (r ACLResult) { 18 resp, err := client.Get(ctx, secretURL(client, secretID), &r.Body, nil) 19 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 20 return 21 } 22 23 // SetOptsBuilder allows extensions to add additional parameters to the 24 // Set request. 25 type SetOptsBuilder interface { 26 ToACLSetMap() (map[string]any, error) 27 } 28 29 // SetOpt represents options to set a particular ACL type on a resource. 30 type SetOpt struct { 31 // Type is the type of ACL to set. ie: read. 32 Type string `json:"-" required:"true"` 33 34 // Users are the list of Keystone user UUIDs. 35 Users *[]string `json:"users,omitempty"` 36 37 // ProjectAccess toggles if all users in a project can access the resource. 38 ProjectAccess *bool `json:"project-access,omitempty"` 39 } 40 41 // SetOpts represents options to set an ACL on a resource. 42 type SetOpts []SetOpt 43 44 // ToACLSetMap formats a SetOpts into a set request. 45 func (opts SetOpts) ToACLSetMap() (map[string]any, error) { 46 b := make(map[string]any) 47 for _, v := range opts { 48 m, err := gophercloud.BuildRequestBody(v, v.Type) 49 if err != nil { 50 return nil, err 51 } 52 b[v.Type] = m[v.Type] 53 } 54 return b, nil 55 } 56 57 // SetContainerACL will set an ACL on a container. 58 func SetContainerACL(ctx context.Context, client *gophercloud.ServiceClient, containerID string, opts SetOptsBuilder) (r ACLRefResult) { 59 b, err := opts.ToACLSetMap() 60 if err != nil { 61 r.Err = err 62 return 63 } 64 65 resp, err := client.Put(ctx, containerURL(client, containerID), &b, &r.Body, &gophercloud.RequestOpts{ 66 OkCodes: []int{200}, 67 }) 68 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 69 return 70 } 71 72 // SetSecretACL will set an ACL on a secret. 73 func SetSecretACL(ctx context.Context, client *gophercloud.ServiceClient, secretID string, opts SetOptsBuilder) (r ACLRefResult) { 74 b, err := opts.ToACLSetMap() 75 if err != nil { 76 r.Err = err 77 return 78 } 79 80 resp, err := client.Put(ctx, secretURL(client, secretID), &b, &r.Body, &gophercloud.RequestOpts{ 81 OkCodes: []int{200}, 82 }) 83 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 84 return 85 } 86 87 // UpdateContainerACL will update an ACL on a container. 88 func UpdateContainerACL(ctx context.Context, client *gophercloud.ServiceClient, containerID string, opts SetOptsBuilder) (r ACLRefResult) { 89 b, err := opts.ToACLSetMap() 90 if err != nil { 91 r.Err = err 92 return 93 } 94 95 resp, err := client.Patch(ctx, containerURL(client, containerID), &b, &r.Body, &gophercloud.RequestOpts{ 96 OkCodes: []int{200}, 97 }) 98 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 99 return 100 } 101 102 // UpdateSecretACL will update an ACL on a secret. 103 func UpdateSecretACL(ctx context.Context, client *gophercloud.ServiceClient, secretID string, opts SetOptsBuilder) (r ACLRefResult) { 104 b, err := opts.ToACLSetMap() 105 if err != nil { 106 r.Err = err 107 return 108 } 109 110 resp, err := client.Patch(ctx, secretURL(client, secretID), &b, &r.Body, &gophercloud.RequestOpts{ 111 OkCodes: []int{200}, 112 }) 113 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 114 return 115 } 116 117 // DeleteContainerACL will delete an ACL from a conatiner. 118 func DeleteContainerACL(ctx context.Context, client *gophercloud.ServiceClient, containerID string) (r DeleteResult) { 119 resp, err := client.Delete(ctx, containerURL(client, containerID), &gophercloud.RequestOpts{ 120 OkCodes: []int{200}, 121 }) 122 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 123 return 124 } 125 126 // DeleteSecretACL will delete an ACL from a secret. 127 func DeleteSecretACL(ctx context.Context, client *gophercloud.ServiceClient, secretID string) (r DeleteResult) { 128 resp, err := client.Delete(ctx, secretURL(client, secretID), &gophercloud.RequestOpts{ 129 OkCodes: []int{200}, 130 }) 131 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 132 return 133 }