Skip to content

Commit 39c1e03

Browse files
author
Hongyu Zhou
committed
free ourselves of all aws-sdk-go v1
1 parent 68f556f commit 39c1e03

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/aws/aws-sdk-go-v2/config v1.18.29
1010
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.73
1111
github.com/aws/aws-sdk-go-v2/service/s3 v1.37.0
12+
github.com/aws/smithy-go v1.14.0
1213
github.com/fsnotify/fsnotify v1.5.1
1314
github.com/go-sql-driver/mysql v1.4.1
1415
github.com/google/go-cmp v0.5.8
@@ -42,7 +43,6 @@ require (
4243
github.com/aws/aws-sdk-go-v2/service/sso v1.13.1 // indirect
4344
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.1 // indirect
4445
github.com/aws/aws-sdk-go-v2/service/sts v1.21.1 // indirect
45-
github.com/aws/smithy-go v1.14.0 // indirect
4646
github.com/davecgh/go-spew v1.1.1 // indirect
4747
github.com/jmespath/go-jmespath v0.4.0 // indirect
4848
github.com/klauspost/compress v1.16.7 // indirect

pkg/reflector/download.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package reflector
33
import (
44
"bytes"
55
"context"
6+
er "errors"
67
"fmt"
78
"io"
8-
"net/http"
99
"os"
1010
"strings"
1111
"time"
@@ -14,7 +14,8 @@ import (
1414
"github.com/aws/aws-sdk-go-v2/config"
1515
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
1616
"github.com/aws/aws-sdk-go-v2/service/s3"
17-
"github.com/aws/aws-sdk-go/aws/awserr"
17+
"github.com/aws/aws-sdk-go-v2/service/s3/types"
18+
"github.com/aws/smithy-go"
1819
gzip "github.com/klauspost/pgzip"
1920

2021
"github.com/segmentio/ctlstore/pkg/errs"
@@ -60,11 +61,14 @@ func (d *S3Downloader) DownloadTo(w io.Writer) (n int64, err error) {
6061
stats.Observe("snapshot_download_time", time.Now().Sub(start))
6162

6263
if err != nil {
63-
switch err := err.(type) {
64-
case awserr.RequestFailure:
65-
if d.StartOverOnNotFound && err.StatusCode() == http.StatusNotFound {
66-
// don't bother retrying. we'll start with a fresh ldb.
67-
return -1, errors.WithTypes(errors.Wrap(err, "get s3 data"), errs.ErrTypePermanent)
64+
var ae smithy.APIError
65+
if er.As(err, &ae) {
66+
switch ae.(type) {
67+
case *types.NotFound:
68+
if d.StartOverOnNotFound {
69+
// don't bother retrying. we'll start with a fresh ldb.
70+
return -1, errors.WithTypes(errors.Wrap(err, "get s3 data"), errs.ErrTypePermanent)
71+
}
6872
}
6973
}
7074
// retry

pkg/reflector/download_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/aws/aws-sdk-go-v2/aws"
1213
"github.com/aws/aws-sdk-go-v2/service/s3"
13-
"github.com/aws/aws-sdk-go/aws/awserr"
14+
"github.com/aws/aws-sdk-go-v2/service/s3/types"
15+
"github.com/aws/smithy-go"
1416
gzip "github.com/klauspost/pgzip"
1517
"github.com/stretchr/testify/require"
1618

@@ -62,8 +64,9 @@ func TestS3DownloadErrors(t *testing.T) {
6264
isSupervisor: true,
6365
s3Client: func() reflector.S3Client {
6466
f := &fakes.FakeS3Client{}
65-
f.GetObjectReturns(nil, awserr.NewRequestFailure(
66-
awserr.New("error-code", "error-message", errors.New("failure")), http.StatusNotFound, ""))
67+
f.GetObjectReturns(nil, &types.NotFound{
68+
Message: aws.String("failure"),
69+
})
6770
return f
6871
},
6972
err: errors.New("failure"),
@@ -74,8 +77,9 @@ func TestS3DownloadErrors(t *testing.T) {
7477
name: "temporary failure on 404 if not-supervisor",
7578
s3Client: func() reflector.S3Client {
7679
f := &fakes.FakeS3Client{}
77-
f.GetObjectReturns(nil, awserr.NewRequestFailure(
78-
awserr.New("error-code", "error-message", errors.New("failure")), http.StatusNotFound, ""))
80+
f.GetObjectReturns(nil, &types.NotFound{
81+
Message: aws.String("failure"),
82+
})
7983
return f
8084
},
8185
err: errors.New("failure"),
@@ -86,8 +90,10 @@ func TestS3DownloadErrors(t *testing.T) {
8690
name: "temporary failure",
8791
s3Client: func() reflector.S3Client {
8892
f := &fakes.FakeS3Client{}
89-
f.GetObjectReturns(nil, awserr.NewRequestFailure(
90-
awserr.New("error-code", "error-message", errors.New("failure")), http.StatusInternalServerError, ""))
93+
f.GetObjectReturns(nil, &smithy.GenericAPIError{
94+
Code: string(rune(http.StatusInternalServerError)),
95+
Message: "failure",
96+
})
9197
return f
9298
},
9399
err: errors.New("failure"),

0 commit comments

Comments
 (0)