github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/service_broker.go (about) 1 package v7action 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 6 ) 7 8 type ServiceBroker = ccv3.ServiceBroker 9 type ServiceBrokerModel = ccv3.ServiceBrokerModel 10 11 func (actor Actor) GetServiceBrokers() ([]ServiceBroker, Warnings, error) { 12 serviceBrokers, warnings, err := actor.CloudControllerClient.GetServiceBrokers() 13 if err != nil { 14 return nil, Warnings(warnings), err 15 } 16 17 return serviceBrokers, Warnings(warnings), nil 18 } 19 20 func (actor Actor) GetServiceBrokerByName(serviceBrokerName string) (ServiceBroker, Warnings, error) { 21 query := []ccv3.Query{ 22 { 23 Key: ccv3.NameFilter, 24 Values: []string{serviceBrokerName}, 25 }, 26 } 27 serviceBrokers, warnings, err := actor.CloudControllerClient.GetServiceBrokers(query...) 28 if err != nil { 29 return ServiceBroker{}, Warnings(warnings), err 30 } 31 32 if len(serviceBrokers) == 0 { 33 return ServiceBroker{}, Warnings(warnings), actionerror.ServiceBrokerNotFoundError{Name: serviceBrokerName} 34 } 35 36 return serviceBrokers[0], Warnings(warnings), nil 37 } 38 39 func (actor Actor) CreateServiceBroker(model ServiceBrokerModel) (Warnings, error) { 40 allWarnings := Warnings{} 41 42 jobURL, warnings, err := actor.CloudControllerClient.CreateServiceBroker(model) 43 allWarnings = append(allWarnings, warnings...) 44 if err != nil { 45 return allWarnings, err 46 } 47 48 warnings, err = actor.CloudControllerClient.PollJob(jobURL) 49 allWarnings = append(allWarnings, warnings...) 50 return allWarnings, err 51 } 52 53 func (actor Actor) UpdateServiceBroker(serviceBrokerGUID string, model ServiceBrokerModel) (Warnings, error) { 54 allWarnings := Warnings{} 55 56 jobURL, warnings, err := actor.CloudControllerClient.UpdateServiceBroker(serviceBrokerGUID, model) 57 allWarnings = append(allWarnings, warnings...) 58 if err != nil { 59 return allWarnings, err 60 } 61 62 warnings, err = actor.CloudControllerClient.PollJob(jobURL) 63 allWarnings = append(allWarnings, warnings...) 64 return allWarnings, err 65 } 66 67 func (actor Actor) DeleteServiceBroker(serviceBrokerGUID string) (Warnings, error) { 68 allWarnings := Warnings{} 69 70 jobURL, warnings, err := actor.CloudControllerClient.DeleteServiceBroker(serviceBrokerGUID) 71 allWarnings = append(allWarnings, warnings...) 72 if err != nil { 73 return allWarnings, err 74 } 75 76 warnings, err = actor.CloudControllerClient.PollJob(jobURL) 77 allWarnings = append(allWarnings, warnings...) 78 79 return allWarnings, err 80 }