github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/api/cloudcontroller/ccv2/space_quota.go (about) 1 package ccv2 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal" 6 ) 7 8 // SpaceQuota represents the Cloud Controller configured quota assigned to the 9 // space. 10 type SpaceQuota struct { 11 12 // GUID is the unique space quota identifier. 13 GUID string 14 15 // Name is the name given to the space quota. 16 Name string 17 } 18 19 // UnmarshalJSON helps unmarshal a Cloud Controller Space Quota response. 20 func (spaceQuota *SpaceQuota) UnmarshalJSON(data []byte) error { 21 var ccSpaceQuota struct { 22 Metadata internal.Metadata `json:"metadata"` 23 Entity struct { 24 Name string `json:"name"` 25 } `json:"entity"` 26 } 27 err := cloudcontroller.DecodeJSON(data, &ccSpaceQuota) 28 if err != nil { 29 return err 30 } 31 32 spaceQuota.GUID = ccSpaceQuota.Metadata.GUID 33 spaceQuota.Name = ccSpaceQuota.Entity.Name 34 return nil 35 } 36 37 // GetSpaceQuotaDefinition returns a Space Quota. 38 func (client *Client) GetSpaceQuotaDefinition(guid string) (SpaceQuota, Warnings, error) { 39 request, err := client.newHTTPRequest(requestOptions{ 40 RequestName: internal.GetSpaceQuotaDefinitionRequest, 41 URIParams: Params{"space_quota_guid": guid}, 42 }) 43 if err != nil { 44 return SpaceQuota{}, nil, err 45 } 46 47 var spaceQuota SpaceQuota 48 response := cloudcontroller.Response{ 49 Result: &spaceQuota, 50 } 51 52 err = client.connection.Make(request, &response) 53 return spaceQuota, response.Warnings, err 54 }