From f8a4fcc6ecf4327b46328211261bb47230fdf538 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Tue, 25 Jun 2024 10:47:30 +0200 Subject: [PATCH] Go: replace aws-sdk-go with aws-sdk-go-v2 [AWS](https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-go-v1-on-july-31-2025/) announed the deprication of aws-sdk-go. Starting with July 30, 2024 this API will be in maintenance mode and with July 31, 2025 this API will be end of support. Therefore replace aws-sdk-go with its successor aws-sdk-go-v2. Signed-off-by: Florian Lehner --- go.mod | 29 +++++++++------- go.sum | 54 +++++++++++++++++------------ tools/coredump/coredump_test.go | 3 +- tools/coredump/main.go | 24 ++++++++----- tools/coredump/modulestore/store.go | 54 +++++++++++++++++------------ tools/coredump/modulestore/util.go | 14 ++++---- 6 files changed, 105 insertions(+), 73 deletions(-) diff --git a/go.mod b/go.mod index 80eba35d..92a7bd02 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,11 @@ go 1.22.2 require ( cloud.google.com/go/compute/metadata v0.3.0 - github.com/aws/aws-sdk-go v1.54.4 - github.com/aws/aws-sdk-go-v2/config v1.27.20 - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.7 + github.com/aws/aws-sdk-go-v2/config v1.27.21 + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8 + github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.1 github.com/aws/aws-sdk-go-v2/service/ec2 v1.165.0 + github.com/aws/aws-sdk-go-v2/service/s3 v1.56.1 github.com/cespare/xxhash/v2 v2.3.0 github.com/cilium/ebpf v0.15.0 github.com/containerd/containerd v1.7.18 @@ -33,6 +34,7 @@ require ( golang.org/x/sync v0.7.0 golang.org/x/sys v0.21.0 google.golang.org/grpc v1.64.0 + google.golang.org/protobuf v1.34.1 k8s.io/api v0.30.2 k8s.io/apimachinery v0.30.2 k8s.io/client-go v0.30.2 @@ -43,16 +45,20 @@ require ( github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/Microsoft/hcsshim v0.11.5 // indirect - github.com/aws/aws-sdk-go-v2 v1.29.0 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.17.20 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.11 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.11 // indirect + github.com/aws/aws-sdk-go-v2 v1.30.0 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.21 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.12 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.13 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.21.0 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.0 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.29.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.14 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.12 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.21.1 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.1 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.29.1 // indirect github.com/aws/smithy-go v1.20.2 // indirect github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/continuity v0.4.2 // indirect @@ -118,7 +124,6 @@ require ( google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect - google.golang.org/protobuf v1.34.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index a6714881..a2d94e6d 100644 --- a/go.sum +++ b/go.sum @@ -12,34 +12,44 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Microsoft/hcsshim v0.11.5 h1:haEcLNpj9Ka1gd3B3tAEs9CpE0c+1IhoL59w/exYU38= github.com/Microsoft/hcsshim v0.11.5/go.mod h1:MV8xMfmECjl5HdO7U/3/hFVnkmSBjAjmA09d4bExKcU= -github.com/aws/aws-sdk-go v1.54.4 h1:xZga3fPu7uxVgh83DIaQlb7r0cixFx1xKiiROTWAhpU= -github.com/aws/aws-sdk-go v1.54.4/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= -github.com/aws/aws-sdk-go-v2 v1.29.0 h1:uMlEecEwgp2gs6CsM6ugquNHr6mg0LHylPBR8u5Ojac= -github.com/aws/aws-sdk-go-v2 v1.29.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= -github.com/aws/aws-sdk-go-v2/config v1.27.20 h1:oQSn/KNUMV54X0FBEDQQ2ymNfcKyMT81ar8gyvMzzqs= -github.com/aws/aws-sdk-go-v2/config v1.27.20/go.mod h1:IbEMotJrWc3Bh7++HXZDlviHZP7kHrkHU3PNl9e17po= -github.com/aws/aws-sdk-go-v2/credentials v1.17.20 h1:VYTCplAeOeBv5InTtrmF61OIwD4aHKryg3KZ6hf7dsI= -github.com/aws/aws-sdk-go-v2/credentials v1.17.20/go.mod h1:ktubcFYvbN8++72jVM9IJoQH6Q2TP+Z7r2VbV1AaESU= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.7 h1:54QUEXjkE1SlxHmRA3gBXA52j/ZSAgdOfAFGv1NsPCY= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.7/go.mod h1:bQRjJsdSMzmo/qbtGeBtPbIMp1IgQ+9R9jYJLm12uJA= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.11 h1:ltkhl3I9ddcRR3Dsy+7bOFFq546O8OYsfNEXVIyuOSE= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.11/go.mod h1:H4D8JoCFNJwnT7U5U8iwgG24n71Fx2I/ZP/18eYFr9g= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.11 h1:+BgX2AY7yV4ggSwa80z/yZIJX+e0jnNxjMLVyfpSXM0= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.11/go.mod h1:DlBATBSDCz30BCdRFldmyLsAzJwi2pdQ+YSdJTHhTUI= +github.com/aws/aws-sdk-go-v2 v1.30.0 h1:6qAwtzlfcTtcL8NHtbDQAqgM5s6NDipQTkPxyH/6kAA= +github.com/aws/aws-sdk-go-v2 v1.30.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg= +github.com/aws/aws-sdk-go-v2/config v1.27.21 h1:yPX3pjGCe2hJsetlmGNB4Mngu7UPmvWPzzWCv1+boeM= +github.com/aws/aws-sdk-go-v2/config v1.27.21/go.mod h1:4XtlEU6DzNai8RMbjSF5MgGZtYvrhBP/aKZcRtZAVdM= +github.com/aws/aws-sdk-go-v2/credentials v1.17.21 h1:pjAqgzfgFhTv5grc7xPHtXCAaMapzmwA7aU+c/SZQGw= +github.com/aws/aws-sdk-go-v2/credentials v1.17.21/go.mod h1:nhK6PtBlfHTUDVmBLr1dg+WHCOCK+1Fu/WQyVHPsgNQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8 h1:FR+oWPFb/8qMVYMWN98bUZAGqPvLHiyqg1wqQGfUAXY= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8/go.mod h1:EgSKcHiuuakEIxJcKGzVNWh5srVAQ3jKaSrBGRYvM48= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.1 h1:D9VqWMuw7lJAX6d5eINfRQ/PkvtcJAK3Qmd6f6xEeUw= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.1/go.mod h1:ckvBx7codI4wzc5inOfDp5ZbK7TjMFa7eXwmLvXQrRk= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 h1:SJ04WXGTwnHlWIODtC5kJzKbeuHt+OUNOgKg7nfnUGw= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12/go.mod h1:FkpvXhA92gb3GE9LD6Og0pHHycTxW7xGpnEh5E7Opwo= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 h1:hb5KgeYfObi5MHkSSZMEudnIvX30iB+E21evI4r6BnQ= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12/go.mod h1:CroKe/eWJdyfy9Vx4rljP5wTUjNJfb+fPz1uMYUhEGM= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.12 h1:DXFWyt7ymx/l1ygdyTTS0X923e+Q2wXIxConJzrgwc0= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.12/go.mod h1:mVOr/LbvaNySK1/BTy4cBOCjhCNY2raWBwK4v+WR5J4= github.com/aws/aws-sdk-go-v2/service/ec2 v1.165.0 h1:FQpJS76mmmo21FZn9FAutjAIxotNkiGXUYfUQN/RfGA= github.com/aws/aws-sdk-go-v2/service/ec2 v1.165.0/go.mod h1:+dDvvbkwmJCZGzsSlsqEtJ6XhyG/hD2FHjIfpqcNl+o= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.13 h1:3A8vxp65nZy6aMlSCBvpIyxIbAN0DOSxaPDZuzasxuU= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.13/go.mod h1:IxJ/pMQ/Y+MDFGo6pQRyqzKKwtGMHb5IWp5PXSQr8dM= -github.com/aws/aws-sdk-go-v2/service/sso v1.21.0 h1:P0zUA+5liaoNILI/btBBQHC09PFPyRJr+w+Xt9KHKck= -github.com/aws/aws-sdk-go-v2/service/sso v1.21.0/go.mod h1:0bmRzdsq9/iNyP02H4UV0ZRjFx6qQBqRvfCJ4trFgjE= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.0 h1:jPV8U9r3msO9ECm9geW8PGjU/rz8vfPTPmIBbA83W3M= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.0/go.mod h1:B3G77bQDCmhp0RV0P/J9Kd4/qsymdWVhzTe3btAtywE= -github.com/aws/aws-sdk-go-v2/service/sts v1.29.0 h1:dqW4XRwPE/poWSqVntpeXLHzpPK6AOfKmL9QWDYl9aw= -github.com/aws/aws-sdk-go-v2/service/sts v1.29.0/go.mod h1:j8+hrxlmLR8ZQo6ytTAls/JFrt5bVisuS6PD8gw2VBw= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.14 h1:oWccitSnByVU74rQRHac4gLfDqjB6Z1YQGOY/dXKedI= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.14/go.mod h1:8SaZBlQdCLrc/2U3CEO48rYj9uR8qRsPRkmzwNM52pM= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14 h1:zSDPny/pVnkqABXYRicYuPf9z2bTqfH13HT3v6UheIk= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14/go.mod h1:3TTcI5JSzda1nw/pkVC9dhgLre0SNBFj2lYS4GctXKI= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.12 h1:tzha+v1SCEBpXWEuw6B/+jm4h5z8hZbTpXz0zRZqTnw= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.12/go.mod h1:n+nt2qjHGoseWeLHt1vEr6ZRCCxIN2KcNpJxBcYQSwI= +github.com/aws/aws-sdk-go-v2/service/s3 v1.56.1 h1:wsg9Z/vNnCmxWikfGIoOlnExtEU459cR+2d+iDJ8elo= +github.com/aws/aws-sdk-go-v2/service/s3 v1.56.1/go.mod h1:8rDw3mVwmvIWWX/+LWY3PPIMZuwnQdJMCt0iVFVT3qw= +github.com/aws/aws-sdk-go-v2/service/sso v1.21.1 h1:sd0BsnAvLH8gsp2e3cbaIr+9D7T1xugueQ7V/zUAsS4= +github.com/aws/aws-sdk-go-v2/service/sso v1.21.1/go.mod h1:lcQG/MmxydijbeTOp04hIuJwXGWPZGI3bwdFDGRTv14= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.1 h1:1uEFNNskK/I1KoZ9Q8wJxMz5V9jyBlsiaNrM7vA3YUQ= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.1/go.mod h1:z0P8K+cBIsFXUr5rzo/psUeJ20XjPN0+Nn8067Nd+E4= +github.com/aws/aws-sdk-go-v2/service/sts v1.29.1 h1:myX5CxqXE0QMZNja6FA1/FSE3Vu1rVmeUmpJMMzeZg0= +github.com/aws/aws-sdk-go-v2/service/sts v1.29.1/go.mod h1:N2mQiucsO0VwK9CYuS4/c2n6Smeh1v47Rz3dWCPFLdE= github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= diff --git a/tools/coredump/coredump_test.go b/tools/coredump/coredump_test.go index bfaabea6..30a45b6b 100644 --- a/tools/coredump/coredump_test.go +++ b/tools/coredump/coredump_test.go @@ -14,7 +14,8 @@ package main // require.NoError(t, err) // require.NotEmpty(t, cases) // -// store := initModuleStore() +// store, err := initModuleStore() +// require.NoError(t, err) // // for _, filename := range cases { // filename := filename diff --git a/tools/coredump/main.go b/tools/coredump/main.go index 1c9a87c4..a8f3a205 100644 --- a/tools/coredump/main.go +++ b/tools/coredump/main.go @@ -16,9 +16,9 @@ import ( "flag" "os" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/s3" + awsconfig "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/s3" + "github.com/elastic/otel-profiling-agent/tools/coredump/modulestore" "github.com/peterbourgon/ff/v3/ffcli" log "github.com/sirupsen/logrus" @@ -31,7 +31,10 @@ func main() { log.SetReportCaller(false) log.SetFormatter(&log.TextFormatter{}) - store := initModuleStore() + store, err := initModuleStore() + if err != nil { + log.Fatalf("%v", err) + } root := ffcli.Command{ Name: "coredump", @@ -58,9 +61,12 @@ func main() { } } -func initModuleStore() *modulestore.Store { - cfg := aws.NewConfig().WithRegion("eu-central-1") - sess := session.Must(session.NewSession(cfg)) - s3Client := s3.New(sess) - return modulestore.New(s3Client, moduleStoreS3Bucket, "modulecache") +func initModuleStore() (*modulestore.Store, error) { + cfg, err := awsconfig.LoadDefaultConfig(context.Background()) + if err != nil { + return nil, err + } + s3Client := s3.NewFromConfig(cfg) + ms := modulestore.New(s3Client, moduleStoreS3Bucket, "modulecache") + return ms, nil } diff --git a/tools/coredump/modulestore/store.go b/tools/coredump/modulestore/store.go index 1a5c9109..f3b0b801 100644 --- a/tools/coredump/modulestore/store.go +++ b/tools/coredump/modulestore/store.go @@ -10,6 +10,7 @@ package modulestore import ( + "context" "errors" "fmt" "io" @@ -19,10 +20,10 @@ import ( "syscall" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/service/s3" - "github.com/aws/aws-sdk-go/service/s3/s3manager" + s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager" + "github.com/aws/aws-sdk-go-v2/service/s3" + s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" + log "github.com/sirupsen/logrus" "golang.org/x/sys/unix" @@ -54,14 +55,14 @@ const ( // It is safe to create multiple `Store` instances for the same local directory and remote bucket // at the same time, also when created within multiple different applications. type Store struct { - s3client *s3.S3 + s3client *s3.Client bucket string localCachePath string } // New creates a new module storage. The modules present in the local cache are inspected and a // full index of the modules in the remote S3 bucket is retrieved and cached as well. -func New(s3client *s3.S3, s3Bucket, localCachePath string) *Store { +func New(s3client *s3.Client, s3Bucket, localCachePath string) *Store { return &Store{ s3client: s3client, bucket: s3Bucket, @@ -187,14 +188,17 @@ func (store *Store) UploadModule(id ID) error { return fmt.Errorf("failed to open local file: %w", err) } - _, err = store.s3client.PutObject(&s3.PutObjectInput{ - Bucket: aws.String(store.bucket), - Key: aws.String(makeS3Key(id)), + moduleKey := makeS3Key(id) + contentType := "application/octet-stream" + contentDisposition := "attachment" + + _, err = store.s3client.PutObject(context.TODO(), &s3.PutObjectInput{ + Bucket: &store.bucket, + Key: &moduleKey, Body: file, - ContentType: aws.String("application/octet-stream"), - ContentDisposition: aws.String("attachment"), + ContentType: &contentType, + ContentDisposition: &contentDisposition, }) - if err != nil { return fmt.Errorf("failed to upload file: %w", err) } @@ -221,11 +225,11 @@ func (store *Store) RemoveLocalModule(id ID) error { // RemoveRemoteModule removes a module from the remote storage. No-op if not present. func (store *Store) RemoveRemoteModule(id ID) error { - _, err := store.s3client.DeleteObject(&s3.DeleteObjectInput{ + moduleKey := makeS3Key(id) + _, err := store.s3client.DeleteObject(context.TODO(), &s3.DeleteObjectInput{ Bucket: &store.bucket, - Key: aws.String(makeS3Key(id)), + Key: &moduleKey, }) - if err != nil { if isErrNoSuchKey(err) { return nil @@ -308,9 +312,10 @@ func (store *Store) UnpackModule(id ID, out io.Writer) error { // IsPresentRemotely checks whether a module is present in the remote data-store. func (store *Store) IsPresentRemotely(id ID) (bool, error) { - _, err := store.s3client.HeadObject(&s3.HeadObjectInput{ + moduleKey := makeS3Key(id) + _, err := store.s3client.HeadObject(context.TODO(), &s3.HeadObjectInput{ Bucket: &store.bucket, - Key: aws.String(makeS3Key(id)), + Key: &moduleKey, }) if err != nil { @@ -419,13 +424,14 @@ func (store *Store) ensurePresentLocally(id ID) (string, error) { } defer file.Close() + moduleKey := makeS3Key(id) req := &s3.GetObjectInput{ - Bucket: aws.String(store.bucket), - Key: aws.String(makeS3Key(id)), + Bucket: &store.bucket, + Key: &moduleKey, } - downloader := s3manager.NewDownloaderWithClient(store.s3client) - _, err = downloader.Download(file, req) + downloader := s3manager.NewDownloader(store.s3client) + _, err = downloader.Download(context.TODO(), file, req) if err != nil { if isErrNoSuchKey(err) { return "", errors.New("module doesn't exist in remote storage") @@ -499,6 +505,8 @@ func isErrNoSuchKey(err error) bool { // bucket should rarely happen in practice. // // For forward compatibility (in case this ever gets fixed), we also check for `NoSuchKey`. - var e awserr.Error - return errors.As(err, &e) && (e.Code() == "NoSuchKey" || e.Code() == "NotFound") + + var noSuchKey s3types.NoSuchKey + var notFound s3types.NotFound + return errors.As(err, &noSuchKey) || errors.As(err, ¬Found) } diff --git a/tools/coredump/modulestore/util.go b/tools/coredump/modulestore/util.go index e86d7af1..cf43f0cd 100644 --- a/tools/coredump/modulestore/util.go +++ b/tools/coredump/modulestore/util.go @@ -7,20 +7,22 @@ package modulestore import ( + "context" "errors" "fmt" - "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go-v2/service/s3" + s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" ) // getS3ObjectList gets all matching objects in an S3 bucket. -func getS3ObjectList(client *s3.S3, bucket, prefix string, itemLimit int) ([]*s3.Object, error) { - var objects []*s3.Object +func getS3ObjectList(client *s3.Client, bucket, prefix string, itemLimit int) ([]s3types.Object, error) { + var objects []s3types.Object var contToken *string - var batchSize int64 = s3ResultsPerPage + var batchSize int32 = s3ResultsPerPage for { - resp, err := client.ListObjectsV2(&s3.ListObjectsV2Input{ + resp, err := client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{ Bucket: &bucket, Prefix: &prefix, MaxKeys: &batchSize, @@ -33,7 +35,7 @@ func getS3ObjectList(client *s3.S3, bucket, prefix string, itemLimit int) ([]*s3 objects = append(objects, resp.Contents...) - if int64(len(resp.Contents)) != batchSize { + if int32(len(resp.Contents)) != batchSize { break } if len(resp.Contents) > itemLimit {