Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions pkg/config/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,34 @@ func (s *S3Info) awsUpload(ctx context.Context, bucket, key, asset string, rwc i
}

clt := s3.NewFromConfig(cfg)
opts := s3.CreateBucketInput{
Bucket: &bucket,
CreateBucketConfiguration: &types.CreateBucketConfiguration{
LocationConstraint: types.BucketLocationConstraint(*s.Region),
},
}
if _, err = clt.CreateBucket(ctx, &opts); err != nil {
var (
exists *types.BucketAlreadyExists
owned *types.BucketAlreadyOwnedByYou
)
switch {
case errors.As(err, &exists):
log.Info().Msgf("bucket %s already exists", bucket)
case errors.As(err, &owned):
log.Info().Msgf("bucket %s already owned by you", bucket)
default:
log.Err(err).Msgf("failed to create bucket %s", bucket)
return err
_, err = clt.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: &bucket})
if err != nil {
log.Debug().Msgf("bucket %s not found or not accessible, attempting to create", bucket)
opts := s3.CreateBucketInput{
Bucket: &bucket,
CreateBucketConfiguration: &types.CreateBucketConfiguration{
LocationConstraint: types.BucketLocationConstraint(*s.Region),
},
}
if _, err = clt.CreateBucket(ctx, &opts); err != nil {
var (
exists *types.BucketAlreadyExists
owned *types.BucketAlreadyOwnedByYou
)
switch {
case errors.As(err, &exists):
log.Info().Msgf("bucket %s already exists", bucket)
case errors.As(err, &owned):
log.Info().Msgf("bucket %s already owned by you", bucket)
default:
log.Err(err).Msgf("failed to create bucket %s", bucket)
return err
}
} else {
log.Info().Msgf("successfully created bucket %s", bucket)
}
} else {
log.Info().Msgf("bucket %s already exists", bucket)
}

uploader := manager.NewUploader(clt)
Expand Down