blob: 7ce7bc1efba42901e56ff0a1b0ca4f34e8914a39 [file] [log] [blame]
Jamie Hannafordd165fe72014-10-30 13:53:55 +01001package roles
2
3import (
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.
13func 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.
20func 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.
34func 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.
47type UserRoleResult struct {
48 gophercloud.ErrResult
49}
50
51func userRoleURL(c *gophercloud.ServiceClient, userID, roleID string) string {
52 return c.ServiceURL(os.UserPath, userID, os.ExtPath, roleID)
53}