diff --git a/changelog/unreleased/create-space-quota.md b/changelog/unreleased/create-space-quota.md new file mode 100644 index 000000000..7651cf746 --- /dev/null +++ b/changelog/unreleased/create-space-quota.md @@ -0,0 +1,7 @@ +Change: Configurable default quota + +When creating a new space a (configurable) default quota will be used (instead the hardcoded one) +One can set the EnvVar `GRAPH_SPACES_DEFAULT_QUOTA` to configure it + +https://github.com/owncloud/ocis/issues/2621 +https://jira.owncloud.com/browse/OCIS-2070 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 a8df40fa5..4357d0ba8 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..14ea3fe63 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" @@ -54,6 +55,7 @@ func (g Graph) GetDrives(w http.ResponseWriter, r *http.Request) { } g.logger.Error().Err(err).Msg("error sending list storage spaces grpc request") errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, res.Status.Message) + return } wdu, err := url.Parse(g.config.Spaces.WebDavBase) @@ -178,26 +180,18 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { driveType = *drive.DriveType } switch driveType { - case "": + case "", "project": driveType = "project" - case "share": - 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. + default: + errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("drives of type %s cannot be created via this api", driveType)) + return } csr := provider.CreateStorageSpaceRequest{ Owner: us, Type: driveType, Name: spaceName, - Quota: &provider.Quota{ - QuotaMaxBytes: quota, - }, + Quota: getQuota(drive.Quota, g.config.Spaces.DefaultQuota), } resp, err := client.CreateStorageSpace(r.Context(), &csr) @@ -208,6 +202,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) @@ -415,3 +410,21 @@ func formatDrives(baseURL *url.URL, mds []*storageprovider.StorageSpace) ([]*msg return responses, nil } + +func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota { + switch { + case quota != nil && quota.Total != nil: + if q := *quota.Total; q >= 0 { + return &provider.Quota{QuotaMaxBytes: uint64(q)} + } + fallthrough + case defaultQuota != "": + if q, err := strconv.ParseInt(defaultQuota, 10, 64); err == nil && q >= 0 { + return &provider.Quota{QuotaMaxBytes: uint64(q)} + } + fallthrough + default: + return nil + } + +}