blob: 152031ac3505ca8a47c8bd1c9de2b0fea71ff4ad [file] [log] [blame]
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01001package roles
2
3import (
Jamie Hannaford1d58e7a2014-10-30 13:23:33 +01004 "github.com/racker/perigee"
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01005 "github.com/rackspace/gophercloud"
6 "github.com/rackspace/gophercloud/pagination"
7)
8
Jamie Hannafordede36712014-10-30 13:43:42 +01009// List is the operation responsible for listing all available global roles
10// that a user can adopt.
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010011func 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 Hannaford9b642e02014-10-30 13:20:06 +010017
Jamie Hannafordede36712014-10-30 13:43:42 +010018// 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 Hannafordb15878a2014-10-30 13:26:32 +010021func AddUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID string) UserRoleResult {
22 var result UserRoleResult
Jamie Hannaford9b642e02014-10-30 13:20:06 +010023
24 _, result.Err = perigee.Request("PUT", userRoleURL(client, tenantID, userID, roleID), perigee.Options{
25 MoreHeaders: client.AuthenticatedHeaders(),
Jamie Hannaford36a7dfd2014-10-30 14:31:34 +010026 OkCodes: []int{200, 201},
Jamie Hannaford9b642e02014-10-30 13:20:06 +010027 })
28
29 return result
30}
Jamie Hannafordb15878a2014-10-30 13:26:32 +010031
Jamie Hannafordede36712014-10-30 13:43:42 +010032// 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 Hannafordb15878a2014-10-30 13:26:32 +010035func 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}