forked from cloudfoundry/cli
/
organization_quota.go
55 lines (45 loc) · 1.44 KB
/
organization_quota.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ccv2
import (
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
)
// OrganizationQuota is the definition of a quota for an organization.
type OrganizationQuota struct {
// GUID is the unique OrganizationQuota identifier.
GUID string
// Name is the name of the OrganizationQuota.
Name string
}
// UnmarshalJSON helps unmarshal a Cloud Controller organization quota response.
func (application *OrganizationQuota) UnmarshalJSON(data []byte) error {
var ccOrgQuota struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccOrgQuota)
if err != nil {
return err
}
application.GUID = ccOrgQuota.Metadata.GUID
application.Name = ccOrgQuota.Entity.Name
return nil
}
// GetOrganizationQuota returns an Organization Quota associated with the
// provided GUID.
func (client *Client) GetOrganizationQuota(guid string) (OrganizationQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationQuotaDefinitionRequest,
URIParams: Params{"organization_quota_guid": guid},
})
if err != nil {
return OrganizationQuota{}, nil, err
}
var orgQuota OrganizationQuota
response := cloudcontroller.Response{
Result: &orgQuota,
}
err = client.connection.Make(request, &response)
return orgQuota, response.Warnings, err
}