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

Add support for OBJ gen2 #649

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

zliang-akamai
Copy link
Member

@zliang-akamai zliang-akamai commented Jan 6, 2025

📝 Description

This is to add support for the API changes came with the object storage service gen2.

✔️ How to Test

make fixtures ARGS="-run TestObjectStorage"

@zliang-akamai zliang-akamai marked this pull request as ready for review January 8, 2025 07:52
@zliang-akamai zliang-akamai requested review from a team as code owners January 8, 2025 07:52
return doGETRequest[ObjectStorageObjectACLConfigV2](ctx, c, e)
}

func (c *Client) UpdateObjectStorageObjectACLConfigV2(ctx context.Context, objectID, label string, opts ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfigV2, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth introducing a ObjectStorageObjectACLConfigUpdateOptionsV2 struct for consistency and future-proofing, although it might be a bit redundant 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the API schema will stay the same for this set of options? Gen2 doesn't currently support the object-level ACL.

Copy link
Contributor

@lgarber-akamai lgarber-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, excellent work!

Manually tested on my local machine using the following:

package main

import (
	"context"
	_ "embed"
	"log"
	"os"

	"github.com/davecgh/go-spew/spew"
	"github.com/linode/linodego"
)

var (
	//go:embed key.pem
	privateKey string

	//go:embed cert.pem
	certificate string
)

func main() {
	ctx := context.Background()

	client := linodego.NewClient(nil)
	client.SetToken(os.Getenv("LINODE_TOKEN"))
	client.SetAPIVersion("v4beta")

	endpoints, err := client.ListObjectStorageEndpoints(ctx, nil)
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(endpoints)

	bucket, err := client.CreateObjectStorageBucket(ctx, linodego.ObjectStorageBucketCreateOptions{
		Region:       endpoints[0].Region,
		Label:        "lgarber-dev-foobar",
		S3Endpoint:   *endpoints[0].S3Endpoint,
		EndpointType: endpoints[0].EndpointType,
		ACL:          linodego.ACLAuthenticatedRead,
	})
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(bucket)

	acl, err := client.GetObjectStorageBucketAccessV2(ctx, bucket.Region, bucket.Label)
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(acl)

	if err := client.UpdateObjectStorageBucketAccess(ctx, bucket.Region, bucket.Label, linodego.ObjectStorageBucketUpdateAccessOptions{
		ACL:         linodego.ACLPublicRead,
		CorsEnabled: linodego.Pointer(false),
	}); err != nil {
		log.Fatal(err)
	}

	acl, err = client.GetObjectStorageBucketAccessV2(ctx, bucket.Region, bucket.Label)
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(acl)

	cert, err := client.UploadObjectStorageBucketCertV2(ctx, bucket.Region, bucket.Label, linodego.ObjectStorageBucketCertUploadOptions{
		Certificate: certificate,
		PrivateKey:  privateKey,
	})
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(cert)

	cert, err = client.GetObjectStorageBucketCertV2(ctx, bucket.Region, bucket.Label)
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(cert)

	key, err := client.CreateObjectStorageKey(ctx, linodego.ObjectStorageKeyCreateOptions{
		Label: "lgarber-dev-key",
		BucketAccess: &[]linodego.ObjectStorageKeyBucketAccess{
			{
				Region:      endpoints[0].Region,
				BucketName:  bucket.Label,
				Permissions: "read_write",
			},
		},
		Regions: []string{endpoints[0].Region},
	})
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(key)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants