aboutsummaryrefslogtreecommitdiff
path: root/quotas.go
diff options
context:
space:
mode:
Diffstat (limited to 'quotas.go')
-rw-r--r--quotas.go54
1 files changed, 52 insertions, 2 deletions
diff --git a/quotas.go b/quotas.go
index 894ea3c..c68f5de 100644
--- a/quotas.go
+++ b/quotas.go
@@ -9,16 +9,23 @@ import (
"github.com/go-ldap/ldap/v3"
)
+// Note: PIM = Personal Information Manager
const (
- // --- Default Quota Values ---
+ // --- Default Quota Values Websites ---
QUOTA_WEBSITE_SIZE_DEFAULT = 1024 * 1024 * 50 // 50MB
QUOTA_WEBSITE_SIZE_BURSTED = 1024 * 1024 * 200 // 200MB
- QUOTA_WEBSITE_OBJECTS = 10000 // 10k objects
+ QUOTA_WEBSITE_OBJECTS = 10_000 // 10k objects
QUOTA_WEBSITE_COUNT = 5 // 5 buckets
+ // --- Default Quota Values PIM ---
+ QUOTA_PIM_SIZE_DEFAULT = 1024 * 1024 * 100 // 100MB
+ QUOTA_PIM_SIZE_BURSTED = 1024 * 1024 * 500 // 500MB
+ QUOTA_PIM_OBJECTS = 100_000 // 100k objects
+
// --- Per-user overridable fields ---
FIELD_QUOTA_WEBSITE_SIZE_BURSTED = "quota_website_size_bursted"
FIELD_QUOTA_WEBSITE_COUNT = "quota_website_count"
+ FIELD_QUOTA_PIM_SIZE_BURSTED = "quota_pim_size_bursted"
)
type UserQuota struct {
@@ -26,6 +33,9 @@ type UserQuota struct {
WebsiteSizeDefault int64
WebsiteSizeBursted int64
WebsiteObjects int64
+ PimSizeDefault int64
+ PimSizeBursted int64
+ PimObjects int64
}
func NewUserQuota() *UserQuota {
@@ -34,6 +44,9 @@ func NewUserQuota() *UserQuota {
WebsiteSizeDefault: QUOTA_WEBSITE_SIZE_DEFAULT,
WebsiteSizeBursted: QUOTA_WEBSITE_SIZE_BURSTED,
WebsiteObjects: QUOTA_WEBSITE_OBJECTS,
+ PimSizeDefault: QUOTA_PIM_SIZE_DEFAULT,
+ PimSizeBursted: QUOTA_PIM_SIZE_BURSTED,
+ PimObjects: QUOTA_PIM_OBJECTS,
}
}
@@ -66,6 +79,10 @@ func NewUserQuotaFromEntry(entry *ldap.Entry) *UserQuota {
quotas.WebsiteSizeBursted = q
}
+ if q, err := entryToQuota(entry, FIELD_QUOTA_PIM_SIZE_BURSTED); err == nil {
+ quotas.PimSizeBursted = q
+ }
+
return quotas
}
@@ -78,6 +95,16 @@ func (q *UserQuota) DefaultWebsiteQuota() *garage.UpdateBucketRequestQuotas {
return qr
}
+func (q *UserQuota) DefaultPimQuota() *garage.UpdateBucketRequestQuotas {
+ qr := garage.NewUpdateBucketRequestQuotas()
+
+ qr.SetMaxSize(q.PimSizeDefault)
+ qr.SetMaxObjects(q.PimObjects)
+
+ return qr
+}
+
+// Website getters/setters
func (q *UserQuota) WebsiteSizeAdjust(sz int64) int64 {
if sz < q.WebsiteSizeDefault {
return q.WebsiteSizeDefault
@@ -100,6 +127,29 @@ func (q *UserQuota) WebsiteSizeBurstedPretty() string {
return prettyValue(q.WebsiteSizeBursted)
}
+// PIM getters/setters
+func (q *UserQuota) PimSizeAdjust(sz int64) int64 {
+ if sz < q.PimSizeDefault {
+ return q.PimSizeDefault
+ } else if sz > q.PimSizeBursted {
+ return q.PimSizeBursted
+ } else {
+ return sz
+ }
+}
+
+func (q *UserQuota) PimObjectAdjust(objs int64) int64 {
+ if objs > q.PimObjects || objs <= 0 {
+ return q.PimObjects
+ } else {
+ return objs
+ }
+}
+
+func (q *UserQuota) PimSizeBurstedPretty() string {
+ return prettyValue(q.PimSizeBursted)
+}
+
// --- A quota stat we can use
type QuotaStat struct {
Current int64 `json:"current"`