Skip to content

Commit 2b13f94

Browse files
authored
Support Object Storage quota limits visibility (#717)
* obj quota * fmt * address comment
1 parent f5822d7 commit 2b13f94

5 files changed

Lines changed: 159 additions & 0 deletions

object_storage_quota.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// ObjectStorageQuota represents a Object Storage related quota information on your account.
8+
type ObjectStorageQuota struct {
9+
QuotaID string `json:"quota_id"`
10+
QuotaName string `json:"quota_name"`
11+
EndpointType string `json:"endpoint_type"`
12+
S3Endpoint string `json:"s3_endpoint"`
13+
Description string `json:"description"`
14+
QuotaLimit int `json:"quota_limit"`
15+
ResourceMetric string `json:"resource_metric"`
16+
}
17+
18+
// ObjectStorageQuotaUsage is the usage data for a specific Object Storage related quota on your account.
19+
type ObjectStorageQuotaUsage struct {
20+
QuotaLimit int `json:"quota_limit"`
21+
Usage *int `json:"usage"`
22+
}
23+
24+
// ListObjectStorageQuotas lists the active ObjectStorage-related quotas applied to your account.
25+
// Object Storage Quota related features are under v4beta and may not currently be available to all users.
26+
func (c *Client) ListObjectStorageQuotas(ctx context.Context, opts *ListOptions) ([]ObjectStorageQuota, error) {
27+
return getPaginatedResults[ObjectStorageQuota](ctx, c, formatAPIPath("object-storage/quotas"), opts)
28+
}
29+
30+
// GetObjectStorageQuota gets information about a specific ObjectStorage-related quota on your account.
31+
// Object Storage Quota related features are under v4beta and may not currently be available to all users.
32+
func (c *Client) GetObjectStorageQuota(ctx context.Context, quotaID string) (*ObjectStorageQuota, error) {
33+
e := formatAPIPath("object-storage/quotas/%s", quotaID)
34+
return doGETRequest[ObjectStorageQuota](ctx, c, e)
35+
}
36+
37+
// GetObjectStorageQuotaUsage gets usage data for a specific ObjectStorage Quota resource you can have on your account and the current usage for that resource.
38+
// Object Storage Quota related features are under v4beta and may not currently be available to all users.
39+
func (c *Client) GetObjectStorageQuotaUsage(ctx context.Context, quotaID string) (*ObjectStorageQuotaUsage, error) {
40+
e := formatAPIPath("object-storage/quotas/%s/usage", quotaID)
41+
return doGETRequest[ObjectStorageQuotaUsage](ctx, c, e)
42+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"quota_id": "obj-objects-us-ord-1",
3+
"quota_name": "Object Storage Maximum Objects",
4+
"description": "Maximum number of Objects this customer is allowed to have on this endpoint.",
5+
"endpoint_type": "E1",
6+
"s3_endpoint": "us-iad-1.linodeobjects.com",
7+
"quota_limit": 50,
8+
"resource_metric": "object"
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"data":[
3+
{
4+
"quota_id": "obj-objects-us-ord-1",
5+
"quota_name": "Object Storage Maximum Objects",
6+
"description": "Maximum number of Objects this customer is allowed to have on this endpoint.",
7+
"endpoint_type": "E1",
8+
"s3_endpoint": "us-iad-1.linodeobjects.com",
9+
"quota_limit": 50,
10+
"resource_metric": "object"
11+
},
12+
{
13+
"quota_id": "obj-bucket-us-ord-1",
14+
"quota_name": "Object Storage Maximum Buckets",
15+
"description": "Maximum number of buckets this customer is allowed to have on this endpoint.",
16+
"endpoint_type": "E1",
17+
"s3_endpoint": "us-iad-1.linodeobjects.com",
18+
"quota_limit": 50,
19+
"resource_metric": "bucket"
20+
}],
21+
"page": 1,
22+
"pages": 1,
23+
"results": 2
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"quota_limit": 100,
3+
"usage": 10
4+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package unit
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/linode/linodego"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestObjectStorageQuotas_Get(t *testing.T) {
12+
fixtureData, err := fixtures.GetFixture("object_storage_quotas_get")
13+
assert.NoError(t, err)
14+
15+
var base ClientBaseCase
16+
base.SetUp(t)
17+
defer base.TearDown(t)
18+
19+
base.MockGet("object-storage/quotas/obj-objects-us-ord-1", fixtureData)
20+
21+
quota, err := base.Client.GetObjectStorageQuota(context.Background(), "obj-objects-us-ord-1")
22+
if err != nil {
23+
t.Fatalf("Error getting object-storage quota: %v", err)
24+
}
25+
26+
assert.Equal(t, "obj-objects-us-ord-1", quota.QuotaID)
27+
assert.Equal(t, "Object Storage Maximum Objects", quota.QuotaName)
28+
assert.Equal(t, "Maximum number of Objects this customer is allowed to have on this endpoint.", quota.Description)
29+
assert.Equal(t, "E1", quota.EndpointType)
30+
assert.Equal(t, "us-iad-1.linodeobjects.com", quota.S3Endpoint)
31+
assert.Equal(t, 50, quota.QuotaLimit)
32+
assert.Equal(t, "object", quota.ResourceMetric)
33+
}
34+
35+
func TestObjectStorageQuotas_List(t *testing.T) {
36+
fixtureData, err := fixtures.GetFixture("object_storage_quotas_list")
37+
assert.NoError(t, err)
38+
39+
var base ClientBaseCase
40+
base.SetUp(t)
41+
defer base.TearDown(t)
42+
43+
base.MockGet("object-storage/quotas", fixtureData)
44+
45+
quotas, err := base.Client.ListObjectStorageQuotas(context.Background(), &linodego.ListOptions{})
46+
if err != nil {
47+
t.Fatalf("Error listing object-storage quotas: %v", err)
48+
}
49+
50+
if len(quotas) < 1 {
51+
t.Fatalf("Expected to get a list of object-storage quotas but failed.")
52+
}
53+
54+
assert.Equal(t, "obj-objects-us-ord-1", quotas[0].QuotaID)
55+
assert.Equal(t, "Object Storage Maximum Objects", quotas[0].QuotaName)
56+
assert.Equal(t, "Maximum number of Objects this customer is allowed to have on this endpoint.", quotas[0].Description)
57+
assert.Equal(t, "E1", quotas[0].EndpointType)
58+
assert.Equal(t, "us-iad-1.linodeobjects.com", quotas[0].S3Endpoint)
59+
assert.Equal(t, 50, quotas[0].QuotaLimit)
60+
assert.Equal(t, "object", quotas[0].ResourceMetric)
61+
}
62+
63+
func TestObjectStorageQuotaUsage_Get(t *testing.T) {
64+
fixtureData, err := fixtures.GetFixture("object_storage_quotas_usage_get")
65+
assert.NoError(t, err)
66+
67+
var base ClientBaseCase
68+
base.SetUp(t)
69+
defer base.TearDown(t)
70+
71+
base.MockGet("object-storage/quotas/obj-bucket-us-ord-1/usage", fixtureData)
72+
73+
quotaUsage, err := base.Client.GetObjectStorageQuotaUsage(context.Background(), "obj-bucket-us-ord-1")
74+
if err != nil {
75+
t.Fatalf("Error getting object storage quota usage: %v", err)
76+
}
77+
78+
assert.Equal(t, 100, quotaUsage.QuotaLimit)
79+
assert.Equal(t, 10, *quotaUsage.Usage)
80+
}

0 commit comments

Comments
 (0)