-
Notifications
You must be signed in to change notification settings - Fork 928
/
service_offering.go
29 lines (24 loc) · 1.06 KB
/
service_offering.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package v7action
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
)
type ServiceOffering ccv3.ServiceOffering
func (actor Actor) GetServiceOfferingByNameAndBroker(serviceOfferingName, serviceBrokerName string) (ServiceOffering, Warnings, error) {
query := []ccv3.Query{{Key: ccv3.NameFilter, Values: []string{serviceOfferingName}}}
if serviceBrokerName != "" {
query = append(query, ccv3.Query{Key: ccv3.ServiceBrokerNamesFilter, Values: []string{serviceBrokerName}})
}
serviceOfferings, warnings, err := actor.CloudControllerClient.GetServiceOfferings(query...)
if err != nil {
return ServiceOffering{}, Warnings(warnings), err
}
switch len(serviceOfferings) {
case 0:
return ServiceOffering{}, Warnings(warnings), actionerror.ServiceNotFoundError{Name: serviceOfferingName, Broker: serviceBrokerName}
case 1:
return ServiceOffering(serviceOfferings[0]), Warnings(warnings), nil
default:
return ServiceOffering{}, Warnings(warnings), actionerror.DuplicateServiceError{Name: serviceOfferingName}
}
}