github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/api/cloudcontroller/ccv2/service_instance_shared_to.go (about)

     1  package ccv2
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
     6  )
     7  
     8  // ServiceInstanceSharedTo represents a Cloud Controller relationship object
     9  // that describes a service instance in another space (and possibly org) that
    10  // this service is **shared to**.
    11  type ServiceInstanceSharedTo struct {
    12  	// SpaceGUID is the unique identifier of the space that this service is
    13  	// shared to.
    14  	SpaceGUID string `json:"space_guid"`
    15  
    16  	// SpaceName is the name of the space that this service is shared to.
    17  	SpaceName string `json:"space_name"`
    18  
    19  	// OrganizationName is the name of the organization that this service is
    20  	// shared to.
    21  	OrganizationName string `json:"organization_name"`
    22  
    23  	// BoundAppCount is the number of apps that are bound to the shared to
    24  	// service instance.
    25  	BoundAppCount int `json:"bound_app_count"`
    26  }
    27  
    28  // GetServiceInstanceSharedTos returns a list of ServiceInstanceSharedTo objects.
    29  func (client *Client) GetServiceInstanceSharedTos(serviceInstanceGUID string) ([]ServiceInstanceSharedTo, Warnings, error) {
    30  	request, err := client.newHTTPRequest(requestOptions{
    31  		RequestName: internal.GetServiceInstanceSharedToRequest,
    32  		URIParams:   Params{"service_instance_guid": serviceInstanceGUID},
    33  	})
    34  
    35  	if err != nil {
    36  		return nil, nil, err
    37  	}
    38  
    39  	var fullSharedToList []ServiceInstanceSharedTo
    40  	warnings, err := client.paginate(request, ServiceInstanceSharedTo{}, func(item interface{}) error {
    41  		if instance, ok := item.(ServiceInstanceSharedTo); ok {
    42  			fullSharedToList = append(fullSharedToList, instance)
    43  		} else {
    44  			return ccerror.UnknownObjectInListError{
    45  				Expected:   ServiceInstanceSharedTo{},
    46  				Unexpected: item,
    47  			}
    48  		}
    49  		return nil
    50  	})
    51  
    52  	return fullSharedToList, warnings, err
    53  }