github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/actor/v2action/service_plan.go (about)

     1  package v2action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
     7  )
     8  
     9  type ServicePlan ccv2.ServicePlan
    10  
    11  func (actor Actor) GetServicePlan(servicePlanGUID string) (ServicePlan, Warnings, error) {
    12  	servicePlan, warnings, err := actor.CloudControllerClient.GetServicePlan(servicePlanGUID)
    13  	return ServicePlan(servicePlan), Warnings(warnings), err
    14  }
    15  
    16  // GetServicePlansForService returns a list of plans associated with the service and the broker if provided
    17  func (actor Actor) GetServicePlansForService(serviceName, brokerName string) ([]ServicePlan, Warnings, error) {
    18  	service, allWarnings, err := actor.GetServiceByNameAndBrokerName(serviceName, brokerName)
    19  	if err != nil {
    20  		return []ServicePlan{}, allWarnings, err
    21  	}
    22  
    23  	servicePlans, warnings, err := actor.CloudControllerClient.GetServicePlans(ccv2.Filter{
    24  		Type:     constant.ServiceGUIDFilter,
    25  		Operator: constant.EqualOperator,
    26  		Values:   []string{service.GUID},
    27  	})
    28  	allWarnings = append(allWarnings, warnings...)
    29  	if err != nil {
    30  		return []ServicePlan{}, allWarnings, err
    31  	}
    32  
    33  	var plansToReturn []ServicePlan
    34  	for _, plan := range servicePlans {
    35  		plansToReturn = append(plansToReturn, ServicePlan(plan))
    36  	}
    37  
    38  	return plansToReturn, allWarnings, nil
    39  }
    40  
    41  func (actor Actor) getServicePlanForServiceInSpace(servicePlanName, serviceName, spaceGUID, brokerGUID string) (ServicePlan, Warnings, error) {
    42  	service, allWarnings, err := actor.getServiceByNameForSpace(serviceName, spaceGUID, brokerGUID)
    43  	if err != nil {
    44  		return ServicePlan{}, allWarnings, err
    45  	}
    46  
    47  	plans, warnings, err := actor.CloudControllerClient.GetServicePlans(ccv2.Filter{
    48  		Type:     constant.ServiceGUIDFilter,
    49  		Operator: constant.EqualOperator,
    50  		Values:   []string{service.GUID},
    51  	})
    52  	allWarnings = append(allWarnings, warnings...)
    53  	if err != nil {
    54  		return ServicePlan{}, allWarnings, err
    55  	}
    56  
    57  	for _, plan := range plans {
    58  		if servicePlanName == plan.Name {
    59  			return ServicePlan(plan), allWarnings, err
    60  		}
    61  	}
    62  
    63  	return ServicePlan{}, allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
    64  }