github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v2action/space_quota.go (about)

     1  package v2action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     7  )
     8  
     9  type SpaceQuota ccv2.SpaceQuota
    10  
    11  func (actor Actor) GetSpaceQuota(guid string) (SpaceQuota, Warnings, error) {
    12  	spaceQuota, warnings, err := actor.CloudControllerClient.GetSpaceQuotaDefinition(guid)
    13  
    14  	if _, ok := err.(ccerror.ResourceNotFoundError); ok {
    15  		return SpaceQuota{}, Warnings(warnings), actionerror.SpaceQuotaNotFoundError{GUID: guid}
    16  	}
    17  
    18  	return SpaceQuota(spaceQuota), Warnings(warnings), err
    19  }
    20  
    21  // GetSpaceQuotaByName finds the quota by name and returns an error if not found
    22  func (actor Actor) GetSpaceQuotaByName(quotaName, orgGUID string) (SpaceQuota, Warnings, error) {
    23  	quotas, warnings, err := actor.CloudControllerClient.GetSpaceQuotas(orgGUID)
    24  
    25  	if err != nil {
    26  		return SpaceQuota{}, Warnings(warnings), err
    27  	}
    28  
    29  	for _, quota := range quotas {
    30  		if quota.Name == quotaName {
    31  			return SpaceQuota(quota), Warnings(warnings), nil
    32  		}
    33  	}
    34  
    35  	return SpaceQuota{}, Warnings(warnings), actionerror.QuotaNotFoundForNameError{Name: quotaName}
    36  }
    37  
    38  // SetSpaceQuota sets the space quota for the corresponding space
    39  func (actor Actor) SetSpaceQuota(spaceGUID, quotaGUID string) (Warnings, error) {
    40  	warnings, err := actor.CloudControllerClient.SetSpaceQuota(spaceGUID, quotaGUID)
    41  	return Warnings(warnings), err
    42  }