github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/actor/v2action/service_plan.go (about)

     1  package v2action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
     6  )
     7  
     8  type ServicePlan ccv2.ServicePlan
     9  
    10  func (actor Actor) GetServicePlan(servicePlanGUID string) (ServicePlan, Warnings, error) {
    11  	servicePlan, warnings, err := actor.CloudControllerClient.GetServicePlan(servicePlanGUID)
    12  	return ServicePlan(servicePlan), Warnings(warnings), err
    13  }
    14  
    15  // GetServicePlansForService returns a list of plans associated with the service
    16  func (actor Actor) GetServicePlansForService(serviceName string) ([]ServicePlan, Warnings, error) {
    17  	service, allWarnings, err := actor.GetServiceByName(serviceName)
    18  	if err != nil {
    19  		return []ServicePlan{}, allWarnings, err
    20  	}
    21  
    22  	servicePlans, warnings, err := actor.CloudControllerClient.GetServicePlans(ccv2.Filter{
    23  		Type:     constant.ServiceGUIDFilter,
    24  		Operator: constant.EqualOperator,
    25  		Values:   []string{service.GUID},
    26  	})
    27  	allWarnings = append(allWarnings, warnings...)
    28  	if err != nil {
    29  		return []ServicePlan{}, allWarnings, err
    30  	}
    31  
    32  	var plansToReturn []ServicePlan
    33  	for _, plan := range servicePlans {
    34  		plansToReturn = append(plansToReturn, ServicePlan(plan))
    35  	}
    36  
    37  	return plansToReturn, allWarnings, nil
    38  }