Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-s3): Always use models.WrappedBucket to avoid panic #10827

Merged
merged 2 commits into from
May 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions plugins/source/aws/resources/services/s3/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/cloudquery/plugins/source/aws/resources/services/s3/models"
"github.com/cloudquery/plugin-sdk/v2/schema"
Expand Down Expand Up @@ -52,7 +51,12 @@ func listS3Buckets(ctx context.Context, meta schema.ClientMeta, _ *schema.Resour
if err != nil {
return err
}
res <- response.Buckets
for _, bucket := range response.Buckets {
res <- &models.WrappedBucket{
Name: bucket.Name,
CreationDate: bucket.CreationDate,
}
}
return nil
}

Expand All @@ -71,13 +75,12 @@ func listBucketRegion(cl *client.Client) string {
}

func resolveS3BucketsAttributes(ctx context.Context, meta schema.ClientMeta, r *schema.Resource) error {
bucket := r.Item.(types.Bucket)
resource := &models.WrappedBucket{Name: bucket.Name, CreationDate: bucket.CreationDate}
resource := r.Item.(*models.WrappedBucket)
cl := meta.(*client.Client)
svc := cl.Services().S3

output, err := svc.GetBucketLocation(ctx, &s3.GetBucketLocationInput{
Bucket: bucket.Name,
Bucket: resource.Name,
}, func(o *s3.Options) {
o.Region = listBucketRegion(cl)
})
Expand Down