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 object storage services gen2 #649

Merged
merged 11 commits into from
Jan 15, 2025

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 force-pushed the zhiwei/obj-gen2 branch 2 times, most recently from e7e09ae to cf499ea Compare January 7, 2025 20:19
@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)
}

@zliang-akamai zliang-akamai requested review from a team, jriddle-linode and yec-akamai and removed request for a team January 10, 2025 19:53
Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

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

Tested and works well on my end!

@zliang-akamai zliang-akamai force-pushed the zhiwei/obj-gen2 branch 2 times, most recently from 40ee3ba to 7677de7 Compare January 14, 2025 20:03
@zliang-akamai zliang-akamai changed the title Add support for OBJ gen2 Add support for object storage services gen2 Jan 15, 2025
@zliang-akamai zliang-akamai merged commit 9193012 into linode:main Jan 15, 2025
10 checks passed
@zliang-akamai zliang-akamai deleted the zhiwei/obj-gen2 branch January 15, 2025 05:08
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.

3 participants