github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/kms/v1/grants/requests.go (about) 1 package grants 2 3 import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 4 5 type CreateOptsBuilder interface { 6 ToGrantCreateMap() (map[string]interface{}, error) 7 } 8 9 type CreateOpts struct { 10 // 36-byte ID of a CMK that matches the 11 // regular expression ^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$ 12 KeyID string `json:"key_id" required:"true"` 13 // Indicates the ID of the authorized user. 14 // The value is between 1 to 64 bytes and meets the regular expression "^[a-zA-Z0-9]{1,64}$". 15 GranteePrincipal string `json:"grantee_principal" required:"true"` 16 // Permissions that can be granted 17 Operations []string `json:"operations" required:"true"` 18 // Name of a grant which can be 1 to 255 characters in 19 // length and matches the regular expression ^[a-zA-Z0-9:/_-]{1,255}$ 20 Name string `json:"name,omitempty"` 21 // Indicates the ID of the retiring user. The value is between 1 to 64 22 // bytes and meets the regular expression "^[a-zA-Z0-9]{1,64}$". 23 RetiringPrincipal string `json:"retiring_principal,omitempty"` 24 // Sequence represents 36-byte serial number of a request message 25 Sequence string `json:"sequence,omitempty"` 26 } 27 28 // ToGrantCreateMap assembles a request body based on the contents of a 29 // CreateOpts. 30 func (opts CreateOpts) ToGrantCreateMap() (map[string]interface{}, error) { 31 return golangsdk.BuildRequestBody(opts, "") 32 } 33 34 // Create will create a new Grant based on the values in CreateOpts. To 35 // extract the Grant object from the response, call the Extract method on the 36 // CreateResult. 37 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 38 b, err := opts.ToGrantCreateMap() 39 if err != nil { 40 r.Err = err 41 return 42 } 43 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 44 OkCodes: []int{200}, 45 }) 46 return 47 } 48 49 type DeleteOptsBuilder interface { 50 ToGrantDeleteMap() (map[string]interface{}, error) 51 } 52 53 type DeleteOpts struct { 54 // 36-byte ID of a CMK that matches the regular 55 // expression ^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$ 56 KeyID string `json:"key_id" required:"true"` 57 // 64-byte ID of a grant that meets the regular 58 // expression ^[A-Fa-f0-9]{64}$ 59 GrantID string `json:"grant_id" required:"true"` 60 // Sequence represents 36-byte serial number of a request message 61 Sequence string `json:"sequence,omitempty"` 62 } 63 64 // ToGrantDeleteMap assembles a request body based on the contents of a 65 // DeleteOpts. 66 func (opts DeleteOpts) ToGrantDeleteMap() (map[string]interface{}, error) { 67 return golangsdk.BuildRequestBody(opts, "") 68 } 69 70 // Delete will delete the existing Grant based on the values in DeleteOpts. To 71 // extract result call the ExtractErr method on the DeleteResult. 72 func Delete(client *golangsdk.ServiceClient, opts DeleteOptsBuilder) (r DeleteResult) { 73 b, err := opts.ToGrantDeleteMap() 74 if err != nil { 75 r.Err = err 76 return 77 } 78 _, r.Err = client.Post(deleteURL(client), b, &r.Body, &golangsdk.RequestOpts{ 79 OkCodes: []int{200}, 80 }) 81 return 82 } 83 84 type ListOptsBuilder interface { 85 ToGrantListMap() (map[string]interface{}, error) 86 } 87 88 type ListOpts struct { 89 KeyID string `json:"key_id,omitempty"` 90 Limit string `json:"limit,omitempty"` 91 Marker string `json:"marker,omitempty"` 92 Sequence string `json:"sequence,omitempty"` 93 } 94 95 func (opts ListOpts) ToGrantListMap() (map[string]interface{}, error) { 96 return golangsdk.BuildRequestBody(opts, "") 97 } 98 99 // List will return a collection of Grants on a CMK. 100 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) { 101 b, err := opts.ToGrantListMap() 102 if err != nil { 103 r.Err = err 104 return 105 } 106 _, r.Err = client.Post(listURL(client), b, &r.Body, &golangsdk.RequestOpts{ 107 OkCodes: []int{200}, 108 }) 109 return 110 }