github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/service_instance.go (about)

     1  package v7action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     6  	"code.cloudfoundry.org/cli/resources"
     7  )
     8  
     9  func (actor Actor) GetServiceInstanceByNameAndSpace(serviceInstanceName string, spaceGUID string) (resources.ServiceInstance, Warnings, error) {
    10  	serviceInstances, warnings, err := actor.CloudControllerClient.GetServiceInstances(
    11  		ccv3.Query{Key: ccv3.NameFilter, Values: []string{serviceInstanceName}},
    12  		ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{spaceGUID}},
    13  	)
    14  
    15  	if err != nil {
    16  		return resources.ServiceInstance{}, Warnings(warnings), err
    17  	}
    18  
    19  	if len(serviceInstances) == 0 {
    20  		return resources.ServiceInstance{}, Warnings(warnings), actionerror.ServiceInstanceNotFoundError{Name: serviceInstanceName}
    21  	}
    22  
    23  	//Handle multiple serviceInstances being returned as GetServiceInstances arnt filtered by space
    24  	return serviceInstances[0], Warnings(warnings), nil
    25  }
    26  
    27  func (actor Actor) UnshareServiceInstanceByServiceInstanceAndSpace(serviceInstanceGUID string, sharedToSpaceGUID string) (Warnings, error) {
    28  	warnings, err := actor.CloudControllerClient.DeleteServiceInstanceRelationshipsSharedSpace(serviceInstanceGUID, sharedToSpaceGUID)
    29  	return Warnings(warnings), err
    30  }