Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 1 | package roles |
| 2 | |
| 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | "github.com/rackspace/gophercloud/pagination" |
| 6 | ) |
| 7 | |
Jamie Hannaford | ede3671 | 2014-10-30 13:43:42 +0100 | [diff] [blame] | 8 | // List is the operation responsible for listing all available global roles |
| 9 | // that a user can adopt. |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 10 | func List(client *gophercloud.ServiceClient) pagination.Pager { |
| 11 | createPage := func(r pagination.PageResult) pagination.Page { |
| 12 | return RolePage{pagination.SinglePageBase(r)} |
| 13 | } |
| 14 | return pagination.NewPager(client, rootURL(client), createPage) |
| 15 | } |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 16 | |
Jamie Hannaford | ede3671 | 2014-10-30 13:43:42 +0100 | [diff] [blame] | 17 | // AddUserRole is the operation responsible for assigning a particular role to |
| 18 | // a user. This is confined to the scope of the user's tenant - so the tenant |
| 19 | // ID is a required argument. |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 20 | func AddUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID string) UserRoleResult { |
| 21 | var result UserRoleResult |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 22 | |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 23 | _, result.Err = client.Request("PUT", userRoleURL(client, tenantID, userID, roleID), gophercloud.RequestOpts{ |
| 24 | OkCodes: []int{200, 201}, |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 25 | }) |
| 26 | |
| 27 | return result |
| 28 | } |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 29 | |
Jamie Hannaford | ede3671 | 2014-10-30 13:43:42 +0100 | [diff] [blame] | 30 | // DeleteUserRole is the operation responsible for deleting a particular role |
| 31 | // from a user. This is confined to the scope of the user's tenant - so the |
| 32 | // tenant ID is a required argument. |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 33 | func DeleteUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID string) UserRoleResult { |
| 34 | var result UserRoleResult |
| 35 | |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 36 | _, result.Err = client.Request("DELETE", userRoleURL(client, tenantID, userID, roleID), gophercloud.RequestOpts{ |
| 37 | OkCodes: []int{204}, |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 38 | }) |
| 39 | |
| 40 | return result |
| 41 | } |