From d5d33c7941608708a4c9a4910ae7660a66d24f42 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 13 Oct 2021 13:47:57 +0200 Subject: [PATCH] add default space quota --- graph/pkg/config/config.go | 3 ++- graph/pkg/flagset/flagset.go | 8 ++++++++ graph/pkg/service/v0/drives.go | 25 +++++++++++++++++-------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index e678250f5..402147277 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -51,7 +51,8 @@ type TokenManager struct { } type Spaces struct { - WebDavBase string + WebDavBase string + DefaultQuota string } // Config combines all available configuration parts. diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go index 9ac8ca49e..e691b287f 100644 --- a/graph/pkg/flagset/flagset.go +++ b/graph/pkg/flagset/flagset.go @@ -149,6 +149,14 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { Destination: &cfg.Spaces.WebDavBase, }, + &cli.StringFlag{ + Name: "default-space-quota", + Value: flags.OverrideDefaultString(cfg.Spaces.DefaultQuota, "1000000000"), + Usage: "default quota used for all spaces if no custom quota was given", + EnvVars: []string{"GRAPH_SPACES_DEFAULT_QUOTA"}, + Destination: &cfg.Spaces.DefaultQuota, + }, + &cli.StringFlag{ Name: "jwt-secret", Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"), diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index c83a5de7d..9be62567d 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "path" + "strconv" "strings" "time" @@ -184,20 +185,27 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { errorcode.GeneralException.Render(w, r, http.StatusBadRequest, "drives of type share cannot be created via this api") } - var quota uint64 - if drive.Quota != nil && drive.Quota.Total != nil { - quota = uint64(*drive.Quota.Total) - } else { - quota = 65536 // set default quota if no value was sent. + var maxBytes *int64 + switch { + case drive.Quota != nil && drive.Quota.Total != nil && *drive.Quota.Total >= 0: + maxBytes = drive.Quota.Total + case g.config.Spaces.DefaultQuota != "": + q, err := strconv.ParseInt(g.config.Spaces.DefaultQuota, 10, 64) + if err == nil && q >= 0 { + maxBytes = &q + } + } + + var quota provider.Quota + if maxBytes != nil { + quota.QuotaMaxBytes = uint64(*maxBytes) } csr := provider.CreateStorageSpaceRequest{ Owner: us, Type: driveType, Name: spaceName, - Quota: &provider.Quota{ - QuotaMaxBytes: quota, - }, + Quota: "a, } resp, err := client.CreateStorageSpace(r.Context(), &csr) @@ -208,6 +216,7 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { if resp.GetStatus().GetCode() != v1beta11.Code_CODE_OK { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "") + return } wdu, err := url.Parse(g.config.Spaces.WebDavBase)