github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/role.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     5  	"code.cloudfoundry.org/cli/resources"
     6  )
     7  
     8  func (client *Client) CreateRole(roleSpec resources.Role) (resources.Role, Warnings, error) {
     9  	var responseBody resources.Role
    10  
    11  	_, warnings, err := client.MakeRequest(RequestParams{
    12  		RequestName:  internal.PostRoleRequest,
    13  		RequestBody:  roleSpec,
    14  		ResponseBody: &responseBody,
    15  	})
    16  
    17  	return responseBody, warnings, err
    18  }
    19  
    20  func (client *Client) DeleteRole(roleGUID string) (JobURL, Warnings, error) {
    21  	jobURL, warnings, err := client.MakeRequest(RequestParams{
    22  		RequestName: internal.DeleteRoleRequest,
    23  		URIParams:   internal.Params{"role_guid": roleGUID},
    24  	})
    25  
    26  	return jobURL, warnings, err
    27  }
    28  
    29  // GetRoles lists roles with optional filters & includes.
    30  func (client *Client) GetRoles(query ...Query) ([]resources.Role, IncludedResources, Warnings, error) {
    31  	var roles []resources.Role
    32  
    33  	includedResources, warnings, err := client.MakeListRequest(RequestParams{
    34  		RequestName:  internal.GetRolesRequest,
    35  		Query:        query,
    36  		ResponseBody: resources.Role{},
    37  		AppendToList: func(item interface{}) error {
    38  			roles = append(roles, item.(resources.Role))
    39  			return nil
    40  		},
    41  	})
    42  
    43  	return roles, includedResources, warnings, err
    44  }