-
Notifications
You must be signed in to change notification settings - Fork 2
/
quota.go
61 lines (52 loc) · 1.84 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
52
53
54
55
56
57
58
59
60
61
package radosgwadmin
import (
"context"
)
type quotaGetRequest struct {
UID string `url:"uid" validate:"required"`
QuotaType string `url:"quota-type,omitempty" validate:"omitempty,eq=user|eq=bucket"`
}
// QuotaSetRequest - passed to a QuotaSet() call
type QuotaSetRequest struct {
UID string `url:"uid" validate:"required"`
QuotaType string `url:"quota-type" validate:"eq=user|eq=bucket"`
MaximumObjects int `url:"max-objects,omitempty"`
MaximumSizeKb int `url:"max-size-kb,omitempty"`
Enabled bool `url:"enabled"`
}
// QuotaMeta - metadata about a quota
type QuotaMeta struct {
Enabled bool `json:"enabled"`
MaxSizeKb int64 `json:"max_size_kb"`
MaxObjects int64 `json:"max_objects"`
}
// Quotas - return type when both bucket and user quotas are returned
type Quotas struct {
BucketQuota QuotaMeta `json:"bucket_quota"`
UserQuota QuotaMeta `json:"user_quota"`
}
// Quotas - get user and bucket quota info by uid
func (aa *AdminAPI) Quotas(ctx context.Context, uid string) (*Quotas, error) {
resp := &Quotas{}
req := "aGetRequest{UID: uid}
err := aa.Get(ctx, "/user?quota", req, &resp)
return resp, err
}
// QuotaBucket - get bucket quota info by uid
func (aa *AdminAPI) QuotaBucket(ctx context.Context, uid string) (*QuotaMeta, error) {
resp := &QuotaMeta{}
req := "aGetRequest{UID: uid, QuotaType: "bucket"}
err := aa.Get(ctx, "/user?quota", req, &resp)
return resp, err
}
// QuotaUser - get user quota info by uid.
func (aa *AdminAPI) QuotaUser(ctx context.Context, uid string) (*QuotaMeta, error) {
resp := &QuotaMeta{}
req := "aGetRequest{UID: uid, QuotaType: "user"}
err := aa.Get(ctx, "/user?quota", req, &resp)
return resp, err
}
// QuotaSet - Set a quota
func (aa *AdminAPI) QuotaSet(ctx context.Context, qsr *QuotaSetRequest) error {
return aa.Put(ctx, "/user?quota", qsr, nil, nil)
}