github.com/sleungcy-sap/cli@v7.1.0+incompatible/actor/v7action/space_feature.go (about)

     1  package v7action
     2  
     3  import "code.cloudfoundry.org/cli/actor/actionerror"
     4  
     5  func (actor Actor) UpdateSpaceFeature(spaceName string, orgGUID string, enabled bool, feature string) (Warnings, error) {
     6  	var allWarnings Warnings
     7  
     8  	space, warnings, err := actor.GetSpaceByNameAndOrganization(spaceName, orgGUID)
     9  	allWarnings = append(allWarnings, warnings...)
    10  	if err != nil {
    11  		return allWarnings, err
    12  	}
    13  
    14  	previousValue, ccv3Warnings, err := actor.CloudControllerClient.GetSpaceFeature(space.GUID, feature)
    15  
    16  	allWarnings = append(allWarnings, ccv3Warnings...)
    17  
    18  	if err != nil {
    19  		return allWarnings, err
    20  	}
    21  
    22  	if (previousValue == enabled) && (feature == "ssh") {
    23  		if enabled {
    24  			return allWarnings, actionerror.SpaceSSHAlreadyEnabledError{Space: space.Name}
    25  		} else {
    26  			return allWarnings, actionerror.SpaceSSHAlreadyDisabledError{Space: space.Name}
    27  		}
    28  	}
    29  
    30  	ccv3Warnings, err = actor.CloudControllerClient.UpdateSpaceFeature(space.GUID, enabled, feature)
    31  	allWarnings = append(allWarnings, Warnings(ccv3Warnings)...)
    32  
    33  	return allWarnings, err
    34  }
    35  
    36  func (actor Actor) GetSpaceFeature(spaceName string, orgGUID string, feature string) (bool, Warnings, error) {
    37  	var allWarnings Warnings
    38  
    39  	space, warnings, err := actor.GetSpaceByNameAndOrganization(spaceName, orgGUID)
    40  	allWarnings = append(allWarnings, warnings...)
    41  	if err != nil {
    42  		return false, allWarnings, err
    43  	}
    44  
    45  	enabled, ccv3Warnings, err := actor.CloudControllerClient.GetSpaceFeature(space.GUID, feature)
    46  	allWarnings = append(allWarnings, Warnings(ccv3Warnings)...)
    47  
    48  	return enabled, allWarnings, err
    49  }