aboutsummaryrefslogtreecommitdiff
path: root/quotas.go
diff options
context:
space:
mode:
Diffstat (limited to 'quotas.go')
-rw-r--r--quotas.go45
1 files changed, 23 insertions, 22 deletions
diff --git a/quotas.go b/quotas.go
index e520f5c..894ea3c 100644
--- a/quotas.go
+++ b/quotas.go
@@ -5,40 +5,40 @@ import (
"fmt"
"strconv"
- "github.com/go-ldap/ldap/v3"
garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang"
+ "github.com/go-ldap/ldap/v3"
)
const (
// --- Default Quota Values ---
- QUOTA_WEBSITE_SIZE_DEFAULT = 1024 * 1024 * 50 // 50MB
+ QUOTA_WEBSITE_SIZE_DEFAULT = 1024 * 1024 * 50 // 50MB
QUOTA_WEBSITE_SIZE_BURSTED = 1024 * 1024 * 200 // 200MB
- QUOTA_WEBSITE_OBJECTS = 10000 // 10k objects
- QUOTA_WEBSITE_COUNT = 5 // 5 buckets
+ QUOTA_WEBSITE_OBJECTS = 10000 // 10k objects
+ QUOTA_WEBSITE_COUNT = 5 // 5 buckets
// --- Per-user overridable fields ---
FIELD_QUOTA_WEBSITE_SIZE_BURSTED = "quota_website_size_bursted"
- FIELD_QUOTA_WEBSITE_COUNT = "quota_website_count"
+ FIELD_QUOTA_WEBSITE_COUNT = "quota_website_count"
)
type UserQuota struct {
- WebsiteCount int64
+ WebsiteCount int64
WebsiteSizeDefault int64
WebsiteSizeBursted int64
- WebsiteObjects int64
+ WebsiteObjects int64
}
func NewUserQuota() *UserQuota {
- return &UserQuota {
- WebsiteCount: QUOTA_WEBSITE_COUNT,
+ return &UserQuota{
+ WebsiteCount: QUOTA_WEBSITE_COUNT,
WebsiteSizeDefault: QUOTA_WEBSITE_SIZE_DEFAULT,
WebsiteSizeBursted: QUOTA_WEBSITE_SIZE_BURSTED,
- WebsiteObjects: QUOTA_WEBSITE_OBJECTS,
+ WebsiteObjects: QUOTA_WEBSITE_OBJECTS,
}
}
var (
- ErrQuotaEmpty = fmt.Errorf("No quota is defined for this entry")
+ ErrQuotaEmpty = fmt.Errorf("No quota is defined for this entry")
ErrQuotaInvalid = fmt.Errorf("The defined quota can't be parsed")
)
@@ -72,7 +72,7 @@ func NewUserQuotaFromEntry(entry *ldap.Entry) *UserQuota {
func (q *UserQuota) DefaultWebsiteQuota() *garage.UpdateBucketRequestQuotas {
qr := garage.NewUpdateBucketRequestQuotas()
- qr.SetMaxSize(q.WebsiteSizeDefault)
+ qr.SetMaxSize(q.WebsiteSizeDefault)
qr.SetMaxObjects(q.WebsiteSizeBursted)
return qr
@@ -80,7 +80,7 @@ func (q *UserQuota) DefaultWebsiteQuota() *garage.UpdateBucketRequestQuotas {
func (q *UserQuota) WebsiteSizeAdjust(sz int64) int64 {
if sz < q.WebsiteSizeDefault {
- return q.WebsiteSizeDefault
+ return q.WebsiteSizeDefault
} else if sz > q.WebsiteSizeBursted {
return q.WebsiteSizeBursted
} else {
@@ -102,16 +102,17 @@ func (q *UserQuota) WebsiteSizeBurstedPretty() string {
// --- A quota stat we can use
type QuotaStat struct {
- Current int64 `json:"current"`
- Max int64 `json:"max"`
- Ratio float64 `json:"ratio"`
- Burstable bool `json:"burstable"`
+ Current int64 `json:"current"`
+ Max int64 `json:"max"`
+ Ratio float64 `json:"ratio"`
+ Burstable bool `json:"burstable"`
}
+
func NewQuotaStat(current, max int64, burstable bool) QuotaStat {
- return QuotaStat {
- Current: current,
- Max: max,
- Ratio: float64(current) / float64(max),
+ return QuotaStat{
+ Current: current,
+ Max: max,
+ Ratio: float64(current) / float64(max),
Burstable: burstable,
}
}
@@ -141,7 +142,7 @@ func prettyValue(v int64) string {
if v < 1024 {
return fmt.Sprintf("%d Mio", v)
}
- v = v / 1024
+ v = v / 1024
if v < 1024 {
return fmt.Sprintf("%d Gio", v)
}