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

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     5  	"code.cloudfoundry.org/cli/resources"
     6  	"code.cloudfoundry.org/cli/util/lookuptable"
     7  )
     8  
     9  func (client *Client) CreateServiceCredentialBinding(binding resources.ServiceCredentialBinding) (JobURL, Warnings, error) {
    10  	return client.MakeRequest(RequestParams{
    11  		RequestName: internal.PostServiceCredentialBindingRequest,
    12  		RequestBody: binding,
    13  	})
    14  }
    15  
    16  // GetServiceCredentialBindings queries the CC API with the specified query
    17  // and returns a slice of ServiceCredentialBindings. Additionally if Apps are
    18  // included in the API response (by having `include=app` in the query) then the
    19  // App names will be added into each ServiceCredentialBinding for app bindings
    20  func (client *Client) GetServiceCredentialBindings(query ...Query) ([]resources.ServiceCredentialBinding, Warnings, error) {
    21  	var result []resources.ServiceCredentialBinding
    22  
    23  	included, warnings, err := client.MakeListRequest(RequestParams{
    24  		RequestName:  internal.GetServiceCredentialBindingsRequest,
    25  		Query:        query,
    26  		ResponseBody: resources.ServiceCredentialBinding{},
    27  		AppendToList: func(item interface{}) error {
    28  			result = append(result, item.(resources.ServiceCredentialBinding))
    29  			return nil
    30  		},
    31  	})
    32  
    33  	if len(included.Apps) > 0 {
    34  		appLookup := lookuptable.AppFromGUID(included.Apps)
    35  
    36  		for i := range result {
    37  			result[i].AppName = appLookup[result[i].AppGUID].Name
    38  			result[i].AppSpaceGUID = appLookup[result[i].AppGUID].SpaceGUID
    39  		}
    40  	}
    41  
    42  	return result, warnings, err
    43  }
    44  
    45  func (client *Client) DeleteServiceCredentialBinding(guid string) (JobURL, Warnings, error) {
    46  	return client.MakeRequest(RequestParams{
    47  		RequestName: internal.DeleteServiceCredentialBindingRequest,
    48  		URIParams:   internal.Params{"service_credential_binding_guid": guid},
    49  	})
    50  }
    51  
    52  func (client *Client) GetServiceCredentialBindingDetails(guid string) (details resources.ServiceCredentialBindingDetails, warnings Warnings, err error) {
    53  	_, warnings, err = client.MakeRequest(RequestParams{
    54  		RequestName:  internal.GetServiceCredentialBindingDetailsRequest,
    55  		URIParams:    internal.Params{"service_credential_binding_guid": guid},
    56  		ResponseBody: &details,
    57  	})
    58  
    59  	return
    60  }