-
Notifications
You must be signed in to change notification settings - Fork 13
/
quota.go
82 lines (71 loc) · 1.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package provisioning
import management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1"
// Quota - interface for accessing an access requests quota
type Quota interface {
// GetInterval returns the quota interval from within the access request
GetInterval() QuotaInterval
// GetIntervalString returns the string representation of the quota interval from within the access request
GetIntervalString() string
// GetLimit returns the quota limit from within the access request
GetLimit() int64
}
// QuotaInterval is the quota limit
type QuotaInterval int
const (
// Daily -
Daily QuotaInterval = iota + 1
// Weekly -
Weekly
// Monthly -
Monthly
// Annually -
Annually
)
// String returns the string value of the State
func (q QuotaInterval) String() string {
return map[QuotaInterval]string{
Daily: "daily",
Weekly: "weekly",
Monthly: "monthly",
Annually: "annually",
}[q]
}
// quotaIntervalFromString returns the quota limit represented by the string sent in
func quotaIntervalFromString(limit string) QuotaInterval {
if q, ok := map[string]QuotaInterval{
"daily": Daily,
"weekly": Weekly,
"monthly": Monthly,
"annually": Annually,
}[limit]; ok {
return q
}
return -1
}
type quota struct {
interval QuotaInterval
limit int64
}
//NewQuotaFromAccessRequest create a Quota interface from an access request or nil if no quota on access request
func NewQuotaFromAccessRequest(ar *management.AccessRequest) Quota {
if ar.Spec.Quota == nil {
return nil
}
interval := quotaIntervalFromString(ar.Spec.Quota.Interval)
if interval == -1 {
return nil
}
return "a{
limit: int64(ar.Spec.Quota.Limit),
interval: interval,
}
}
func (q *quota) GetInterval() QuotaInterval {
return q.interval
}
func (q *quota) GetIntervalString() string {
return q.interval.String()
}
func (q *quota) GetLimit() int64 {
return q.limit
}