blob: a6ee8515ceb8366eff66d4ea620be5558886ac89 [file] [log] [blame]
Jamie Hannafordd165fe72014-10-30 13:53:55 +01001package roles
2
3import (
Jamie Hannafordd165fe72014-10-30 13:53:55 +01004 "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.
12func 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.
19func AddUserRole(client *gophercloud.ServiceClient, userID, roleID string) UserRoleResult {
20 var result UserRoleResult
21
Ash Wilson59fb6c42015-02-12 16:21:13 -050022 _, result.Err = client.Request("PUT", userRoleURL(client, userID, roleID), gophercloud.RequestOpts{
23 OkCodes: []int{200, 201},
Jamie Hannafordd165fe72014-10-30 13:53:55 +010024 })
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.
32func DeleteUserRole(client *gophercloud.ServiceClient, userID, roleID string) UserRoleResult {
33 var result UserRoleResult
34
Ash Wilson59fb6c42015-02-12 16:21:13 -050035 _, result.Err = client.Request("DELETE", userRoleURL(client, userID, roleID), gophercloud.RequestOpts{
36 OkCodes: []int{204},
Jamie Hannafordd165fe72014-10-30 13:53:55 +010037 })
38
39 return result
40}
41
42// UserRoleResult represents the result of either an AddUserRole or
43// a DeleteUserRole operation.
44type UserRoleResult struct {
45 gophercloud.ErrResult
46}
47
48func userRoleURL(c *gophercloud.ServiceClient, userID, roleID string) string {
Jamie Hannaford36a7dfd2014-10-30 14:31:34 +010049 return c.ServiceURL(os.UserPath, userID, os.RolePath, os.ExtPath, roleID)
Jamie Hannafordd165fe72014-10-30 13:53:55 +010050}