github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3.0/credentials/requests.go (about) 1 package credentials 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 const parentElement = "credential" 8 9 type ListOptsBuilder interface { 10 ToCredentialListQuery() (string, error) 11 } 12 13 type ListOpts struct { 14 UserID string `json:"user_id,omitempty"` 15 } 16 17 func (opts ListOpts) ToCredentialListQuery() (string, error) { 18 q, err := golangsdk.BuildQueryString(opts) 19 if err != nil { 20 return "", err 21 } 22 return q.String(), err 23 } 24 25 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (l ListResult) { 26 url := rootURL(client) 27 if opts != nil { 28 query, err := opts.ToCredentialListQuery() 29 if err != nil { 30 l.Err = err 31 return 32 } 33 url += query 34 } 35 36 _, l.Err = client.Get(url, &l.Body, nil) 37 return 38 } 39 40 type CreateOptsBuilder interface { 41 ToCredentialCreateMap() (map[string]interface{}, error) 42 } 43 44 type CreateOpts struct { 45 UserID string `json:"user_id" required:"true"` 46 Description string `json:"description,omitempty"` 47 } 48 49 func (opts CreateOpts) ToCredentialCreateMap() (map[string]interface{}, error) { 50 return golangsdk.BuildRequestBody(opts, parentElement) 51 } 52 53 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 54 b, err := opts.ToCredentialCreateMap() 55 if err != nil { 56 r.Err = err 57 return 58 } 59 _, r.Err = client.Post(rootURL(client), &b, &r.Body, nil) 60 return 61 } 62 63 type UpdateOptsBuilder interface { 64 ToCredentialUpdateMap() (map[string]interface{}, error) 65 } 66 67 type UpdateOpts struct { 68 Status string `json:"status,omitempty"` 69 Description string `json:"description,omitempty"` 70 } 71 72 func (opts UpdateOpts) ToCredentialUpdateMap() (map[string]interface{}, error) { 73 return golangsdk.BuildRequestBody(opts, parentElement) 74 } 75 76 func Update(client *golangsdk.ServiceClient, credentialID string, opts UpdateOptsBuilder) (r CreateResult) { 77 b, err := opts.ToCredentialUpdateMap() 78 if err != nil { 79 r.Err = err 80 return 81 } 82 _, r.Err = client.Put(resourceURL(client, credentialID), &b, &r.Body, &golangsdk.RequestOpts{ 83 OkCodes: []int{200}, 84 }) 85 return 86 } 87 88 func Get(client *golangsdk.ServiceClient, credentialID string) (r GetResult) { 89 _, r.Err = client.Get(resourceURL(client, credentialID), &r.Body, nil) 90 return 91 } 92 93 func Delete(client *golangsdk.ServiceClient, credentialID string) (r DeleteResult) { 94 _, r.Err = client.Delete(resourceURL(client, credentialID), nil) 95 return 96 }