github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/api/cloudcontroller/ccv2/service_broker.go (about) 1 package ccv2 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal" 7 ) 8 9 // ServiceBroker represents a Cloud Controller Service Broker. 10 type ServiceBroker struct { 11 // GUID is the unique Service Broker identifier. 12 GUID string 13 // Name is the name of the service broker. 14 Name string 15 } 16 17 // UnmarshalJSON helps unmarshal a Cloud Controller Service Broker response. 18 func (serviceBroker *ServiceBroker) UnmarshalJSON(data []byte) error { 19 var ccServiceBroker struct { 20 Metadata internal.Metadata 21 Entity struct { 22 Name string `json:"name"` 23 } `json:"entity"` 24 } 25 err := cloudcontroller.DecodeJSON(data, &ccServiceBroker) 26 if err != nil { 27 return err 28 } 29 30 serviceBroker.Name = ccServiceBroker.Entity.Name 31 serviceBroker.GUID = ccServiceBroker.Metadata.GUID 32 return nil 33 } 34 35 // GetServiceBrokers returns back a list of Service Brokers given the provided 36 // filters. 37 func (client *Client) GetServiceBrokers(filters ...Filter) ([]ServiceBroker, Warnings, error) { 38 request, err := client.newHTTPRequest(requestOptions{ 39 RequestName: internal.GetServiceBrokersRequest, 40 Query: ConvertFilterParameters(filters), 41 }) 42 43 if err != nil { 44 return nil, nil, err 45 } 46 47 var fullBrokersList []ServiceBroker 48 warnings, err := client.paginate(request, ServiceBroker{}, func(item interface{}) error { 49 if broker, ok := item.(ServiceBroker); ok { 50 fullBrokersList = append(fullBrokersList, broker) 51 } else { 52 return ccerror.UnknownObjectInListError{ 53 Expected: ServiceBroker{}, 54 Unexpected: item, 55 } 56 } 57 return nil 58 }) 59 60 return fullBrokersList, warnings, err 61 }