Skip to main content

Creating and Managing Buckets

Buckets in Rig are references to buckets in the connected backends. To this end, Rig-buckets have both a unique name for Rig, and a provider name used when interacting with the backends. They also contain the region in which the bucket is created.


Creating Buckets

Creating buckets is done using the CreateBucket endpoint. The endpoint takes as input a name for the bucket, a provider name, and a region. The name is unique in Rig, and the provider name is the name of the bucket in the backend. The region is the region in which the bucket is created. A list of available regions can be found in the AWS documentation for S3, and the Google Cloud documentation for GCS. In the case of a self-hosted Minio Server, the region does not make much sense and can be left blank. If a bucket with the given provider name already exists in the backend, the bucket will be linked to Rig. If not, it will be created.

// Create a bucket in eu-central-1
providerID := "" // NOTE: insert providerID here
resp, err := client.Storage().CreateBucket(ctx, connect.NewRequest(&storage.CreateBucketRequest{
Bucket: "my-bucket",
ProviderBucket: "my-bucket",
Region: "eu-central-1",
ProviderId: providerID,
}))
if err != nil {
log.Fatal(err)
}
log.Printf("successfully created bucket")

Deleting Buckets

As buckets in Rig are references to Buckets for the given providers, it is possible to either delete the buckets in the backend or simply unlink them to Rig. To delete a bucket, the endpoint DeleteBucket can be used and to unlink the bucket, the UnlinkBucketendpoint can be used. Both endpoints take the Rig bucket name as input.

// Delete a bucket
resp, err := client.Storage().DeleteBucket(ctx, connect.NewRequest(&storage.DeleteBucketRequest{
Bucket: "my-bucket",
}))
if err != nil {
log.Fatal(err)
}
log.Printf("successfully deleted bucket \n")

// Unlink a bucket
resp, err := client.Storage().UnlinkBucket(ctx, connect.NewRequest(&storage.UnlinkBucketRequest{
Bucket: "my-bucket",
}))
if err != nil {
log.Fatal(err)
}
log.Printf("successfully unlinked bucket \n")

Fetching Buckets

Getting a Bucket

To fetch a bucket, the GetBucket endpoint can be used. The endpoint takes the Rig bucket name as input and returns the bucket object.

// Get a bucket
resp, err := client.Storage().GetBucket(ctx, connect.NewRequest(&storage.GetBucketRequest{
Bucket: "my-bucket",
}))
if err != nil {
log.Fatal(err)
}
log.Println("Succesfully retrieved bucket %s", resp.Msg.GetBucket().GetName())

Listing Buckets

Listing buckets using the SDK can be done using the ListBuckets endpoint. This will return all Rig-buckets across the providers. The endpoint takes no input and returns a list of buckets. In the CLI, this functionality is combined with listing of objects and is done using the list command. When no path is given, the command will list all buckets, and when a path is given, it will list all objects in the given path. Refer to the objects documentation for more information on listing objects.

resp, err := client.Storage().ListBuckets(ctx, connect.NewRequest(&storage.ListBucketsRequest{}))
if err != nil {
log.Fatal(err)
}
log.Printf("successfully fetched %d buckets \n", len(resp.Msg.GetBuckets()))

Was this page helpful?