Skip to content

Commit

Permalink
Merge pull request mendersoftware#653 from sentinel-tech/fix-bucket-i…
Browse files Browse the repository at this point in the history
…nitialization

Fix bucket initialization
  • Loading branch information
tranchitella authored Dec 19, 2021
2 parents 64ed029 + e4335c1 commit d0093dd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion s3/filestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ func getArtifactByTenant(ctx context.Context, objectID string) string {
}

func (s *SimpleStorageService) InitBucket(ctx context.Context, bucket string) error {
hparams := &s3.HeadBucketInput{
Bucket: aws.String(bucket),
}

headBucketCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

_, err := s.client.HeadBucketWithContext(headBucketCtx, hparams)
if nil == err {
// bucket exists and have permission to access it
return nil
}

// minio requires explicit bucket creation
cparams := &s3.CreateBucketInput{
Bucket: aws.String(bucket), // Required
Expand All @@ -174,7 +187,7 @@ func (s *SimpleStorageService) InitBucket(ctx context.Context, bucket string) er
ctxWithTimeout, cancelFn := context.WithTimeout(ctx, 5*time.Second)
defer cancelFn()

_, err := s.client.CreateBucketWithContext(ctxWithTimeout, cparams)
_, err = s.client.CreateBucketWithContext(ctxWithTimeout, cparams)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() != ErrCodeBucketAlreadyOwnedByYou {
Expand Down

0 comments on commit d0093dd

Please sign in to comment.