github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v2/roles/requests.go (about)

     1  package roles
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     8  )
     9  
    10  // List is the operation responsible for listing all available global roles
    11  // that a user can adopt.
    12  func List(client *gophercloud.ServiceClient) pagination.Pager {
    13  	return pagination.NewPager(client, rootURL(client), func(r pagination.PageResult) pagination.Page {
    14  		return RolePage{pagination.SinglePageBase(r)}
    15  	})
    16  }
    17  
    18  // AddUser 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.
    21  func AddUser(ctx context.Context, client *gophercloud.ServiceClient, tenantID, userID, roleID string) (r UserRoleResult) {
    22  	resp, err := client.Put(ctx, userTenantRoleURL(client, tenantID, userID, roleID), nil, nil, &gophercloud.RequestOpts{
    23  		OkCodes: []int{200, 201},
    24  	})
    25  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    26  	return
    27  }
    28  
    29  // DeleteUser 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.
    32  func DeleteUser(ctx context.Context, client *gophercloud.ServiceClient, tenantID, userID, roleID string) (r UserRoleResult) {
    33  	resp, err := client.Delete(ctx, userTenantRoleURL(client, tenantID, userID, roleID), nil)
    34  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    35  	return
    36  }