-
Notifications
You must be signed in to change notification settings - Fork 14
/
quota.go
51 lines (41 loc) · 1.13 KB
/
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
package v2
import (
"context"
apiv2 "github.com/exoscale/egoscale/v2/api"
"github.com/exoscale/egoscale/v2/oapi"
)
// Quota represents an Exoscale organization quota.
type Quota struct {
Resource *string
Usage *int64
Limit *int64
}
func quotaFromAPI(q *oapi.Quota) *Quota {
return &Quota{
Resource: q.Resource,
Usage: q.Usage,
Limit: q.Limit,
}
}
// ListQuotas returns the list of Exoscale organization quotas.
func (c *Client) ListQuotas(ctx context.Context, zone string) ([]*Quota, error) {
list := make([]*Quota, 0)
resp, err := c.ListQuotasWithResponse(apiv2.WithZone(ctx, zone))
if err != nil {
return nil, err
}
if resp.JSON200.Quotas != nil {
for i := range *resp.JSON200.Quotas {
list = append(list, quotaFromAPI(&(*resp.JSON200.Quotas)[i]))
}
}
return list, nil
}
// GetQuota returns the current Exoscale organization quota for the specified resource.
func (c *Client) GetQuota(ctx context.Context, zone, resource string) (*Quota, error) {
resp, err := c.GetQuotaWithResponse(apiv2.WithZone(ctx, zone), resource)
if err != nil {
return nil, err
}
return quotaFromAPI(resp.JSON200), nil
}