Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 1 | package roles |
| 2 | |
| 3 | import ( |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 4 | "github.com/rackspace/gophercloud" |
| 5 | "github.com/rackspace/gophercloud/pagination" |
| 6 | |
| 7 | os "github.com/rackspace/gophercloud/openstack/identity/v2/extensions/admin/roles" |
| 8 | ) |
| 9 | |
| 10 | // List is the operation responsible for listing all available global roles |
| 11 | // that a user can adopt. |
| 12 | func List(client *gophercloud.ServiceClient) pagination.Pager { |
| 13 | return os.List(client) |
| 14 | } |
| 15 | |
| 16 | // AddUserRole is the operation responsible for assigning a particular role to |
| 17 | // a user. This is confined to the scope of the user's tenant - so the tenant |
| 18 | // ID is a required argument. |
| 19 | func AddUserRole(client *gophercloud.ServiceClient, userID, roleID string) UserRoleResult { |
| 20 | var result UserRoleResult |
| 21 | |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 22 | _, result.Err = client.Request("PUT", userRoleURL(client, userID, roleID), gophercloud.RequestOpts{ |
| 23 | OkCodes: []int{200, 201}, |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 24 | }) |
| 25 | |
| 26 | return result |
| 27 | } |
| 28 | |
| 29 | // DeleteUserRole is the operation responsible for deleting a particular role |
| 30 | // from a user. This is confined to the scope of the user's tenant - so the |
| 31 | // tenant ID is a required argument. |
| 32 | func DeleteUserRole(client *gophercloud.ServiceClient, userID, roleID string) UserRoleResult { |
| 33 | var result UserRoleResult |
| 34 | |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 35 | _, result.Err = client.Request("DELETE", userRoleURL(client, userID, roleID), gophercloud.RequestOpts{ |
| 36 | OkCodes: []int{204}, |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 37 | }) |
| 38 | |
| 39 | return result |
| 40 | } |
| 41 | |
| 42 | // UserRoleResult represents the result of either an AddUserRole or |
| 43 | // a DeleteUserRole operation. |
| 44 | type UserRoleResult struct { |
| 45 | gophercloud.ErrResult |
| 46 | } |
| 47 | |
| 48 | func userRoleURL(c *gophercloud.ServiceClient, userID, roleID string) string { |
Jamie Hannaford | 36a7dfd | 2014-10-30 14:31:34 +0100 | [diff] [blame] | 49 | return c.ServiceURL(os.UserPath, userID, os.RolePath, os.ExtPath, roleID) |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 50 | } |