github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/actor/v2action/service_instance.go (about) 1 package v2action 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 7 ) 8 9 // ServiceInstance represents an instance of a service. 10 type ServiceInstance ccv2.ServiceInstance 11 12 type ServiceInstanceNotFoundError struct { 13 Name string 14 } 15 16 func (e ServiceInstanceNotFoundError) Error() string { 17 return fmt.Sprintf("Service instance '%s' not found.", e.Name) 18 } 19 20 func (actor Actor) GetServiceInstanceByNameAndSpace(name string, spaceGUID string) (ServiceInstance, Warnings, error) { 21 serviceInstances, warnings, err := actor.CloudControllerClient.GetSpaceServiceInstances( 22 spaceGUID, 23 true, 24 []ccv2.Query{ 25 ccv2.Query{ 26 Filter: ccv2.NameFilter, 27 Operator: ccv2.EqualOperator, 28 Value: name, 29 }, 30 }) 31 32 if err != nil { 33 return ServiceInstance{}, Warnings(warnings), err 34 } 35 36 if len(serviceInstances) == 0 { 37 return ServiceInstance{}, Warnings(warnings), ServiceInstanceNotFoundError{ 38 Name: name, 39 } 40 } 41 42 return ServiceInstance(serviceInstances[0]), Warnings(warnings), nil 43 }