github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/actor/v3action/space.go (about)

     1  package v3action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     6  )
     7  
     8  type Space ccv3.Space
     9  
    10  // ResetSpaceIsolationSegment disassociates a space from an isolation segment.
    11  //
    12  // If the space's organization has a default isolation segment, return its
    13  // name. Otherwise return the empty string.
    14  func (actor Actor) ResetSpaceIsolationSegment(orgGUID string, spaceGUID string) (string, Warnings, error) {
    15  	var allWarnings Warnings
    16  
    17  	_, apiWarnings, err := actor.CloudControllerClient.UpdateSpaceIsolationSegmentRelationship(spaceGUID, "")
    18  	allWarnings = append(allWarnings, apiWarnings...)
    19  	if err != nil {
    20  		return "", allWarnings, err
    21  	}
    22  
    23  	isoSegRelationship, apiWarnings, err := actor.CloudControllerClient.GetOrganizationDefaultIsolationSegment(orgGUID)
    24  	allWarnings = append(allWarnings, apiWarnings...)
    25  	if err != nil {
    26  		return "", allWarnings, err
    27  	}
    28  
    29  	var isoSegName string
    30  	if isoSegRelationship.GUID != "" {
    31  		isolationSegment, apiWarnings, err := actor.CloudControllerClient.GetIsolationSegment(isoSegRelationship.GUID)
    32  		allWarnings = append(allWarnings, apiWarnings...)
    33  		if err != nil {
    34  			return "", allWarnings, err
    35  		}
    36  		isoSegName = isolationSegment.Name
    37  	}
    38  
    39  	return isoSegName, allWarnings, nil
    40  }
    41  
    42  func (actor Actor) GetSpaceByNameAndOrganization(spaceName string, orgGUID string) (Space, Warnings, error) {
    43  	spaces, warnings, err := actor.CloudControllerClient.GetSpaces(
    44  		ccv3.Query{Key: ccv3.NameFilter, Values: []string{spaceName}},
    45  		ccv3.Query{Key: ccv3.OrganizationGUIDFilter, Values: []string{orgGUID}},
    46  	)
    47  
    48  	if err != nil {
    49  		return Space{}, Warnings(warnings), err
    50  	}
    51  
    52  	if len(spaces) == 0 {
    53  		return Space{}, Warnings(warnings), actionerror.SpaceNotFoundError{Name: spaceName}
    54  	}
    55  
    56  	return Space(spaces[0]), Warnings(warnings), nil
    57  }