github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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 } 44 45 func (actor Actor) GetServiceInstancesBySpace(spaceGUID string) ([]ServiceInstance, Warnings, error) { 46 ccv2ServiceInstances, warnings, err := actor.CloudControllerClient.GetSpaceServiceInstances( 47 spaceGUID, true, nil) 48 49 if err != nil { 50 return []ServiceInstance{}, Warnings(warnings), err 51 } 52 53 serviceInstances := make([]ServiceInstance, len(ccv2ServiceInstances)) 54 for i, ccv2ServiceInstance := range ccv2ServiceInstances { 55 serviceInstances[i] = ServiceInstance(ccv2ServiceInstance) 56 } 57 58 return serviceInstances, Warnings(warnings), nil 59 }