Skip to content

Commit 4243c0e

Browse files
project: MultiCluster Object Storage (#522)
* Add MultiCluster API changes support for key and bucket structs (#516) * Deprecate OBJ Clusters List and View Functions (#517) * Mark ListObjectStorageClusters and GetObjectStorageCluster as deprecated * format code * Update deprecated warning wording Co-authored-by: Lena Garber <[email protected]> * Update deprecated warning wording Co-authored-by: Lena Garber <[email protected]> --------- Co-authored-by: Lena Garber <[email protected]> * Deprecated OBJ Cluster Fields (#524) * Fix typo --------- Co-authored-by: Lena Garber <[email protected]>
1 parent 2a5ae92 commit 4243c0e

10 files changed

+918
-54
lines changed

client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestDebugLogSanitization(t *testing.T) {
153153
Label string `json:"label"`
154154
}
155155

156-
var testResp = instanceResponse{
156+
testResp := instanceResponse{
157157
ID: 100,
158158
Region: "test-central",
159159
Label: "this-is-a-test-linode",

object_storage_bucket_certs.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ type ObjectStorageBucketCertUploadOptions struct {
1717
}
1818

1919
// UploadObjectStorageBucketCert uploads a TLS/SSL Cert to be used with an Object Storage Bucket.
20-
func (c *Client) UploadObjectStorageBucketCert(ctx context.Context, clusterID, bucket string, opts ObjectStorageBucketCertUploadOptions) (*ObjectStorageBucketCert, error) {
20+
func (c *Client) UploadObjectStorageBucketCert(ctx context.Context, clusterOrRegionID, bucket string, opts ObjectStorageBucketCertUploadOptions) (*ObjectStorageBucketCert, error) {
2121
body, err := json.Marshal(opts)
2222
if err != nil {
2323
return nil, err
2424
}
2525

26-
clusterID = url.PathEscape(clusterID)
26+
clusterOrRegionID = url.PathEscape(clusterOrRegionID)
2727
bucket = url.PathEscape(bucket)
28-
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterID, bucket)
28+
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
2929
req := c.R(ctx).SetResult(&ObjectStorageBucketCert{}).SetBody(string(body))
3030
r, err := coupleAPIErrors(req.Post(e))
3131
if err != nil {
@@ -35,10 +35,10 @@ func (c *Client) UploadObjectStorageBucketCert(ctx context.Context, clusterID, b
3535
}
3636

3737
// GetObjectStorageBucketCert gets an ObjectStorageBucketCert
38-
func (c *Client) GetObjectStorageBucketCert(ctx context.Context, clusterID, bucket string) (*ObjectStorageBucketCert, error) {
39-
clusterID = url.PathEscape(clusterID)
38+
func (c *Client) GetObjectStorageBucketCert(ctx context.Context, clusterOrRegionID, bucket string) (*ObjectStorageBucketCert, error) {
39+
clusterOrRegionID = url.PathEscape(clusterOrRegionID)
4040
bucket = url.PathEscape(bucket)
41-
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterID, bucket)
41+
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
4242
req := c.R(ctx).SetResult(&ObjectStorageBucketCert{})
4343
r, err := coupleAPIErrors(req.Get(e))
4444
if err != nil {
@@ -48,10 +48,10 @@ func (c *Client) GetObjectStorageBucketCert(ctx context.Context, clusterID, buck
4848
}
4949

5050
// DeleteObjectStorageBucketCert deletes an ObjectStorageBucketCert
51-
func (c *Client) DeleteObjectStorageBucketCert(ctx context.Context, clusterID, bucket string) error {
52-
clusterID = url.PathEscape(clusterID)
51+
func (c *Client) DeleteObjectStorageBucketCert(ctx context.Context, clusterOrRegionID, bucket string) error {
52+
clusterOrRegionID = url.PathEscape(clusterOrRegionID)
5353
bucket = url.PathEscape(bucket)
54-
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterID, bucket)
54+
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
5555
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
5656
return err
5757
}

object_storage_buckets.go

+32-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@ import (
1313

1414
// ObjectStorageBucket represents a ObjectStorage object
1515
type ObjectStorageBucket struct {
16-
Label string `json:"label"`
16+
Label string `json:"label"`
17+
18+
// Deprecated: The 'Cluster' field has been deprecated in favor of the 'Region' field.
19+
// For example, a Cluster value of `us-mia-1` will translate to a Region value of `us-mia`.
20+
//
21+
// This is necessary because there are now multiple Object Storage clusters to a region.
22+
//
23+
// NOTE: The 'Cluster' field will always return a value similar to `<REGION>-1` (e.g., `us-mia-1`)
24+
// for backward compatibility purposes.
1725
Cluster string `json:"cluster"`
26+
Region string `json:"region"`
1827

1928
Created *time.Time `json:"-"`
2029
Hostname string `json:"hostname"`
@@ -50,8 +59,15 @@ func (i *ObjectStorageBucket) UnmarshalJSON(b []byte) error {
5059

5160
// ObjectStorageBucketCreateOptions fields are those accepted by CreateObjectStorageBucket
5261
type ObjectStorageBucketCreateOptions struct {
53-
Cluster string `json:"cluster"`
54-
Label string `json:"label"`
62+
// Deprecated: The 'Cluster' field has been deprecated.
63+
//
64+
// Going forward, the 'Region' field will be the supported way to designate where an
65+
// Object Storage Bucket should be created. For example, a 'Cluster' value of `us-mia-1`
66+
// will translate to a Region value of `us-mia`.
67+
Cluster string `json:"cluster,omitempty"`
68+
Region string `json:"region,omitempty"`
69+
70+
Label string `json:"label"`
5571

5672
ACL ObjectStorageACL `json:"acl,omitempty"`
5773
CorsEnabled *bool `json:"cors_enabled,omitempty"`
@@ -110,20 +126,20 @@ func (c *Client) ListObjectStorageBuckets(ctx context.Context, opts *ListOptions
110126
}
111127

112128
// ListObjectStorageBucketsInCluster lists all ObjectStorageBuckets of a cluster
113-
func (c *Client) ListObjectStorageBucketsInCluster(ctx context.Context, opts *ListOptions, clusterID string) ([]ObjectStorageBucket, error) {
129+
func (c *Client) ListObjectStorageBucketsInCluster(ctx context.Context, opts *ListOptions, clusterOrRegionID string) ([]ObjectStorageBucket, error) {
114130
response := ObjectStorageBucketsPagedResponse{}
115-
err := c.listHelper(ctx, &response, opts, clusterID)
131+
err := c.listHelper(ctx, &response, opts, clusterOrRegionID)
116132
if err != nil {
117133
return nil, err
118134
}
119135
return response.Data, nil
120136
}
121137

122138
// GetObjectStorageBucket gets the ObjectStorageBucket with the provided label
123-
func (c *Client) GetObjectStorageBucket(ctx context.Context, clusterID, label string) (*ObjectStorageBucket, error) {
139+
func (c *Client) GetObjectStorageBucket(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucket, error) {
124140
label = url.PathEscape(label)
125-
clusterID = url.PathEscape(clusterID)
126-
e := fmt.Sprintf("object-storage/buckets/%s/%s", clusterID, label)
141+
clusterOrRegionID = url.PathEscape(clusterOrRegionID)
142+
e := fmt.Sprintf("object-storage/buckets/%s/%s", clusterOrRegionID, label)
127143
req := c.R(ctx).SetResult(&ObjectStorageBucket{})
128144
r, err := coupleAPIErrors(req.Get(e))
129145
if err != nil {
@@ -149,10 +165,10 @@ func (c *Client) CreateObjectStorageBucket(ctx context.Context, opts ObjectStora
149165
}
150166

151167
// GetObjectStorageBucketAccess gets the current access config for a bucket
152-
func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterID, label string) (*ObjectStorageBucketAccess, error) {
168+
func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucketAccess, error) {
153169
label = url.PathEscape(label)
154-
clusterID = url.PathEscape(clusterID)
155-
e := fmt.Sprintf("object-storage/buckets/%s/%s/access", clusterID, label)
170+
clusterOrRegionID = url.PathEscape(clusterOrRegionID)
171+
e := fmt.Sprintf("object-storage/buckets/%s/%s/access", clusterOrRegionID, label)
156172
req := c.R(ctx).SetResult(&ObjectStorageBucketAccess{})
157173
r, err := coupleAPIErrors(req.Get(e))
158174
if err != nil {
@@ -163,15 +179,15 @@ func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterID, la
163179
}
164180

165181
// UpdateObjectStorageBucketAccess updates the access configuration for an ObjectStorageBucket
166-
func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterID, label string, opts ObjectStorageBucketUpdateAccessOptions) error {
182+
func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterOrRegionID, label string, opts ObjectStorageBucketUpdateAccessOptions) error {
167183
body, err := json.Marshal(opts)
168184
if err != nil {
169185
return err
170186
}
171187

172188
label = url.PathEscape(label)
173-
clusterID = url.PathEscape(clusterID)
174-
e := fmt.Sprintf("object-storage/buckets/%s/%s/access", clusterID, label)
189+
clusterOrRegionID = url.PathEscape(clusterOrRegionID)
190+
e := fmt.Sprintf("object-storage/buckets/%s/%s/access", clusterOrRegionID, label)
175191
_, err = coupleAPIErrors(c.R(ctx).SetBody(string(body)).Post(e))
176192
if err != nil {
177193
return err
@@ -181,9 +197,9 @@ func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterID,
181197
}
182198

183199
// DeleteObjectStorageBucket deletes the ObjectStorageBucket with the specified label
184-
func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterID, label string) error {
200+
func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterOrRegionID, label string) error {
185201
label = url.PathEscape(label)
186-
e := fmt.Sprintf("object-storage/buckets/%s/%s", clusterID, label)
202+
e := fmt.Sprintf("object-storage/buckets/%s/%s", clusterOrRegionID, label)
187203
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
188204
return err
189205
}

object_storage_clusters.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (resp *ObjectStorageClustersPagedResponse) castResult(r *resty.Request, e s
3838
return castedRes.Pages, castedRes.Results, nil
3939
}
4040

41+
// Deprecated: ListObjectStorageClusters uses a deprecated API endpoint.
4142
// ListObjectStorageClusters lists ObjectStorageClusters
4243
func (c *Client) ListObjectStorageClusters(ctx context.Context, opts *ListOptions) ([]ObjectStorageCluster, error) {
4344
response := ObjectStorageClustersPagedResponse{}
@@ -48,6 +49,7 @@ func (c *Client) ListObjectStorageClusters(ctx context.Context, opts *ListOption
4849
return response.Data, nil
4950
}
5051

52+
// Deprecated: GetObjectStorageCluster uses a deprecated API endpoint.
5153
// GetObjectStorageCluster gets the template with the provided ID
5254
func (c *Client) GetObjectStorageCluster(ctx context.Context, clusterID string) (*ObjectStorageCluster, error) {
5355
clusterID = url.PathEscape(clusterID)

object_storage_keys.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88
"github.com/go-resty/resty/v2"
99
)
1010

11+
type ObjectStorageKeyRegion struct {
12+
ID string `json:"id"`
13+
S3Endpoint string `json:"s3_endpoint"`
14+
}
15+
1116
// ObjectStorageKey represents a linode object storage key object
1217
type ObjectStorageKey struct {
1318
ID int `json:"id"`
@@ -16,24 +21,32 @@ type ObjectStorageKey struct {
1621
SecretKey string `json:"secret_key"`
1722
Limited bool `json:"limited"`
1823
BucketAccess *[]ObjectStorageKeyBucketAccess `json:"bucket_access"`
24+
Regions []ObjectStorageKeyRegion `json:"regions"`
1925
}
2026

2127
// ObjectStorageKeyBucketAccess represents a linode limited object storage key's bucket access
2228
type ObjectStorageKeyBucketAccess struct {
23-
Cluster string `json:"cluster"`
29+
// Deprecated: Cluster field has been deprecated.
30+
// Please consider switching to use the 'Region' field.
31+
// If your Cluster is `us-mia-1`, then the region would be `us-mia`.
32+
Cluster string `json:"cluster,omitempty"`
33+
Region string `json:"region,omitempty"`
34+
2435
BucketName string `json:"bucket_name"`
2536
Permissions string `json:"permissions"`
2637
}
2738

2839
// ObjectStorageKeyCreateOptions fields are those accepted by CreateObjectStorageKey
2940
type ObjectStorageKeyCreateOptions struct {
3041
Label string `json:"label"`
31-
BucketAccess *[]ObjectStorageKeyBucketAccess `json:"bucket_access"`
42+
BucketAccess *[]ObjectStorageKeyBucketAccess `json:"bucket_access,omitempty"`
43+
Regions []string `json:"regions,omitempty"`
3244
}
3345

3446
// ObjectStorageKeyUpdateOptions fields are those accepted by UpdateObjectStorageKey
3547
type ObjectStorageKeyUpdateOptions struct {
36-
Label string `json:"label"`
48+
Label string `json:"label,omitempty"`
49+
Regions []string `json:"regions,omitempty"`
3750
}
3851

3952
// ObjectStorageKeysPagedResponse represents a linode API response for listing

0 commit comments

Comments
 (0)