github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+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  )
     7  
     8  type ServiceInstance ccv3.ServiceInstance
     9  
    10  func (actor Actor) GetServiceInstanceByNameAndSpace(serviceInstanceName string, spaceGUID string) (ServiceInstance, Warnings, error) {
    11  	serviceInstances, warnings, err := actor.CloudControllerClient.GetServiceInstances(
    12  		ccv3.Query{Key: ccv3.NameFilter, Values: []string{serviceInstanceName}},
    13  		ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{spaceGUID}},
    14  	)
    15  
    16  	if err != nil {
    17  		return ServiceInstance{}, Warnings(warnings), err
    18  	}
    19  
    20  	if len(serviceInstances) == 0 {
    21  		return ServiceInstance{}, Warnings(warnings), actionerror.ServiceInstanceNotFoundError{Name: serviceInstanceName}
    22  	}
    23  
    24  	//Handle multiple serviceInstances being returned as GetServiceInstances arnt filtered by space
    25  	return ServiceInstance(serviceInstances[0]), Warnings(warnings), nil
    26  }
    27  
    28  func (actor Actor) UnshareServiceInstanceByServiceInstanceAndSpace(serviceInstanceGUID string, sharedToSpaceGUID string) (Warnings, error) {
    29  	warnings, err := actor.CloudControllerClient.DeleteServiceInstanceRelationshipsSharedSpace(serviceInstanceGUID, sharedToSpaceGUID)
    30  	return Warnings(warnings), err
    31  }