mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-06 08:17:42 -05:00
Merge pull request #2607 from owncloud/report-quota
[full-ci][Change] report quota in `/me/drives`
This commit is contained in:
2
go.mod
2
go.mod
@@ -20,7 +20,7 @@ require (
|
||||
github.com/blevesearch/bleve/v2 v2.1.0
|
||||
github.com/coreos/go-oidc/v3 v3.0.0
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11
|
||||
github.com/cs3org/reva v1.14.0
|
||||
github.com/cs3org/reva v1.14.1-0.20211014164014-5866f5e0f31b
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/glauth/glauth v1.1.3-0.20210729125545-b9aecdfcac31
|
||||
github.com/go-chi/chi/v5 v5.0.4
|
||||
|
||||
4
go.sum
4
go.sum
@@ -291,8 +291,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S
|
||||
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11 h1:cc/8fdzWdr/wAZOXb29J8bnXjo1poCMCLwhlFBlvhfI=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
|
||||
github.com/cs3org/reva v1.14.0 h1:vY/F/lhnsuizH4XVusUIrMZIXDCXSaJjbeudWPo/Rqk=
|
||||
github.com/cs3org/reva v1.14.0/go.mod h1:uENdZEtDFmTRt6+d4+Ro4P5XnNL+9I6gwftHEBJzHQw=
|
||||
github.com/cs3org/reva v1.14.1-0.20211014164014-5866f5e0f31b h1:IT6h3/gt83pge8hHRdb8FpIMkyrrgeEM1VF9I0RP/kA=
|
||||
github.com/cs3org/reva v1.14.1-0.20211014164014-5866f5e0f31b/go.mod h1:uENdZEtDFmTRt6+d4+Ro4P5XnNL+9I6gwftHEBJzHQw=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
|
||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/CiscoM31/godata"
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
@@ -64,8 +66,7 @@ func (g Graph) GetDrives(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
files, err := formatDrives(wdu, res.StorageSpaces)
|
||||
files, err := g.formatDrives(ctx, wdu, res.StorageSpaces)
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("error encoding response as json")
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
@@ -398,19 +399,63 @@ func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpac
|
||||
return drive, nil
|
||||
}
|
||||
|
||||
func formatDrives(baseURL *url.URL, mds []*storageprovider.StorageSpace) ([]*msgraph.Drive, error) {
|
||||
func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, mds []*storageprovider.StorageSpace) ([]*msgraph.Drive, error) {
|
||||
responses := make([]*msgraph.Drive, 0, len(mds))
|
||||
for i := range mds {
|
||||
res, err := cs3StorageSpaceToDrive(baseURL, mds[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qta, err := g.getDriveQuota(ctx, mds[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.Quota = &qta
|
||||
responses = append(responses, res)
|
||||
}
|
||||
|
||||
return responses, nil
|
||||
}
|
||||
|
||||
func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.StorageSpace) (msgraph.Quota, error) {
|
||||
client, err := g.GetClient()
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("error creating grpc client")
|
||||
return msgraph.Quota{}, err
|
||||
}
|
||||
|
||||
req := &gateway.GetQuotaRequest{
|
||||
Ref: &provider.Reference{
|
||||
ResourceId: &provider.ResourceId{
|
||||
StorageId: space.Root.StorageId,
|
||||
OpaqueId: space.Root.OpaqueId,
|
||||
},
|
||||
Path: ".",
|
||||
},
|
||||
}
|
||||
res, err := client.GetQuota(ctx, req)
|
||||
switch {
|
||||
case err != nil:
|
||||
g.logger.Error().Err(err).Msg("error sending get quota grpc request")
|
||||
return msgraph.Quota{}, err
|
||||
case res.Status.Code != cs3rpc.Code_CODE_OK:
|
||||
g.logger.Error().Err(err).Msg("error sending sending get quota grpc request")
|
||||
return msgraph.Quota{}, err
|
||||
}
|
||||
|
||||
total := int64(res.TotalBytes)
|
||||
|
||||
used := int64(res.UsedBytes)
|
||||
remaining := total - used
|
||||
qta := msgraph.Quota{
|
||||
Remaining: &remaining,
|
||||
Total: &total,
|
||||
Used: &used,
|
||||
}
|
||||
|
||||
return qta, nil
|
||||
}
|
||||
|
||||
func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota {
|
||||
switch {
|
||||
case quota != nil && quota.Total != nil:
|
||||
|
||||
Reference in New Issue
Block a user