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