github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/space_quota.go (about)

     1  package ccv2
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
     8  )
     9  
    10  type SpaceQuota struct {
    11  	GUID string
    12  	Name string
    13  }
    14  
    15  // UnmarshalJSON helps unmarshal a Cloud Controller Space Quota response.
    16  func (spaceQuota *SpaceQuota) UnmarshalJSON(data []byte) error {
    17  	var ccSpaceQuota struct {
    18  		Metadata internal.Metadata `json:"metadata"`
    19  		Entity   struct {
    20  			Name string `json:"name"`
    21  		} `json:"entity"`
    22  	}
    23  	if err := json.Unmarshal(data, &ccSpaceQuota); err != nil {
    24  		return err
    25  	}
    26  
    27  	spaceQuota.GUID = ccSpaceQuota.Metadata.GUID
    28  	spaceQuota.Name = ccSpaceQuota.Entity.Name
    29  	return nil
    30  }
    31  
    32  // GetSpaceQuotaDefinition returns a Space Quota.
    33  func (client *Client) GetSpaceQuotaDefinition(guid string) (SpaceQuota, Warnings, error) {
    34  	request, err := client.newHTTPRequest(requestOptions{
    35  		RequestName: internal.GetSpaceQuotaDefinitionRequest,
    36  		URIParams:   Params{"space_quota_guid": guid},
    37  	})
    38  	if err != nil {
    39  		return SpaceQuota{}, nil, err
    40  	}
    41  
    42  	var spaceQuota SpaceQuota
    43  	response := cloudcontroller.Response{
    44  		Result: &spaceQuota,
    45  	}
    46  
    47  	err = client.connection.Make(request, &response)
    48  	return spaceQuota, response.Warnings, err
    49  }