add default space quota

This commit is contained in:
jkoberg
2021-10-13 13:47:57 +02:00
parent 5703a18f17
commit d5d33c7941
3 changed files with 27 additions and 9 deletions
+2 -1
View File
@@ -51,7 +51,8 @@ type TokenManager struct {
}
type Spaces struct {
WebDavBase string
WebDavBase string
DefaultQuota string
}
// Config combines all available configuration parts.
+8
View File
@@ -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"),
+17 -8
View File
@@ -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: &quota,
}
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)