github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/service_broker.go (about)

     1  package v7action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     6  	"code.cloudfoundry.org/cli/resources"
     7  )
     8  
     9  func (actor Actor) GetServiceBrokers() ([]resources.ServiceBroker, Warnings, error) {
    10  	serviceBrokers, warnings, err := actor.CloudControllerClient.GetServiceBrokers()
    11  	if err != nil {
    12  		return nil, Warnings(warnings), err
    13  	}
    14  
    15  	return serviceBrokers, Warnings(warnings), nil
    16  }
    17  
    18  func (actor Actor) GetServiceBrokerByName(serviceBrokerName string) (resources.ServiceBroker, Warnings, error) {
    19  	query := []ccv3.Query{
    20  		{
    21  			Key:    ccv3.NameFilter,
    22  			Values: []string{serviceBrokerName},
    23  		},
    24  	}
    25  	serviceBrokers, warnings, err := actor.CloudControllerClient.GetServiceBrokers(query...)
    26  	if err != nil {
    27  		return resources.ServiceBroker{}, Warnings(warnings), err
    28  	}
    29  
    30  	if len(serviceBrokers) == 0 {
    31  		return resources.ServiceBroker{}, Warnings(warnings), actionerror.ServiceBrokerNotFoundError{Name: serviceBrokerName}
    32  	}
    33  
    34  	return serviceBrokers[0], Warnings(warnings), nil
    35  }
    36  
    37  func (actor Actor) CreateServiceBroker(model resources.ServiceBroker) (Warnings, error) {
    38  	allWarnings := Warnings{}
    39  
    40  	jobURL, warnings, err := actor.CloudControllerClient.CreateServiceBroker(model)
    41  	allWarnings = append(allWarnings, warnings...)
    42  	if err != nil {
    43  		return allWarnings, err
    44  	}
    45  
    46  	warnings, err = actor.CloudControllerClient.PollJob(jobURL)
    47  	allWarnings = append(allWarnings, warnings...)
    48  	return allWarnings, err
    49  }
    50  
    51  func (actor Actor) UpdateServiceBroker(serviceBrokerGUID string, model resources.ServiceBroker) (Warnings, error) {
    52  	allWarnings := Warnings{}
    53  
    54  	jobURL, warnings, err := actor.CloudControllerClient.UpdateServiceBroker(serviceBrokerGUID, model)
    55  	allWarnings = append(allWarnings, warnings...)
    56  	if err != nil {
    57  		return allWarnings, err
    58  	}
    59  
    60  	warnings, err = actor.CloudControllerClient.PollJob(jobURL)
    61  	allWarnings = append(allWarnings, warnings...)
    62  	return allWarnings, err
    63  }
    64  
    65  func (actor Actor) DeleteServiceBroker(serviceBrokerGUID string) (Warnings, error) {
    66  	allWarnings := Warnings{}
    67  
    68  	jobURL, warnings, err := actor.CloudControllerClient.DeleteServiceBroker(serviceBrokerGUID)
    69  	allWarnings = append(allWarnings, warnings...)
    70  	if err != nil {
    71  		return allWarnings, err
    72  	}
    73  
    74  	warnings, err = actor.CloudControllerClient.PollJob(jobURL)
    75  	allWarnings = append(allWarnings, warnings...)
    76  
    77  	return allWarnings, err
    78  }