github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/helpers/servicebrokerstub/cf.go (about) 1 package servicebrokerstub 2 3 import ( 4 "encoding/json" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 func (s *ServiceBrokerStub) register(spaceScoped bool) { 12 var params []string 13 14 switch s.registered { 15 case true: 16 params = []string{"update-service-broker"} 17 case false: 18 params = []string{"create-service-broker"} 19 } 20 21 params = append(params, s.Name, s.Username, s.Password, s.URL) 22 23 if spaceScoped { 24 params = append(params, "--space-scoped") 25 } 26 27 Eventually(helpers.CF(params...)).Should(Exit(0)) 28 } 29 30 func (s *ServiceBrokerStub) deregister() { 31 s.purgeServiceOfferings(true) 32 Eventually(helpers.CF("delete-service-broker", "-f", s.Name)).Should(Exit(0)) 33 } 34 35 func (s *ServiceBrokerStub) registerViaV2() { 36 broker := map[string]interface{}{ 37 "name": s.Name, 38 "broker_url": s.URL, 39 "auth_username": s.Username, 40 "auth_password": s.Password, 41 } 42 data, err := json.Marshal(broker) 43 Expect(err).NotTo(HaveOccurred()) 44 45 Eventually(helpers.CF("curl", "-X", "POST", "/v2/service_brokers", "-d", string(data))).Should(Exit(0)) 46 } 47 48 func (s *ServiceBrokerStub) enableServiceAccess() { 49 config := s.ServiceAccessConfig 50 51 if len(config) == 0 { 52 for _, offering := range s.Services { 53 config = append(config, ServiceAccessConfig{OfferingName: offering.Name}) 54 } 55 } 56 57 for _, c := range config { 58 args := []string{"enable-service-access", c.OfferingName, "-b", s.Name} 59 60 if c.PlanName != "" { 61 args = append(args, "-p", c.PlanName) 62 } 63 64 if c.OrgName != "" { 65 args = append(args, "-o", c.OrgName) 66 } 67 68 Eventually(helpers.CF(args...)).Should(Exit(0)) 69 } 70 71 } 72 73 func (s *ServiceBrokerStub) purgeServiceOfferings(ignoreFailures bool) { 74 for _, service := range s.Services { 75 session := helpers.CF("purge-service-offering", service.Name, "-b", s.Name, "-f") 76 session.Wait() 77 78 if !ignoreFailures { 79 Expect(session).To(Exit(0)) 80 } 81 } 82 }