github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/user.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  // CreateUser creates a new Cloud Controller User from the provided UAA user
     9  // ID.
    10  func (client *Client) CreateUser(uaaUserID string) (resources.User, Warnings, error) {
    11  	type userRequestBody struct {
    12  		GUID string `json:"guid"`
    13  	}
    14  
    15  	user := userRequestBody{GUID: uaaUserID}
    16  	var responseBody resources.User
    17  
    18  	_, warnings, err := client.MakeRequest(RequestParams{
    19  		RequestName:  internal.PostUserRequest,
    20  		RequestBody:  user,
    21  		ResponseBody: &responseBody,
    22  	})
    23  
    24  	return responseBody, warnings, err
    25  }
    26  
    27  func (client *Client) DeleteUser(uaaUserID string) (JobURL, Warnings, error) {
    28  	jobURL, warnings, err := client.MakeRequest(RequestParams{
    29  		RequestName: internal.DeleteUserRequest,
    30  		URIParams:   internal.Params{"user_guid": uaaUserID},
    31  	})
    32  
    33  	return jobURL, warnings, err
    34  }
    35  
    36  func (client *Client) GetUser(userGUID string) (resources.User, Warnings, error) {
    37  	var responseBody resources.User
    38  
    39  	_, warnings, err := client.MakeRequest(RequestParams{
    40  		RequestName:  internal.GetUserRequest,
    41  		URIParams:    internal.Params{"user_guid": userGUID},
    42  		ResponseBody: &responseBody,
    43  	})
    44  
    45  	return responseBody, warnings, err
    46  }
    47  
    48  func (client *Client) GetUsers(query ...Query) ([]resources.User, Warnings, error) {
    49  	var users []resources.User
    50  
    51  	_, warnings, err := client.MakeListRequest(RequestParams{
    52  		RequestName:  internal.GetUsersRequest,
    53  		Query:        query,
    54  		ResponseBody: resources.User{},
    55  		AppendToList: func(item interface{}) error {
    56  			users = append(users, item.(resources.User))
    57  			return nil
    58  		},
    59  	})
    60  
    61  	return users, warnings, err
    62  }
    63  
    64  func (client *Client) WhoAmI() (resources.K8sUser, Warnings, error) {
    65  	var user resources.K8sUser
    66  
    67  	_, warnings, err := client.MakeRequest(RequestParams{
    68  		RequestName:  internal.WhoAmI,
    69  		ResponseBody: &user,
    70  	})
    71  
    72  	return user, warnings, err
    73  }