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