2022-10-20 19:59:46 +00:00
|
|
|
package main
|
2022-10-16 20:17:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-06-11 12:54:26 +00:00
|
|
|
"fmt"
|
2023-08-05 21:53:17 +00:00
|
|
|
"isle/bootstrap"
|
|
|
|
"isle/daemon"
|
|
|
|
"isle/garage"
|
2022-10-16 20:17:26 +00:00
|
|
|
|
2024-06-22 15:49:56 +00:00
|
|
|
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
2022-10-16 20:17:26 +00:00
|
|
|
)
|
|
|
|
|
2022-10-26 21:21:31 +00:00
|
|
|
func garageInitializeGlobalBucket(
|
2022-10-26 22:23:39 +00:00
|
|
|
ctx context.Context,
|
2022-11-13 15:45:42 +00:00
|
|
|
logger *mlog.Logger,
|
2022-10-26 22:23:39 +00:00
|
|
|
hostBootstrap bootstrap.Bootstrap,
|
|
|
|
daemonConfig daemon.Config,
|
2024-06-11 12:54:26 +00:00
|
|
|
) (
|
|
|
|
garage.S3APICredentials, error,
|
|
|
|
) {
|
2024-06-17 18:51:02 +00:00
|
|
|
adminClient := daemon.NewGarageAdminClient(
|
|
|
|
logger, hostBootstrap, daemonConfig,
|
|
|
|
)
|
2022-10-19 14:20:26 +00:00
|
|
|
|
2024-06-12 08:53:06 +00:00
|
|
|
creds, err := adminClient.CreateS3APICredentials(
|
|
|
|
ctx, garage.GlobalBucketS3APICredentialsName,
|
2024-06-11 12:54:26 +00:00
|
|
|
)
|
2022-10-19 14:20:26 +00:00
|
|
|
if err != nil {
|
2024-06-12 08:53:06 +00:00
|
|
|
return creds, fmt.Errorf("creating global bucket credentials: %w", err)
|
2022-10-19 14:20:26 +00:00
|
|
|
}
|
|
|
|
|
2024-06-12 08:53:06 +00:00
|
|
|
bucketID, err := adminClient.CreateBucket(ctx, garage.GlobalBucket)
|
2022-10-19 14:20:26 +00:00
|
|
|
if err != nil {
|
2024-06-12 08:53:06 +00:00
|
|
|
return creds, fmt.Errorf("creating global bucket: %w", err)
|
2022-10-19 14:20:26 +00:00
|
|
|
}
|
|
|
|
|
2024-06-12 08:53:06 +00:00
|
|
|
if err := adminClient.GrantBucketPermissions(
|
|
|
|
ctx,
|
|
|
|
bucketID,
|
|
|
|
creds.ID,
|
|
|
|
garage.BucketPermissionRead,
|
|
|
|
garage.BucketPermissionWrite,
|
|
|
|
); err != nil {
|
|
|
|
return creds, fmt.Errorf(
|
2024-06-11 12:54:26 +00:00
|
|
|
"granting permissions to shared global bucket key: %w", err,
|
|
|
|
)
|
2022-10-19 14:20:26 +00:00
|
|
|
}
|
|
|
|
|
2024-06-12 08:53:06 +00:00
|
|
|
return creds, nil
|
2022-10-19 14:20:26 +00:00
|
|
|
}
|