Merge pull request #2619 from kobergj/defaultSpaceQuota
Default space quota
This commit is contained in:
@@ -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
|
||||||
@@ -51,7 +51,8 @@ type TokenManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Spaces struct {
|
type Spaces struct {
|
||||||
WebDavBase string
|
WebDavBase string
|
||||||
|
DefaultQuota string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config combines all available configuration parts.
|
// Config combines all available configuration parts.
|
||||||
|
|||||||
@@ -149,6 +149,14 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
|||||||
Destination: &cfg.Spaces.WebDavBase,
|
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{
|
&cli.StringFlag{
|
||||||
Name: "jwt-secret",
|
Name: "jwt-secret",
|
||||||
Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"),
|
Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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")
|
g.logger.Error().Err(err).Msg("error sending list storage spaces grpc request")
|
||||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, res.Status.Message)
|
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, res.Status.Message)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wdu, err := url.Parse(g.config.Spaces.WebDavBase)
|
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
|
driveType = *drive.DriveType
|
||||||
}
|
}
|
||||||
switch driveType {
|
switch driveType {
|
||||||
case "":
|
case "", "project":
|
||||||
driveType = "project"
|
driveType = "project"
|
||||||
case "share":
|
default:
|
||||||
errorcode.GeneralException.Render(w, r, http.StatusBadRequest, "drives of type share cannot be created via this api")
|
errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("drives of type %s cannot be created via this api", driveType))
|
||||||
}
|
return
|
||||||
|
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
csr := provider.CreateStorageSpaceRequest{
|
csr := provider.CreateStorageSpaceRequest{
|
||||||
Owner: us,
|
Owner: us,
|
||||||
Type: driveType,
|
Type: driveType,
|
||||||
Name: spaceName,
|
Name: spaceName,
|
||||||
Quota: &provider.Quota{
|
Quota: getQuota(drive.Quota, g.config.Spaces.DefaultQuota),
|
||||||
QuotaMaxBytes: quota,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.CreateStorageSpace(r.Context(), &csr)
|
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 {
|
if resp.GetStatus().GetCode() != v1beta11.Code_CODE_OK {
|
||||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "")
|
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wdu, err := url.Parse(g.config.Spaces.WebDavBase)
|
wdu, err := url.Parse(g.config.Spaces.WebDavBase)
|
||||||
@@ -415,3 +410,21 @@ func formatDrives(baseURL *url.URL, mds []*storageprovider.StorageSpace) ([]*msg
|
|||||||
|
|
||||||
return responses, nil
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user