blob: bbdf76a46ce1d7475da4109faea9bcf78783e1e3 [file] [log] [blame]
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01001package roles
2
3import (
4 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/pagination"
6)
7
Jamie Hannafordede36712014-10-30 13:43:42 +01008// List is the operation responsible for listing all available global roles
9// that a user can adopt.
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010010func List(client *gophercloud.ServiceClient) pagination.Pager {
11 createPage := func(r pagination.PageResult) pagination.Page {
12 return RolePage{pagination.SinglePageBase(r)}
13 }
14 return pagination.NewPager(client, rootURL(client), createPage)
15}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010016
Jamie Hannafordede36712014-10-30 13:43:42 +010017// 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.
Jamie Hannafordb15878a2014-10-30 13:26:32 +010020func AddUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID string) UserRoleResult {
21 var result UserRoleResult
Jamie Hannaford9b642e02014-10-30 13:20:06 +010022
Ash Wilson59fb6c42015-02-12 16:21:13 -050023 _, result.Err = client.Request("PUT", userRoleURL(client, tenantID, userID, roleID), gophercloud.RequestOpts{
24 OkCodes: []int{200, 201},
Jamie Hannaford9b642e02014-10-30 13:20:06 +010025 })
26
27 return result
28}
Jamie Hannafordb15878a2014-10-30 13:26:32 +010029
Jamie Hannafordede36712014-10-30 13:43:42 +010030// DeleteUserRole is the operation responsible for deleting a particular role
31// from a user. This is confined to the scope of the user's tenant - so the
32// tenant ID is a required argument.
Jamie Hannafordb15878a2014-10-30 13:26:32 +010033func DeleteUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID string) UserRoleResult {
34 var result UserRoleResult
35
Ash Wilson59fb6c42015-02-12 16:21:13 -050036 _, result.Err = client.Request("DELETE", userRoleURL(client, tenantID, userID, roleID), gophercloud.RequestOpts{
37 OkCodes: []int{204},
Jamie Hannafordb15878a2014-10-30 13:26:32 +010038 })
39
40 return result
41}