Jamie Hannaford | 984e917 | 2015-02-13 14:34:03 +0100 | [diff] [blame] | 1 | package users |
| 2 | |
| 3 | import ( |
Jamie Hannaford | 984e917 | 2015-02-13 14:34:03 +0100 | [diff] [blame] | 4 | "github.com/rackspace/gophercloud" |
| 5 | db "github.com/rackspace/gophercloud/openstack/db/v1/databases" |
| 6 | os "github.com/rackspace/gophercloud/openstack/db/v1/users" |
| 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | ) |
| 9 | |
| 10 | func ChangePassword(client *gophercloud.ServiceClient, instanceID string, opts os.BatchCreateOpts) UpdatePasswordsResult { |
| 11 | var res UpdatePasswordsResult |
| 12 | |
| 13 | reqBody, err := opts.ToUserCreateMap() |
| 14 | if err != nil { |
| 15 | res.Err = err |
| 16 | return res |
| 17 | } |
| 18 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame^] | 19 | _, res.Err = client.Request("PUT", baseURL(client, instanceID), gophercloud.RequestOpts{ |
| 20 | JSONBody: &reqBody, |
| 21 | OkCodes: []int{202}, |
Jamie Hannaford | 984e917 | 2015-02-13 14:34:03 +0100 | [diff] [blame] | 22 | }) |
| 23 | |
| 24 | return res |
| 25 | } |
| 26 | |
| 27 | func Update(client *gophercloud.ServiceClient, instanceID, userName string, opts os.CreateOpts) UpdateResult { |
| 28 | var res UpdateResult |
| 29 | |
| 30 | reqBody, err := opts.ToMap() |
| 31 | if err != nil { |
| 32 | res.Err = err |
| 33 | return res |
| 34 | } |
| 35 | reqBody = map[string]interface{}{"user": reqBody} |
| 36 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame^] | 37 | _, res.Err = client.Request("PUT", userURL(client, instanceID, userName), gophercloud.RequestOpts{ |
| 38 | JSONBody: &reqBody, |
| 39 | OkCodes: []int{202}, |
Jamie Hannaford | 984e917 | 2015-02-13 14:34:03 +0100 | [diff] [blame] | 40 | }) |
| 41 | |
| 42 | return res |
| 43 | } |
| 44 | |
| 45 | func Get(client *gophercloud.ServiceClient, instanceID, userName string) GetResult { |
| 46 | var res GetResult |
| 47 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame^] | 48 | _, res.Err = client.Request("GET", userURL(client, instanceID, userName), gophercloud.RequestOpts{ |
| 49 | JSONResponse: &res.Body, |
| 50 | OkCodes: []int{200}, |
Jamie Hannaford | 984e917 | 2015-02-13 14:34:03 +0100 | [diff] [blame] | 51 | }) |
| 52 | |
| 53 | return res |
| 54 | } |
| 55 | |
| 56 | func ListAccess(client *gophercloud.ServiceClient, instanceID, userName string) pagination.Pager { |
| 57 | pageFn := func(r pagination.PageResult) pagination.Page { |
| 58 | return AccessPage{pagination.LinkedPageBase{PageResult: r}} |
| 59 | } |
| 60 | |
| 61 | return pagination.NewPager(client, dbsURL(client, instanceID, userName), pageFn) |
| 62 | } |
| 63 | |
| 64 | func GrantAccess(client *gophercloud.ServiceClient, instanceID, userName string, opts db.BatchCreateOpts) GrantAccessResult { |
| 65 | var res GrantAccessResult |
| 66 | |
| 67 | reqBody, err := opts.ToDBCreateMap() |
| 68 | if err != nil { |
| 69 | res.Err = err |
| 70 | return res |
| 71 | } |
| 72 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame^] | 73 | _, res.Err = client.Request("PUT", dbsURL(client, instanceID, userName), gophercloud.RequestOpts{ |
| 74 | JSONBody: &reqBody, |
| 75 | OkCodes: []int{202}, |
Jamie Hannaford | 984e917 | 2015-02-13 14:34:03 +0100 | [diff] [blame] | 76 | }) |
| 77 | |
| 78 | return res |
| 79 | } |
| 80 | |
| 81 | func RevokeAccess(client *gophercloud.ServiceClient, instanceID, userName, dbName string) RevokeAccessResult { |
| 82 | var res RevokeAccessResult |
| 83 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame^] | 84 | _, res.Err = client.Request("DELETE", dbURL(client, instanceID, userName, dbName), gophercloud.RequestOpts{ |
| 85 | OkCodes: []int{202}, |
Jamie Hannaford | 984e917 | 2015-02-13 14:34:03 +0100 | [diff] [blame] | 86 | }) |
| 87 | |
| 88 | return res |
| 89 | } |