isle/go/cmd/entrypoint/garage_util.go

51 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"context"
"fmt"
"isle/bootstrap"
"isle/daemon"
"isle/garage"
"github.com/mediocregopher/mediocre-go-lib/v2/mlog"
)
func garageInitializeGlobalBucket(
2022-10-26 22:23:39 +00:00
ctx context.Context,
logger *mlog.Logger,
2022-10-26 22:23:39 +00:00
hostBootstrap bootstrap.Bootstrap,
daemonConfig daemon.Config,
) (
garage.S3APICredentials, error,
) {
adminClient := daemon.NewGarageAdminClient(
logger, hostBootstrap, daemonConfig,
)
creds, err := adminClient.CreateS3APICredentials(
ctx, garage.GlobalBucketS3APICredentialsName,
)
if err != nil {
return creds, fmt.Errorf("creating global bucket credentials: %w", err)
}
bucketID, err := adminClient.CreateBucket(ctx, garage.GlobalBucket)
if err != nil {
return creds, fmt.Errorf("creating global bucket: %w", err)
}
if err := adminClient.GrantBucketPermissions(
ctx,
bucketID,
creds.ID,
garage.BucketPermissionRead,
garage.BucketPermissionWrite,
); err != nil {
return creds, fmt.Errorf(
"granting permissions to shared global bucket key: %w", err,
)
}
return creds, nil
}