github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/service_broker.go (about) 1 package ccv3 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 7 "code.cloudfoundry.org/cli/resources" 8 ) 9 10 // CreateServiceBroker registers a new service broker. 11 func (client *Client) CreateServiceBroker(serviceBroker resources.ServiceBroker) (JobURL, Warnings, error) { 12 serviceBroker.CredentialsType = resources.ServiceBrokerBasicCredentials 13 14 jobURL, warnings, err := client.MakeRequest(RequestParams{ 15 RequestName: internal.PostServiceBrokerRequest, 16 RequestBody: serviceBroker, 17 }) 18 19 return jobURL, warnings, err 20 } 21 22 // DeleteServiceBroker deletes a named service broker 23 func (client *Client) DeleteServiceBroker(serviceBrokerGUID string) (JobURL, Warnings, error) { 24 jobURL, warnings, err := client.MakeRequest(RequestParams{ 25 RequestName: internal.DeleteServiceBrokerRequest, 26 URIParams: internal.Params{"service_broker_guid": serviceBrokerGUID}, 27 }) 28 29 return jobURL, warnings, err 30 } 31 32 // GetServiceBrokers lists service brokers. 33 func (client *Client) GetServiceBrokers(query ...Query) ([]resources.ServiceBroker, Warnings, error) { 34 var result []resources.ServiceBroker 35 36 _, warnings, err := client.MakeListRequest(RequestParams{ 37 RequestName: internal.GetServiceBrokersRequest, 38 Query: query, 39 ResponseBody: resources.ServiceBroker{}, 40 AppendToList: func(item interface{}) error { 41 result = append(result, item.(resources.ServiceBroker)) 42 return nil 43 }, 44 }) 45 46 return result, warnings, err 47 } 48 49 // UpdateServiceBroker updates an existing service broker. 50 func (client *Client) UpdateServiceBroker(serviceBrokerGUID string, serviceBroker resources.ServiceBroker) (JobURL, Warnings, error) { 51 if (serviceBroker.Username == "" && serviceBroker.Password != "") || (serviceBroker.Username != "" && serviceBroker.Password == "") { 52 return "", nil, errors.New("Incorrect usage: both username and password must be defined in order to do an update") 53 } 54 55 if serviceBroker.Username != "" && serviceBroker.Password != "" { 56 serviceBroker.CredentialsType = resources.ServiceBrokerBasicCredentials 57 } 58 59 jobURL, warnings, err := client.MakeRequest(RequestParams{ 60 RequestName: internal.PatchServiceBrokerRequest, 61 URIParams: internal.Params{"service_broker_guid": serviceBrokerGUID}, 62 RequestBody: serviceBroker, 63 }) 64 65 return jobURL, warnings, err 66 }