github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/organization_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 // OrganizationQuota is the definition of a quota for an organization. 11 type OrganizationQuota struct { 12 13 // GUID is the unique OrganizationQuota identifier. 14 GUID string 15 16 // Name is the name of the OrganizationQuota. 17 Name string 18 } 19 20 // UnmarshalJSON helps unmarshal a Cloud Controller organization quota response. 21 func (application *OrganizationQuota) UnmarshalJSON(data []byte) error { 22 var ccOrgQuota struct { 23 Metadata internal.Metadata `json:"metadata"` 24 Entity struct { 25 Name string `json:"name"` 26 } `json:"entity"` 27 } 28 if err := json.Unmarshal(data, &ccOrgQuota); err != nil { 29 return err 30 } 31 32 application.GUID = ccOrgQuota.Metadata.GUID 33 application.Name = ccOrgQuota.Entity.Name 34 35 return nil 36 } 37 38 // GetOrganizationQuota returns an Organization Quota associated with the 39 // provided GUID. 40 func (client *Client) GetOrganizationQuota(guid string) (OrganizationQuota, Warnings, error) { 41 request, err := client.newHTTPRequest(requestOptions{ 42 RequestName: internal.GetOrganizationQuotaDefinitionRequest, 43 URIParams: Params{"organization_quota_guid": guid}, 44 }) 45 if err != nil { 46 return OrganizationQuota{}, nil, err 47 } 48 49 var orgQuota OrganizationQuota 50 response := cloudcontroller.Response{ 51 Result: &orgQuota, 52 } 53 54 err = client.connection.Make(request, &response) 55 return orgQuota, response.Warnings, err 56 }