github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/service_plan.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) GetServicePlanByNameOfferingAndBroker(servicePlanName, serviceOfferingName, serviceBrokerName string) (resources.ServicePlan, Warnings, error) { 10 query := []ccv3.Query{{Key: ccv3.NameFilter, Values: []string{servicePlanName}}} 11 if serviceBrokerName != "" { 12 query = append(query, ccv3.Query{Key: ccv3.ServiceBrokerNamesFilter, Values: []string{serviceBrokerName}}) 13 } 14 if serviceOfferingName != "" { 15 query = append(query, ccv3.Query{Key: ccv3.ServiceOfferingNamesFilter, Values: []string{serviceOfferingName}}) 16 } 17 18 servicePlans, warnings, err := actor.CloudControllerClient.GetServicePlans(query...) 19 if err != nil { 20 return resources.ServicePlan{}, Warnings(warnings), err 21 } 22 23 switch len(servicePlans) { 24 case 0: 25 return resources.ServicePlan{}, Warnings(warnings), actionerror.ServicePlanNotFoundError{PlanName: servicePlanName} 26 case 1: 27 return resources.ServicePlan(servicePlans[0]), Warnings(warnings), nil 28 default: 29 return resources.ServicePlan{}, Warnings(warnings), actionerror.DuplicateServicePlanError{ 30 Name: servicePlanName, 31 ServiceOfferingName: serviceOfferingName, 32 ServiceBrokerName: serviceBrokerName, 33 } 34 } 35 }