Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GetQuotaStatus method #141

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions nexus3/pkg/blobstore/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions nexus3/pkg/blobstore/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 17 additions & 0 deletions nexus3/pkg/blobstore/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
20 changes: 13 additions & 7 deletions nexus3/pkg/blobstore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &quotaStatus); err != nil {
return nil, fmt.Errorf("could not unmarshal of blobstore quotastatus: %v", err)
}

return &quotaStatus, nil
}