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.
- Golang SDK
- Typescript SDK
- CLI
// 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")
// Create a bucket in eu-central-1
const providerID = ""; // NOTE: insert providerID here
const resp = await client.storagesClient.createBucket({
bucket: "my-bucket",
providerBucket: "my-bucket",
region: "eu-central-1",
ProviderId: providerID,
});
console.log("successfully created bucket \n");
rig storage create-bucket [provider-name] --name --provider-bucket-name --region
Example:
rig storage create-bucket my-provider -n fruits -p rig_fruits -r eu-central-1
Fields of the bucket are prompted for.
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 UnlinkBucket
endpoint can be used. Both endpoints take the Rig bucket name as input.
- Golang SDK
- Typescript SDK
- CLI
// 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")
// Delete a bucket
const resp = await client.storagesClient.deleteBucket({
bucket: "my-bucket",
});
console.log("successfully deleted bucket");
// Unlink a bucket
const resp = await client.storagesClient.unlinkBucket({
Bucket: "my-bucket",
});
console.log("successfully unlinked bucket");
rig storage delete-bucket [bucket]
rig storage unlink-bucket [bucket]
Example:
rig storage delete-bucket my-bucket
rig storage unlink-bucket my-bucket
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.
- Golang SDK
- Typescript SDK
- CLI
// 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())
// Get a bucket
const resp = await client.storagesClient.getBucket({
bucket: "my-bucket",
});
console.log("Succesfully retrieved bucket", resp.bucket);
rig storage get-bucket [name] --json
Example:
rig storage get-bucket my-bucket --json
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.
- Golang SDK
- Typescript SDK
- CLI
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()))
const resp = await client.storagesClient.listBuckets({});
console.log(`successfully fetched ${resp.buckets.length} buckets`);
rig storage list [path] --json
Example:
rig storage list --json