github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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 GUID string 13 Name string 14 } 15 16 // UnmarshalJSON helps unmarshal a Cloud Controller organization quota response. 17 func (application *OrganizationQuota) UnmarshalJSON(data []byte) error { 18 var ccOrgQuota struct { 19 Metadata internal.Metadata `json:"metadata"` 20 Entity struct { 21 Name string `json:"name"` 22 } `json:"entity"` 23 } 24 if err := json.Unmarshal(data, &ccOrgQuota); err != nil { 25 return err 26 } 27 28 application.GUID = ccOrgQuota.Metadata.GUID 29 application.Name = ccOrgQuota.Entity.Name 30 31 return nil 32 } 33 34 // GetOrganizaitonQuota gets an organization quota (quota definition) from the API. 35 func (client *Client) GetOrganizationQuota(guid string) (OrganizationQuota, Warnings, error) { 36 request, err := client.newHTTPRequest(requestOptions{ 37 RequestName: internal.GetOrganizationQuotaDefinitionRequest, 38 URIParams: Params{"organization_quota_guid": guid}, 39 }) 40 if err != nil { 41 return OrganizationQuota{}, nil, err 42 } 43 44 var orgQuota OrganizationQuota 45 response := cloudcontroller.Response{ 46 Result: &orgQuota, 47 } 48 49 err = client.connection.Make(request, &response) 50 return orgQuota, response.Warnings, err 51 }