From 00f23138d6e18e1e816d24f1302c3c1c9b94cb76 Mon Sep 17 00:00:00 2001 From: balamut-google <146325648+balamut-google@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:31:01 +0000 Subject: [PATCH] Complete migration to AWS Go client V2. --- aws-janitor/resources/clean.go | 9 ++++++--- aws-janitor/resources/s3_bucket.go | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/aws-janitor/resources/clean.go b/aws-janitor/resources/clean.go index f8908fa6..e5a4ce11 100644 --- a/aws-janitor/resources/clean.go +++ b/aws-janitor/resources/clean.go @@ -20,7 +20,7 @@ import ( "net/http" "strings" - "github.com/aws/aws-sdk-go/aws/awserr" + awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -47,8 +47,11 @@ func CleanAll(opts Options, region string) error { set, err := typ.ListAll(opts) if err != nil { // ignore errors for resources we do not have permissions to list - if reqerr, ok := errors.Cause(err).(awserr.RequestFailure); ok { - if reqerr.StatusCode() == http.StatusForbidden { + if resperr, ok := errors.Cause(err).(*awshttp.ResponseError); ok { + var responseError interface { + HTTPStatusCode() int + } + if resperr.As(&responseError) && responseError.HTTPStatusCode() == http.StatusForbidden { logger.Debugf("Skipping resources of type %T, account does not have permission to list", typ) continue } diff --git a/aws-janitor/resources/s3_bucket.go b/aws-janitor/resources/s3_bucket.go index 1170d891..c376d8f9 100644 --- a/aws-janitor/resources/s3_bucket.go +++ b/aws-janitor/resources/s3_bucket.go @@ -52,8 +52,8 @@ func (S3Bucket) MarkAndSweep(opts Options, set *Set) error { opt.Region = opts.Region }) - // ListBucket lists all buckets owned by the authenticated sender of the request - // https://pkg.go.dev/github.com/aws/aws-sdk-go/service/s3#S3.ListBuckets + // ListBuckets lists all buckets owned by the authenticated sender of the request + // https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Client.ListBuckets // regardless the region configured in client. resp, err := svc.ListBuckets(context.TODO(), &s3v2.ListBucketsInput{}) if err != nil { @@ -130,8 +130,8 @@ func (S3Bucket) ListAll(opts Options) (*Set, error) { opt.Region = opts.Region }) - // ListBucket lists all buckets owned by the authenticated sender of the request - // https://pkg.go.dev/github.com/aws/aws-sdk-go/service/s3#S3.ListBuckets + // ListBuckets lists all buckets owned by the authenticated sender of the request + // https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Client.ListBuckets // regardless the region configured in client. resp, err := svc.ListBuckets(context.TODO(), &s3v2.ListBucketsInput{}) if err != nil {