blob: 50228c906656f5dd26bcaa6ccedfe1dffad467f4 [file] [log] [blame]
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01001package roles
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01006)
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 {
Jon Perrittdb0ae142016-03-13 00:33:41 -060011 return pagination.NewPager(client, rootURL(client), func(r pagination.PageResult) pagination.Page {
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010012 return RolePage{pagination.SinglePageBase(r)}
Jon Perrittdb0ae142016-03-13 00:33:41 -060013 })
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010014}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010015
Jon Perrittdb0ae142016-03-13 00:33:41 -060016// AddUser is the operation responsible for assigning a particular role to
Jamie Hannafordede36712014-10-30 13:43:42 +010017// a user. This is confined to the scope of the user's tenant - so the tenant
18// ID is a required argument.
Jon Perritt3860b512016-03-29 12:01:48 -050019func AddUser(client *gophercloud.ServiceClient, tenantID, userID, roleID string) (r UserRoleResult) {
Joe Topjianf3275902016-08-10 15:17:46 -060020 _, r.Err = client.Put(userRoleURL(client, tenantID, userID, roleID), nil, nil, &gophercloud.RequestOpts{
21 OkCodes: []int{200, 201},
22 })
jrperritt29ae6b32016-04-13 12:59:37 -050023 return
Jamie Hannaford9b642e02014-10-30 13:20:06 +010024}
Jamie Hannafordb15878a2014-10-30 13:26:32 +010025
Jon Perrittdb0ae142016-03-13 00:33:41 -060026// DeleteUser is the operation responsible for deleting a particular role
Jamie Hannafordede36712014-10-30 13:43:42 +010027// from a user. This is confined to the scope of the user's tenant - so the
28// tenant ID is a required argument.
Jon Perritt3860b512016-03-29 12:01:48 -050029func DeleteUser(client *gophercloud.ServiceClient, tenantID, userID, roleID string) (r UserRoleResult) {
Jon Perrittdb0ae142016-03-13 00:33:41 -060030 _, r.Err = client.Delete(userRoleURL(client, tenantID, userID, roleID), nil)
jrperritt29ae6b32016-04-13 12:59:37 -050031 return
Jamie Hannafordb15878a2014-10-30 13:26:32 +010032}