Skip to content

Commit 9193012

Browse files
Add support for object storage services gen2 (linode#649)
1 parent 7b7ba1d commit 9193012

30 files changed

+1954
-918
lines changed

object_storage_bucket_certs.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,44 @@ import (
44
"context"
55
)
66

7+
// Deprecated: Please use ObjectStorageBucketCertV2 for all new implementations.
78
type ObjectStorageBucketCert struct {
89
SSL bool `json:"ssl"`
910
}
1011

12+
type ObjectStorageBucketCertV2 struct {
13+
SSL *bool `json:"ssl"`
14+
}
15+
1116
type ObjectStorageBucketCertUploadOptions struct {
1217
Certificate string `json:"certificate"`
1318
PrivateKey string `json:"private_key"`
1419
}
1520

1621
// UploadObjectStorageBucketCert uploads a TLS/SSL Cert to be used with an Object Storage Bucket.
22+
// Deprecated: Please use UploadObjectStorageBucketCertV2 for all new implementations.
1723
func (c *Client) UploadObjectStorageBucketCert(ctx context.Context, clusterOrRegionID, bucket string, opts ObjectStorageBucketCertUploadOptions) (*ObjectStorageBucketCert, error) {
1824
e := formatAPIPath("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
19-
response, err := doPOSTRequest[ObjectStorageBucketCert](ctx, c, e, opts)
20-
if err != nil {
21-
return nil, err
22-
}
23-
24-
return response, nil
25+
return doPOSTRequest[ObjectStorageBucketCert](ctx, c, e, opts)
2526
}
2627

2728
// GetObjectStorageBucketCert gets an ObjectStorageBucketCert
29+
// Deprecated: Please use GetObjectStorageBucketCertV2 for all new implementations.
2830
func (c *Client) GetObjectStorageBucketCert(ctx context.Context, clusterOrRegionID, bucket string) (*ObjectStorageBucketCert, error) {
2931
e := formatAPIPath("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
30-
response, err := doGETRequest[ObjectStorageBucketCert](ctx, c, e)
31-
if err != nil {
32-
return nil, err
33-
}
32+
return doGETRequest[ObjectStorageBucketCert](ctx, c, e)
33+
}
3434

35-
return response, nil
35+
// UploadObjectStorageBucketCert uploads a TLS/SSL Cert to be used with an Object Storage Bucket.
36+
func (c *Client) UploadObjectStorageBucketCertV2(ctx context.Context, clusterOrRegionID, bucket string, opts ObjectStorageBucketCertUploadOptions) (*ObjectStorageBucketCertV2, error) {
37+
e := formatAPIPath("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
38+
return doPOSTRequest[ObjectStorageBucketCertV2](ctx, c, e, opts)
39+
}
40+
41+
// GetObjectStorageBucketCertV2 gets an ObjectStorageBucketCert
42+
func (c *Client) GetObjectStorageBucketCertV2(ctx context.Context, clusterOrRegionID, bucket string) (*ObjectStorageBucketCertV2, error) {
43+
e := formatAPIPath("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
44+
return doGETRequest[ObjectStorageBucketCertV2](ctx, c, e)
3645
}
3746

3847
// DeleteObjectStorageBucketCert deletes an ObjectStorageBucketCert

object_storage_buckets.go

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ type ObjectStorageBucket struct {
2424
Cluster string `json:"cluster"`
2525
Region string `json:"region"`
2626

27-
Created *time.Time `json:"-"`
28-
Hostname string `json:"hostname"`
29-
Objects int `json:"objects"`
30-
Size int `json:"size"`
27+
S3Endpoint string `json:"s3_endpoint"`
28+
EndpointType ObjectStorageEndpointType `json:"endpoint_type"`
29+
Created *time.Time `json:"-"`
30+
Hostname string `json:"hostname"`
31+
Objects int `json:"objects"`
32+
Size int `json:"size"`
3133
}
3234

3335
// ObjectStorageBucketAccess holds Object Storage access info
@@ -36,6 +38,13 @@ type ObjectStorageBucketAccess struct {
3638
CorsEnabled bool `json:"cors_enabled"`
3739
}
3840

41+
type ObjectStorageBucketAccessV2 struct {
42+
ACL ObjectStorageACL `json:"acl"`
43+
ACLXML string `json:"acl_xml"`
44+
CorsEnabled *bool `json:"cors_enabled"`
45+
CorsXML *string `json:"cors_xml"`
46+
}
47+
3948
// ObjectStorageBucketContent holds the content of an ObjectStorageBucket
4049
type ObjectStorageBucketContent struct {
4150
Data []ObjectStorageBucketContentData `json:"data"`
@@ -82,7 +91,9 @@ type ObjectStorageBucketCreateOptions struct {
8291
Cluster string `json:"cluster,omitempty"`
8392
Region string `json:"region,omitempty"`
8493

85-
Label string `json:"label"`
94+
Label string `json:"label"`
95+
S3Endpoint string `json:"s3_endpoint,omitempty"`
96+
EndpointType ObjectStorageEndpointType `json:"endpoint_type,omitempty"`
8697

8798
ACL ObjectStorageACL `json:"acl,omitempty"`
8899
CorsEnabled *bool `json:"cors_enabled,omitempty"`
@@ -115,55 +126,31 @@ const (
115126

116127
// ListObjectStorageBuckets lists ObjectStorageBuckets
117128
func (c *Client) ListObjectStorageBuckets(ctx context.Context, opts *ListOptions) ([]ObjectStorageBucket, error) {
118-
response, err := getPaginatedResults[ObjectStorageBucket](ctx, c, "object-storage/buckets", opts)
119-
if err != nil {
120-
return nil, err
121-
}
122-
123-
return response, nil
129+
return getPaginatedResults[ObjectStorageBucket](ctx, c, "object-storage/buckets", opts)
124130
}
125131

126132
// ListObjectStorageBucketsInCluster lists all ObjectStorageBuckets of a cluster
127133
func (c *Client) ListObjectStorageBucketsInCluster(ctx context.Context, opts *ListOptions, clusterOrRegionID string) ([]ObjectStorageBucket, error) {
128-
response, err := getPaginatedResults[ObjectStorageBucket](ctx, c, formatAPIPath("object-storage/buckets/%s", clusterOrRegionID), opts)
129-
if err != nil {
130-
return nil, err
131-
}
132-
133-
return response, nil
134+
return getPaginatedResults[ObjectStorageBucket](ctx, c, formatAPIPath("object-storage/buckets/%s", clusterOrRegionID), opts)
134135
}
135136

136137
// GetObjectStorageBucket gets the ObjectStorageBucket with the provided label
137138
func (c *Client) GetObjectStorageBucket(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucket, error) {
138139
e := formatAPIPath("object-storage/buckets/%s/%s", clusterOrRegionID, label)
139-
response, err := doGETRequest[ObjectStorageBucket](ctx, c, e)
140-
if err != nil {
141-
return nil, err
142-
}
143-
144-
return response, nil
140+
return doGETRequest[ObjectStorageBucket](ctx, c, e)
145141
}
146142

147143
// CreateObjectStorageBucket creates an ObjectStorageBucket
148144
func (c *Client) CreateObjectStorageBucket(ctx context.Context, opts ObjectStorageBucketCreateOptions) (*ObjectStorageBucket, error) {
149145
e := "object-storage/buckets"
150-
response, err := doPOSTRequest[ObjectStorageBucket](ctx, c, e, opts)
151-
if err != nil {
152-
return nil, err
153-
}
154-
155-
return response, nil
146+
return doPOSTRequest[ObjectStorageBucket](ctx, c, e, opts)
156147
}
157148

158149
// GetObjectStorageBucketAccess gets the current access config for a bucket
150+
// Deprecated: use GetObjectStorageBucketAccessV2 for new implementations
159151
func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucketAccess, error) {
160152
e := formatAPIPath("object-storage/buckets/%s/%s/access", clusterOrRegionID, label)
161-
response, err := doGETRequest[ObjectStorageBucketAccess](ctx, c, e)
162-
if err != nil {
163-
return nil, err
164-
}
165-
166-
return response, nil
153+
return doGETRequest[ObjectStorageBucketAccess](ctx, c, e)
167154
}
168155

169156
// UpdateObjectStorageBucketAccess updates the access configuration for an ObjectStorageBucket
@@ -174,11 +161,16 @@ func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterOrR
174161
return err
175162
}
176163

164+
// GetObjectStorageBucketAccess gets the current access config for a bucket
165+
func (c *Client) GetObjectStorageBucketAccessV2(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucketAccessV2, error) {
166+
e := formatAPIPath("object-storage/buckets/%s/%s/access", clusterOrRegionID, label)
167+
return doGETRequest[ObjectStorageBucketAccessV2](ctx, c, e)
168+
}
169+
177170
// DeleteObjectStorageBucket deletes the ObjectStorageBucket with the specified label
178171
func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterOrRegionID, label string) error {
179172
e := formatAPIPath("object-storage/buckets/%s/%s", clusterOrRegionID, label)
180-
err := doDELETERequest(ctx, c, e)
181-
return err
173+
return doDELETERequest(ctx, c, e)
182174
}
183175

184176
// Lists the contents of the specified ObjectStorageBucket

object_storage_endpoints.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package linodego
2+
3+
import "context"
4+
5+
// NotificationType constants start with Notification and include all known Linode API Notification Types.
6+
type ObjectStorageEndpointType string
7+
8+
// NotificationType constants represent the actions that cause a Notification. New types may be added in the future.
9+
const (
10+
ObjectStorageEndpointE0 ObjectStorageEndpointType = "E0"
11+
ObjectStorageEndpointE1 ObjectStorageEndpointType = "E1"
12+
ObjectStorageEndpointE2 ObjectStorageEndpointType = "E2"
13+
ObjectStorageEndpointE3 ObjectStorageEndpointType = "E3"
14+
)
15+
16+
// ObjectStorageEndpoint represents a linode object storage endpoint object
17+
type ObjectStorageEndpoint struct {
18+
Region string `json:"region"`
19+
S3Endpoint *string `json:"s3_endpoint"`
20+
EndpointType ObjectStorageEndpointType `json:"endpoint_type"`
21+
}
22+
23+
// ListObjectStorageEndpoints lists all endpoints in all regions
24+
func (c *Client) ListObjectStorageEndpoints(ctx context.Context, opts *ListOptions) ([]ObjectStorageEndpoint, error) {
25+
return getPaginatedResults[ObjectStorageEndpoint](ctx, c, "object-storage/endpoints", opts)
26+
}

object_storage_keys.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import (
55
)
66

77
type ObjectStorageKeyRegion struct {
8-
ID string `json:"id"`
9-
S3Endpoint string `json:"s3_endpoint"`
8+
ID string `json:"id"`
9+
S3Endpoint string `json:"s3_endpoint"`
10+
EndpointType ObjectStorageEndpointType `json:"endpoint_type"`
1011
}
1112

1213
// ObjectStorageKey represents a linode object storage key object

object_storage_object.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,45 @@ type ObjectStorageObjectURL struct {
1717
Exists bool `json:"exists"`
1818
}
1919

20+
// Deprecated: Please use ObjectStorageObjectACLConfigV2 for all new implementations.
2021
type ObjectStorageObjectACLConfig struct {
2122
ACL string `json:"acl"`
2223
ACLXML string `json:"acl_xml"`
2324
}
2425

26+
type ObjectStorageObjectACLConfigV2 struct {
27+
ACL *string `json:"acl"`
28+
ACLXML *string `json:"acl_xml"`
29+
}
30+
2531
type ObjectStorageObjectACLConfigUpdateOptions struct {
2632
Name string `json:"name"`
2733
ACL string `json:"acl"`
2834
}
2935

3036
func (c *Client) CreateObjectStorageObjectURL(ctx context.Context, objectID, label string, opts ObjectStorageObjectURLCreateOptions) (*ObjectStorageObjectURL, error) {
3137
e := formatAPIPath("object-storage/buckets/%s/%s/object-url", objectID, label)
32-
response, err := doPOSTRequest[ObjectStorageObjectURL](ctx, c, e, opts)
33-
return response, err
38+
return doPOSTRequest[ObjectStorageObjectURL](ctx, c, e, opts)
3439
}
3540

41+
// Deprecated: use GetObjectStorageObjectACLConfigV2 for new implementations
3642
func (c *Client) GetObjectStorageObjectACLConfig(ctx context.Context, objectID, label, object string) (*ObjectStorageObjectACLConfig, error) {
3743
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl?name=%s", objectID, label, object)
38-
response, err := doGETRequest[ObjectStorageObjectACLConfig](ctx, c, e)
39-
return response, err
44+
return doGETRequest[ObjectStorageObjectACLConfig](ctx, c, e)
4045
}
4146

47+
// Deprecated: use UpdateObjectStorageObjectACLConfigV2 for new implementations
4248
func (c *Client) UpdateObjectStorageObjectACLConfig(ctx context.Context, objectID, label string, opts ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfig, error) {
4349
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl", objectID, label)
44-
response, err := doPUTRequest[ObjectStorageObjectACLConfig](ctx, c, e, opts)
45-
return response, err
50+
return doPUTRequest[ObjectStorageObjectACLConfig](ctx, c, e, opts)
51+
}
52+
53+
func (c *Client) GetObjectStorageObjectACLConfigV2(ctx context.Context, objectID, label, object string) (*ObjectStorageObjectACLConfigV2, error) {
54+
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl?name=%s", objectID, label, object)
55+
return doGETRequest[ObjectStorageObjectACLConfigV2](ctx, c, e)
56+
}
57+
58+
func (c *Client) UpdateObjectStorageObjectACLConfigV2(ctx context.Context, objectID, label string, opts ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfigV2, error) {
59+
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl", objectID, label)
60+
return doPUTRequest[ObjectStorageObjectACLConfigV2](ctx, c, e, opts)
4661
}

regions.go

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,39 @@ import (
1010
// Defined as strings rather than a custom type to avoid breaking change.
1111
// Can be changed in the potential v2 version.
1212
const (
13-
CapabilityLinodes string = "Linodes"
14-
CapabilityNodeBalancers string = "NodeBalancers"
15-
CapabilityBlockStorage string = "Block Storage"
16-
CapabilityObjectStorage string = "Object Storage"
17-
CapabilityObjectStorageRegions string = "Object Storage Access Key Regions"
18-
CapabilityLKE string = "Kubernetes"
19-
CapabilityLkeHaControlPlanes string = "LKE HA Control Planes"
20-
CapabilityCloudFirewall string = "Cloud Firewall"
21-
CapabilityGPU string = "GPU Linodes"
22-
CapabilityVlans string = "Vlans"
23-
CapabilityVPCs string = "VPCs"
24-
CapabilityVPCsExtra string = "VPCs Extra"
25-
CapabilityQuadraT1UVPU string = "NETINT Quadra T1U"
26-
CapabilityMachineImages string = "Machine Images"
27-
CapabilityBareMetal string = "Bare Metal"
28-
CapabilityDBAAS string = "Managed Databases"
29-
CapabilityBlockStorageMigrations string = "Block Storage Migrations"
30-
CapabilityMetadata string = "Metadata"
31-
CapabilityPremiumPlans string = "Premium Plans"
32-
CapabilityEdgePlans string = "Edge Plans"
33-
CapabilityLKEControlPlaneACL string = "LKE Network Access Control List (IP ACL)"
34-
CapabilityACLB string = "Akamai Cloud Load Balancer"
35-
CapabilitySupportTicketSeverity string = "Support Ticket Severity"
36-
CapabilityBackups string = "Backups"
37-
CapabilityPlacementGroup string = "Placement Group"
38-
CapabilityDiskEncryption string = "Disk Encryption"
39-
CapabilityBlockStorageEncryption string = "Block Storage Encryption"
40-
CapabilityKubernetesEnterprise string = "Kubernetes Enterprise"
13+
CapabilityACLB string = "Akamai Cloud Load Balancer"
14+
CapabilityBackups string = "Backups"
15+
CapabilityBareMetal string = "Bare Metal"
16+
CapabilityBlockStorage string = "Block Storage"
17+
CapabilityBlockStorageEncryption string = "Block Storage Encryption"
18+
CapabilityBlockStorageMigrations string = "Block Storage Migrations"
19+
CapabilityCloudFirewall string = "Cloud Firewall"
20+
CapabilityDBAAS string = "Managed Databases"
21+
CapabilityDiskEncryption string = "Disk Encryption"
22+
CapabilityEdgePlans string = "Edge Plans"
23+
CapabilityGPU string = "GPU Linodes"
24+
CapabilityKubernetesEnterprise string = "Kubernetes Enterprise"
25+
CapabilityLKE string = "Kubernetes"
26+
CapabilityLKEControlPlaneACL string = "LKE Network Access Control List (IP ACL)"
27+
CapabilityLinodes string = "Linodes"
28+
CapabilityLkeHaControlPlanes string = "LKE HA Control Planes"
29+
CapabilityMachineImages string = "Machine Images"
30+
CapabilityMetadata string = "Metadata"
31+
CapabilityNodeBalancers string = "NodeBalancers"
32+
CapabilityObjectStorage string = "Object Storage"
33+
CapabilityObjectStorageAccessKeyRegions string = "Object Storage Access Key Regions"
34+
CapabilityObjectStorageEndpointTypes string = "Object Storage Endpoint Types"
35+
CapabilityPlacementGroup string = "Placement Group"
36+
CapabilityPremiumPlans string = "Premium Plans"
37+
CapabilityQuadraT1UVPU string = "NETINT Quadra T1U"
38+
CapabilitySupportTicketSeverity string = "Support Ticket Severity"
39+
CapabilityVPCs string = "VPCs"
40+
CapabilityVPCsExtra string = "VPCs Extra"
41+
CapabilityVlans string = "Vlans"
42+
43+
// Deprecated: CapabilityObjectStorageRegions constant has been
44+
// renamed to `CapabilityObjectStorageAccessKeyRegions`.
45+
CapabilityObjectStorageRegions string = CapabilityObjectStorageAccessKeyRegions
4146
)
4247

4348
// Region-related endpoints have a custom expiry time as the

0 commit comments

Comments
 (0)