Skip to content

Commit

Permalink
Add v2 functions and structs
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai committed Jan 7, 2025
1 parent 57752c4 commit e7e09ae
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 51 deletions.
31 changes: 20 additions & 11 deletions object_storage_bucket_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import (
"context"
)

// Deprecated: Please use ObjectStorageBucketCertV2 for all new implementations.
type ObjectStorageBucketCert struct {
SSL bool `json:"ssl"`
}

type ObjectStorageBucketCertV2 struct {
SSL *bool `json:"ssl"`
}

Expand All @@ -14,25 +19,29 @@ type ObjectStorageBucketCertUploadOptions struct {
}

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

return response, nil
return doPOSTRequest[ObjectStorageBucketCert](ctx, c, e, opts)
}

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

// UploadObjectStorageBucketCert uploads a TLS/SSL Cert to be used with an Object Storage Bucket.
func (c *Client) UploadObjectStorageBucketCertV2(ctx context.Context, clusterOrRegionID, bucket string, opts ObjectStorageBucketCertUploadOptions) (*ObjectStorageBucketCertV2, error) {
e := formatAPIPath("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
return doPOSTRequest[ObjectStorageBucketCertV2](ctx, c, e, opts)
}

return response, nil
// GetObjectStorageBucketCert gets an ObjectStorageBucketCert
func (c *Client) GetObjectStorageBucketCertV2(ctx context.Context, clusterOrRegionID, bucket string) (*ObjectStorageBucketCertV2, error) {
e := formatAPIPath("object-storage/buckets/%s/%s/ssl", clusterOrRegionID, bucket)
return doGETRequest[ObjectStorageBucketCertV2](ctx, c, e)
}

// DeleteObjectStorageBucketCert deletes an ObjectStorageBucketCert
Expand Down
52 changes: 19 additions & 33 deletions object_storage_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ type ObjectStorageBucket struct {
// ObjectStorageBucketAccess holds Object Storage access info
type ObjectStorageBucketAccess struct {
ACL ObjectStorageACL `json:"acl"`
ACLXML string `json:"acl_xml"`
CorsEnabled bool `json:"cors_enabled"`
}

type ObjectStorageBucketAccessV2 struct {
ACL ObjectStorageACL `json:"acl"`
ACLXML string `json:"acl_xml"`
CorsEnabled *bool `json:"cors_enabled"`

Check failure on line 44 in object_storage_buckets.go

View workflow job for this annotation

GitHub Actions / lint-tidy

File is not properly formatted (gci)
CorsXML *string `json:"cors_xml"`
}

Expand Down Expand Up @@ -121,55 +126,31 @@ const (

// ListObjectStorageBuckets lists ObjectStorageBuckets
func (c *Client) ListObjectStorageBuckets(ctx context.Context, opts *ListOptions) ([]ObjectStorageBucket, error) {
response, err := getPaginatedResults[ObjectStorageBucket](ctx, c, "object-storage/buckets", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[ObjectStorageBucket](ctx, c, "object-storage/buckets", opts)
}

// ListObjectStorageBucketsInCluster lists all ObjectStorageBuckets of a cluster
func (c *Client) ListObjectStorageBucketsInCluster(ctx context.Context, opts *ListOptions, clusterOrRegionID string) ([]ObjectStorageBucket, error) {
response, err := getPaginatedResults[ObjectStorageBucket](ctx, c, formatAPIPath("object-storage/buckets/%s", clusterOrRegionID), opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[ObjectStorageBucket](ctx, c, formatAPIPath("object-storage/buckets/%s", clusterOrRegionID), opts)
}

// GetObjectStorageBucket gets the ObjectStorageBucket with the provided label
func (c *Client) GetObjectStorageBucket(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucket, error) {
e := formatAPIPath("object-storage/buckets/%s/%s", clusterOrRegionID, label)
response, err := doGETRequest[ObjectStorageBucket](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[ObjectStorageBucket](ctx, c, e)
}

// CreateObjectStorageBucket creates an ObjectStorageBucket
func (c *Client) CreateObjectStorageBucket(ctx context.Context, opts ObjectStorageBucketCreateOptions) (*ObjectStorageBucket, error) {
e := "object-storage/buckets"
response, err := doPOSTRequest[ObjectStorageBucket](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[ObjectStorageBucket](ctx, c, e, opts)
}

// GetObjectStorageBucketAccess gets the current access config for a bucket
// Deprecated: use GetObjectStorageBucketAccessV2 for new implementations
func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucketAccess, error) {
e := formatAPIPath("object-storage/buckets/%s/%s/access", clusterOrRegionID, label)
response, err := doGETRequest[ObjectStorageBucketAccess](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[ObjectStorageBucketAccess](ctx, c, e)
}

// UpdateObjectStorageBucketAccess updates the access configuration for an ObjectStorageBucket
Expand All @@ -180,11 +161,16 @@ func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterOrR
return err
}

// GetObjectStorageBucketAccess gets the current access config for a bucket
func (c *Client) GetObjectStorageBucketAccessV2(ctx context.Context, clusterOrRegionID, label string) (*ObjectStorageBucketAccessV2, error) {
e := formatAPIPath("object-storage/buckets/%s/%s/access", clusterOrRegionID, label)
return doGETRequest[ObjectStorageBucketAccessV2](ctx, c, e)
}

// DeleteObjectStorageBucket deletes the ObjectStorageBucket with the specified label
func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterOrRegionID, label string) error {
e := formatAPIPath("object-storage/buckets/%s/%s", clusterOrRegionID, label)
err := doDELETERequest(ctx, c, e)
return err
return doDELETERequest(ctx, c, e)
}

// Lists the contents of the specified ObjectStorageBucket
Expand Down
27 changes: 21 additions & 6 deletions object_storage_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,45 @@ type ObjectStorageObjectURL struct {
Exists bool `json:"exists"`
}

// Deprecated: Please use ObjectStorageObjectACLConfigV2 for all new implementations.
type ObjectStorageObjectACLConfig struct {
ACL string `json:"acl"`
ACLXML string `json:"acl_xml"`
}

type ObjectStorageObjectACLConfigV2 struct {
ACL *string `json:"acl"`
ACLXML *string `json:"acl_xml"`
}

type ObjectStorageObjectACLConfigUpdateOptions struct {
Name string `json:"name"`
ACL string `json:"acl"`
}

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

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

// Deprecated: use UpdateObjectStorageObjectACLConfigV2 for new implementations
func (c *Client) UpdateObjectStorageObjectACLConfig(ctx context.Context, objectID, label string, opts ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfig, error) {
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl", objectID, label)
response, err := doPUTRequest[ObjectStorageObjectACLConfig](ctx, c, e, opts)
return response, err
return doPUTRequest[ObjectStorageObjectACLConfig](ctx, c, e, opts)
}

func (c *Client) GetObjectStorageObjectACLConfigV2(ctx context.Context, objectID, label, object string) (*ObjectStorageObjectACLConfigV2, error) {
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl?name=%s", objectID, label, object)
return doGETRequest[ObjectStorageObjectACLConfigV2](ctx, c, e)
}

func (c *Client) UpdateObjectStorageObjectACLConfigV2(ctx context.Context, objectID, label string, opts ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfigV2, error) {
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl", objectID, label)
return doPUTRequest[ObjectStorageObjectACLConfigV2](ctx, c, e, opts)
}
2 changes: 1 addition & 1 deletion test/integration/object_storage_bucket_certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestObjectStorageBucketCert_smoke(t *testing.T) {
t.Fatalf("failed to get bucket cert: %s", err)
}

if cert.SSL != nil && !*cert.SSL {
if !cert.SSL {
t.Fatalf("expected cert.SSL to be true; got false")
}
}

0 comments on commit e7e09ae

Please sign in to comment.