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