Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
esimkowitz committed Jan 22, 2025
1 parent a682ed6 commit a429c6f
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions pkg/remote/awsconn/awsconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,13 @@ func ParseProfiles() map[string]struct{} {
}

func ListBuckets(ctx context.Context, client *s3.Client) ([]types.Bucket, error) {
var err error
var output *s3.ListBucketsOutput
var buckets []types.Bucket
region := client.Options().Region
bucketPaginator := s3.NewListBucketsPaginator(client, &s3.ListBucketsInput{BucketRegion: &region})
for bucketPaginator.HasMorePages() {
output, err = bucketPaginator.NextPage(ctx)
log.Printf("output: %v", output)
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "AccessDenied" {
fmt.Println("You don't have permission to list buckets for this account.")
err = apiErr
} else {
return nil, fmt.Errorf("Couldn't list buckets for your account. Here's why: %v\n", err)
}
break
}
if output == nil {
break
output, err := client.ListBuckets(ctx, &s3.ListBucketsInput{})
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) {
return nil, fmt.Errorf("error listing buckets: %v", apiErr)
}
buckets = append(buckets, output.Buckets...)
return nil, fmt.Errorf("error listing buckets: %v", err)
}
return buckets, nil
return output.Buckets, nil
}

0 comments on commit a429c6f

Please sign in to comment.