From 00c663f3b676acdd72c0d7d3870b8ed5a8b99c84 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Thu, 14 Oct 2021 13:50:06 +0200 Subject: [PATCH] simplify quota creation logic --- graph/pkg/service/v0/drives.go | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index 26bba71e9..14ea3fe63 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -187,27 +187,11 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { return } - 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 = &provider.Quota{QuotaMaxBytes: uint64(*maxBytes)} - } - csr := provider.CreateStorageSpaceRequest{ Owner: us, Type: driveType, Name: spaceName, - Quota: quota, + Quota: getQuota(drive.Quota, g.config.Spaces.DefaultQuota), } resp, err := client.CreateStorageSpace(r.Context(), &csr) @@ -426,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 + } + +}