From f9dd89133a423cf9920a198e862d2fd6bf3fe2c8 Mon Sep 17 00:00:00 2001 From: csibbel <155465895+csibbel@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:57:10 +0200 Subject: [PATCH] fix: GetQuotaStatus method (#141) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * GetQuotaStatus method is wrongly typed. Changed to master aim * add tests for quotas * Reformat whitespaces --------- Co-authored-by: Serkan AKÇIN --- nexus3/pkg/blobstore/azure.go | 2 +- nexus3/pkg/blobstore/file.go | 2 +- nexus3/pkg/blobstore/file_test.go | 4 ++++ nexus3/pkg/blobstore/group.go | 2 +- nexus3/pkg/blobstore/group_test.go | 4 ++++ nexus3/pkg/blobstore/s3.go | 2 +- nexus3/pkg/blobstore/s3_test.go | 17 +++++++++++++++++ nexus3/pkg/blobstore/service.go | 20 +++++++++++++------- 8 files changed, 42 insertions(+), 11 deletions(-) diff --git a/nexus3/pkg/blobstore/azure.go b/nexus3/pkg/blobstore/azure.go index 093f5b9..13b0110 100644 --- a/nexus3/pkg/blobstore/azure.go +++ b/nexus3/pkg/blobstore/azure.go @@ -78,7 +78,7 @@ func (s *BlobStoreAzureService) Delete(name string) error { return deleteBlobstore(s.Client, name) } -func (s *BlobStoreAzureService) GetQuotaStatus(name string) error { +func (s *BlobStoreAzureService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) { return getBlobstoreQuotaStatus(s.Client, name) } diff --git a/nexus3/pkg/blobstore/file.go b/nexus3/pkg/blobstore/file.go index 6ca489e..c762044 100644 --- a/nexus3/pkg/blobstore/file.go +++ b/nexus3/pkg/blobstore/file.go @@ -78,6 +78,6 @@ func (s *BlobStoreFileService) Delete(name string) error { return deleteBlobstore(s.Client, name) } -func (s *BlobStoreFileService) GetQuotaStatus(name string) error { +func (s *BlobStoreFileService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) { return getBlobstoreQuotaStatus(s.Client, name) } diff --git a/nexus3/pkg/blobstore/file_test.go b/nexus3/pkg/blobstore/file_test.go index 8d52f4c..ab843ca 100644 --- a/nexus3/pkg/blobstore/file_test.go +++ b/nexus3/pkg/blobstore/file_test.go @@ -41,6 +41,10 @@ func TestBlobstoreFile(t *testing.T) { assert.NotNil(t, updatedBlobstore) assert.NotNil(t, updatedBlobstore.SoftQuota) + quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedBlobstore.Name) + assert.Nil(t, err) + assert.Equal(t, updatedBlobstore.Name, quotaStatus.BlobStoreName) + err = service.File.Delete(bs.Name) assert.Nil(t, err) diff --git a/nexus3/pkg/blobstore/group.go b/nexus3/pkg/blobstore/group.go index 0b5480a..276e076 100644 --- a/nexus3/pkg/blobstore/group.go +++ b/nexus3/pkg/blobstore/group.go @@ -78,6 +78,6 @@ func (s *BlobStoreGroupService) Delete(name string) error { return deleteBlobstore(s.Client, name) } -func (s *BlobStoreGroupService) GetQuotaStatus(name string) error { +func (s *BlobStoreGroupService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) { return getBlobstoreQuotaStatus(s.Client, name) } diff --git a/nexus3/pkg/blobstore/group_test.go b/nexus3/pkg/blobstore/group_test.go index 4113dcd..6081b3e 100644 --- a/nexus3/pkg/blobstore/group_test.go +++ b/nexus3/pkg/blobstore/group_test.go @@ -55,6 +55,10 @@ func TestBlobstoreGroup(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, updatedGroup) + quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedGroup.Name) + assert.Nil(t, err) + assert.Equal(t, updatedGroup.Name, quotaStatus.BlobStoreName) + assert.NotNil(t, updatedGroup.SoftQuota) assert.Equal(t, blobstore.GroupFillPolicyWriteToFirst, updatedGroup.FillPolicy) diff --git a/nexus3/pkg/blobstore/s3.go b/nexus3/pkg/blobstore/s3.go index cf0832c..6d24e85 100644 --- a/nexus3/pkg/blobstore/s3.go +++ b/nexus3/pkg/blobstore/s3.go @@ -77,6 +77,6 @@ func (s *BlobStoreS3Service) Delete(name string) error { return deleteBlobstore(s.Client, name) } -func (s *BlobStoreS3Service) GetQuotaStatus(name string) error { +func (s *BlobStoreS3Service) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) { return getBlobstoreQuotaStatus(s.Client, name) } diff --git a/nexus3/pkg/blobstore/s3_test.go b/nexus3/pkg/blobstore/s3_test.go index 7f877f1..527cffb 100644 --- a/nexus3/pkg/blobstore/s3_test.go +++ b/nexus3/pkg/blobstore/s3_test.go @@ -50,6 +50,23 @@ func TestBlobstoreS3(t *testing.T) { assert.NotNil(t, s3BS.BucketConfiguration.Bucket) assert.NotNil(t, s3BS.BucketConfiguration.BucketSecurity) + s3BS.SoftQuota = &blobstore.SoftQuota{ + Type: "spaceRemainingQuota", + Limit: 100000000, + } + + err = service.S3.Update(s3BS.Name, s3BS) + assert.Nil(t, err) + + updatedBlobstore, err := service.S3.Get(s3BS.Name) + assert.Nil(t, err) + assert.NotNil(t, updatedBlobstore) + assert.NotNil(t, updatedBlobstore.SoftQuota) + + quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedBlobstore.Name) + assert.Nil(t, err) + assert.Equal(t, updatedBlobstore.Name, quotaStatus.BlobStoreName) + err = service.S3.Delete(bs.Name) assert.Nil(t, err) } diff --git a/nexus3/pkg/blobstore/service.go b/nexus3/pkg/blobstore/service.go index 7118f10..747f40b 100644 --- a/nexus3/pkg/blobstore/service.go +++ b/nexus3/pkg/blobstore/service.go @@ -71,18 +71,24 @@ func deleteBlobstore(c *client.Client, name string) error { return nil } -func (s *BlobStoreService) GetQuotaStatus(name string) error { +func (s *BlobStoreService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) { return getBlobstoreQuotaStatus(s.Client, name) } -func getBlobstoreQuotaStatus(c *client.Client, name string) error { - body, resp, err := c.Delete(fmt.Sprintf("%s/%s", blobstoreAPIEndpoint, name)) +func getBlobstoreQuotaStatus(c *client.Client, name string) (*blobstore.QuotaStatus, error) { + body, resp, err := c.Get(fmt.Sprintf("%s/%s/%s", blobstoreAPIEndpoint, name, "quota-status"), nil) if err != nil { - return err + return nil, err } - if resp.StatusCode != http.StatusNoContent { - return fmt.Errorf("could not delete blobstore \"%s\": HTTP: %d, %s", name, resp.StatusCode, string(body)) + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("could not get quotastatus for blobstore %s", name) } - return nil + + var quotaStatus blobstore.QuotaStatus + if err := json.Unmarshal(body, "aStatus); err != nil { + return nil, fmt.Errorf("could not unmarshal of blobstore quotastatus: %v", err) + } + + return "aStatus, nil }