From eae1c7713e7f715096bbccc2370b9cedcdb04ebb Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 27 Dec 2023 09:38:28 -0800 Subject: [PATCH 01/23] fixes up until now --- aws/retry/middleware.go | 4 ++-- service/internal/checksum/middleware_add.go | 14 ++++++++++++++ .../checksum/middleware_compute_input_checksum.go | 12 +----------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/aws/retry/middleware.go b/aws/retry/middleware.go index 722ca34c6a0..e956207457b 100644 --- a/aws/retry/middleware.go +++ b/aws/retry/middleware.go @@ -328,10 +328,10 @@ func AddRetryMiddlewares(stack *smithymiddle.Stack, options AddRetryMiddlewaresO middleware.LogAttempts = options.LogRetryAttempts }) - if err := stack.Finalize.Add(attempt, smithymiddle.After); err != nil { + if err := stack.Finalize.Insert(attempt, "Signing", smithymiddle.Before); err != nil { return err } - if err := stack.Finalize.Add(&MetricsHeader{}, smithymiddle.After); err != nil { + if err := stack.Finalize.Insert(&MetricsHeader{}, attempt.ID(), smithymiddle.After); err != nil { return err } return nil diff --git a/service/internal/checksum/middleware_add.go b/service/internal/checksum/middleware_add.go index 610e7ca80eb..4b17bb3d5e3 100644 --- a/service/internal/checksum/middleware_add.go +++ b/service/internal/checksum/middleware_add.go @@ -90,6 +90,20 @@ func AddInputMiddleware(stack *middleware.Stack, options InputMiddlewareOptions) return err } + // If trailing checksum is not supported no need for finalize handler to be added. + if options.EnableTrailingChecksum { + trailerMiddleware := &addInputChecksumTrailer{ + EnableTrailingChecksum: inputChecksum.EnableTrailingChecksum, + RequireChecksum: inputChecksum.RequireChecksum, + EnableComputePayloadHash: inputChecksum.EnableComputePayloadHash, + EnableDecodedContentLengthHeader: inputChecksum.EnableDecodedContentLengthHeader, + } + err = stack.Finalize.Insert(trailerMiddleware, "Retry", middleware.After) + if err != nil { + return err + } + } + return nil } diff --git a/service/internal/checksum/middleware_compute_input_checksum.go b/service/internal/checksum/middleware_compute_input_checksum.go index c7740658aea..b2b1d277485 100644 --- a/service/internal/checksum/middleware_compute_input_checksum.go +++ b/service/internal/checksum/middleware_compute_input_checksum.go @@ -71,8 +71,6 @@ type computeInputPayloadChecksum struct { // header for the decoded length of the underlying stream. Will only be set // when used with trailing checksums, and aws-chunked content-encoding. EnableDecodedContentLengthHeader bool - - useTrailer bool } // ID provides the middleware's identifier. @@ -178,15 +176,7 @@ func (m *computeInputPayloadChecksum) HandleFinalize( // ContentSHA256Header middleware handles the header ctx = v4.SetPayloadHash(ctx, streamingUnsignedPayloadTrailerPayloadHash) } - - m.useTrailer = true - mw := &addInputChecksumTrailer{ - EnableTrailingChecksum: m.EnableTrailingChecksum, - RequireChecksum: m.RequireChecksum, - EnableComputePayloadHash: m.EnableComputePayloadHash, - EnableDecodedContentLengthHeader: m.EnableDecodedContentLengthHeader, - } - return mw.HandleFinalize(ctx, in, next) + return next.HandleFinalize(ctx, in) } // If trailing checksums are not enabled but protocol is still HTTPS From 0ad4fd9c4da17cd4dd28acfa49613fe8068b7c14 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 27 Dec 2023 14:48:17 -0800 Subject: [PATCH 02/23] set use trailer context flag to pass integ tests --- .../internal/checksum/middleware_compute_input_checksum.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/internal/checksum/middleware_compute_input_checksum.go b/service/internal/checksum/middleware_compute_input_checksum.go index b2b1d277485..17b580a0b55 100644 --- a/service/internal/checksum/middleware_compute_input_checksum.go +++ b/service/internal/checksum/middleware_compute_input_checksum.go @@ -73,6 +73,8 @@ type computeInputPayloadChecksum struct { EnableDecodedContentLengthHeader bool } +type useTrailer struct {} + // ID provides the middleware's identifier. func (m *computeInputPayloadChecksum) ID() string { return "AWSChecksum:ComputeInputPayloadChecksum" @@ -176,6 +178,7 @@ func (m *computeInputPayloadChecksum) HandleFinalize( // ContentSHA256Header middleware handles the header ctx = v4.SetPayloadHash(ctx, streamingUnsignedPayloadTrailerPayloadHash) } + ctx = context.WithValue(ctx, useTrailer{}, true) return next.HandleFinalize(ctx, in) } @@ -258,6 +261,10 @@ func (m *addInputChecksumTrailer) HandleFinalize( ) ( out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { + v, ok := ctx.Value(useTrailer{}).(bool) + if !ok || !v { + return next.HandleFinalize(ctx, in) + } req, ok := in.Request.(*smithyhttp.Request) if !ok { return out, metadata, computeInputTrailingChecksumError{ From 76345599034a015fedcaf9cba2d42b775c574c82 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 27 Dec 2023 15:03:15 -0800 Subject: [PATCH 03/23] add integ test --- .../integrationtest/s3/checksum_test.go | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index 9da73ac8d78..4c327981d80 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -10,18 +10,37 @@ import ( "io/ioutil" "strings" "testing" - + "net/http" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/aws/smithy-go/logging" "github.com/google/go-cmp/cmp" + "github.com/aws/aws-sdk-go/aws/awserr" +) + +var ( + isInitialCall = true ) +type retryClient struct { + baseClient aws.HTTPClient +} + +func (c *retryClient) Do(req *http.Request) (*http.Response, error) { + if isInitialCall { + isInitialCall = false + // use retryable error + return nil, awserr.New("ErrCodeSerialization", "mock retryable error on initial call", nil) + } + return c.baseClient.Do(req) +} + func TestInteg_ObjectChecksums(t *testing.T) { cases := map[string]map[string]struct { disableHTTPS bool + retry bool params *s3.PutObjectInput expectErr string @@ -86,6 +105,7 @@ func TestInteg_ObjectChecksums(t *testing.T) { }, }, "autofill trailing checksum": { + retry: true, params: &s3.PutObjectInput{ Body: strings.NewReader("hello world"), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, @@ -343,6 +363,15 @@ func TestInteg_ObjectChecksums(t *testing.T) { o.EndpointOptions.DisableHTTPS = c.disableHTTPS } + if c.retry { + opts := s3client.Options() + baseClient := opts.HTTPClient + opts.HTTPClient = &retryClient{ + baseClient: baseClient, + } + s3client = s3.New(opts) + } + t.Logf("putting bucket: %q, object: %q", *c.params.Bucket, *c.params.Key) putResult, err := s3client.PutObject(ctx, c.params, s3Options) if err == nil && len(c.expectErr) != 0 { From 586b1fd8d7d1332fea74289a25a9840eeba3ecd0 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Thu, 28 Dec 2023 09:47:44 -0800 Subject: [PATCH 04/23] fix signing middleware not found bug --- aws/retry/middleware.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/aws/retry/middleware.go b/aws/retry/middleware.go index e956207457b..5875e1db533 100644 --- a/aws/retry/middleware.go +++ b/aws/retry/middleware.go @@ -328,9 +328,18 @@ func AddRetryMiddlewares(stack *smithymiddle.Stack, options AddRetryMiddlewaresO middleware.LogAttempts = options.LogRetryAttempts }) - if err := stack.Finalize.Insert(attempt, "Signing", smithymiddle.Before); err != nil { - return err + // index retry to before signing, if signing exists + _, ok := stack.Finalize.Get("Signing") + if !ok { + if err := stack.Finalize.Add(attempt, smithymiddle.After); err != nil { + return err + } + } else { + if err := stack.Finalize.Insert(attempt, "Signing", smithymiddle.Before); err != nil { + return err + } } + if err := stack.Finalize.Insert(&MetricsHeader{}, attempt.ID(), smithymiddle.After); err != nil { return err } From 2884b763e4fd8f6d3f40a907421924387ff3520a Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Thu, 28 Dec 2023 10:02:20 -0800 Subject: [PATCH 05/23] add back removed useTrailer due to use in unit test --- service/internal/checksum/middleware_compute_input_checksum.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/service/internal/checksum/middleware_compute_input_checksum.go b/service/internal/checksum/middleware_compute_input_checksum.go index 17b580a0b55..e17f6824c48 100644 --- a/service/internal/checksum/middleware_compute_input_checksum.go +++ b/service/internal/checksum/middleware_compute_input_checksum.go @@ -71,6 +71,8 @@ type computeInputPayloadChecksum struct { // header for the decoded length of the underlying stream. Will only be set // when used with trailing checksums, and aws-chunked content-encoding. EnableDecodedContentLengthHeader bool + + useTrailer bool } type useTrailer struct {} @@ -178,6 +180,7 @@ func (m *computeInputPayloadChecksum) HandleFinalize( // ContentSHA256Header middleware handles the header ctx = v4.SetPayloadHash(ctx, streamingUnsignedPayloadTrailerPayloadHash) } + m.useTrailer = true ctx = context.WithValue(ctx, useTrailer{}, true) return next.HandleFinalize(ctx, in) } From 1c0c19a94e074064bc216ac74f28104fafd97560 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Thu, 28 Dec 2023 10:20:18 -0800 Subject: [PATCH 06/23] remove mistakenly included go v1 module --- .../internal/integrationtest/s3/checksum_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index 4c327981d80..df4e63703d3 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -17,7 +17,6 @@ import ( s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/aws/smithy-go/logging" "github.com/google/go-cmp/cmp" - "github.com/aws/aws-sdk-go/aws/awserr" ) var ( @@ -28,11 +27,22 @@ type retryClient struct { baseClient aws.HTTPClient } +type mockConnectionError struct{ err error } + +func (m mockConnectionError) ConnectionError() bool { + return true +} +func (m mockConnectionError) Error() string { + return fmt.Sprintf("request error: %v", m.err) +} +func (m mockConnectionError) Unwrap() error { + return m.err +} + func (c *retryClient) Do(req *http.Request) (*http.Response, error) { if isInitialCall { isInitialCall = false - // use retryable error - return nil, awserr.New("ErrCodeSerialization", "mock retryable error on initial call", nil) + return nil, mockConnectionError{} } return c.baseClient.Do(req) } From 5d5718415f20631b463f3d6ce127529ea84608ec Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Thu, 28 Dec 2023 12:53:41 -0800 Subject: [PATCH 07/23] fix stack list check --- service/internal/checksum/middleware_add_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/service/internal/checksum/middleware_add_test.go b/service/internal/checksum/middleware_add_test.go index 74f4cdfe78b..2e4a64f115b 100644 --- a/service/internal/checksum/middleware_add_test.go +++ b/service/internal/checksum/middleware_add_test.go @@ -39,6 +39,7 @@ func TestAddInputMiddleware(t *testing.T) { "ComputePayloadHash", "Finalize stack step", "Retry", + "addInputChecksumTrailer", "ResolveEndpointV2", "AWSChecksum:ComputeInputPayloadChecksum", "Signing", @@ -73,6 +74,7 @@ func TestAddInputMiddleware(t *testing.T) { "ComputePayloadHash", "Finalize stack step", "Retry", + "addInputChecksumTrailer", "ResolveEndpointV2", "AWSChecksum:ComputeInputPayloadChecksum", "Signing", @@ -209,6 +211,7 @@ func TestRemoveInputMiddleware(t *testing.T) { "ComputePayloadHash", "Finalize stack step", "Retry", + "addInputChecksumTrailer", "ResolveEndpointV2", "Signing", "Deserialize stack step", From 1ca711f4e25f49139cf68d33dc9e17184ff6cead Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Thu, 28 Dec 2023 14:32:12 -0800 Subject: [PATCH 08/23] fix trailer checksum unit tests --- .../checksum/middleware_compute_input_checksum_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service/internal/checksum/middleware_compute_input_checksum_test.go b/service/internal/checksum/middleware_compute_input_checksum_test.go index 3505663e5e1..c3362bf07e0 100644 --- a/service/internal/checksum/middleware_compute_input_checksum_test.go +++ b/service/internal/checksum/middleware_compute_input_checksum_test.go @@ -773,9 +773,16 @@ func TestComputeInputPayloadChecksum(t *testing.T) { EnableComputePayloadHash: true, EnableDecodedContentLengthHeader: true, } + if c.optionsFn != nil { c.optionsFn(m) } + trailerMiddleware := &addInputChecksumTrailer{ + EnableTrailingChecksum: m.EnableTrailingChecksum, + RequireChecksum: m.RequireChecksum, + EnableComputePayloadHash: m.EnableComputePayloadHash, + EnableDecodedContentLengthHeader: m.EnableDecodedContentLengthHeader, + } ctx := context.Background() var logged bytes.Buffer @@ -809,6 +816,7 @@ func TestComputeInputPayloadChecksum(t *testing.T) { // Build middleware stack.Finalize.Add(m, middleware.After) + stack.Finalize.Add(trailerMiddleware, middleware.After) // Validate defer to finalize was performed as expected stack.Finalize.Add(middleware.FinalizeMiddlewareFunc( From 3426a95bfbaf5de9d5debbfd97a75176e54a3fd0 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Thu, 28 Dec 2023 15:30:24 -0800 Subject: [PATCH 09/23] add expected signed retry header in unit tests --- service/s3/internal/customizations/presign_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/service/s3/internal/customizations/presign_test.go b/service/s3/internal/customizations/presign_test.go index fb689cba3ba..fee63bd31ed 100644 --- a/service/s3/internal/customizations/presign_test.go +++ b/service/s3/internal/customizations/presign_test.go @@ -41,6 +41,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -62,6 +63,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -84,6 +86,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -105,6 +108,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -123,6 +127,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -142,6 +147,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, "Content-Length": []string{"100"}, }, @@ -163,6 +169,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mfzwi23gnjvgw.mrap.accesspoint.s3-global.amazonaws.com"}, @@ -204,6 +211,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -228,6 +236,7 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -315,6 +324,7 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -340,6 +350,7 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -366,6 +377,7 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -391,6 +403,7 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -413,6 +426,7 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ + "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, From c011334510b2b7c71c5c27f314611f6aa94c66a8 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 2 Jan 2024 13:14:29 -0800 Subject: [PATCH 10/23] drop retry middlewares from presigning ops --- .../AwsHttpPresignURLClientGenerator.java | 8 ++++++++ .../smithy/aws/go/codegen/SdkGoTypes.java | 7 +++++++ .../middleware_compute_input_checksum.go | 2 +- .../integrationtest/s3/checksum_test.go | 20 +++++++++---------- service/s3/api_client.go | 6 ++++++ .../internal/customizations/presign_test.go | 14 ------------- 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpPresignURLClientGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpPresignURLClientGenerator.java index 1d9589a98bf..2d578673647 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpPresignURLClientGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpPresignURLClientGenerator.java @@ -375,6 +375,14 @@ private void writeConvertToPresignMiddleware( if _, ok := stack.Finalize.Get(($1P)(nil).ID()); ok { stack.Finalize.Remove(($1P)(nil).ID()) }""", SdkGoTypes.ServiceInternal.AcceptEncoding.DisableGzip); + writer.write(""" + if _, ok := stack.Finalize.Get(($1P)(nil).ID()); ok { + stack.Finalize.Remove(($1P)(nil).ID()) + }""", SdkGoTypes.Aws.Retry.Attempt); + writer.write(""" + if _, ok := stack.Finalize.Get(($1P)(nil).ID()); ok { + stack.Finalize.Remove(($1P)(nil).ID()) + }""", SdkGoTypes.Aws.Retry.MetricsHeader); writer.write("stack.Deserialize.Clear()"); writer.write("stack.Build.Remove(($P)(nil).ID())", requestInvocationID); writer.write("stack.Build.Remove($S)", "UserAgent"); diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java index 437372a1ec0..f960ae88d9e 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java @@ -34,6 +34,7 @@ public static final class Aws { public static final Symbol IsCredentialsProvider = AwsGoDependency.AWS_CORE.valueSymbol("IsCredentialsProvider"); public static final Symbol AnonymousCredentials = AwsGoDependency.AWS_CORE.pointableSymbol("AnonymousCredentials"); + public static final class Middleware { public static final Symbol GetRequiresLegacyEndpoints = AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("GetRequiresLegacyEndpoints"); public static final Symbol GetSigningName = AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("GetSigningName"); @@ -41,6 +42,12 @@ public static final class Middleware { public static final Symbol SetSigningName = AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("SetSigningName"); public static final Symbol SetSigningRegion = AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("SetSigningRegion"); } + + + public static final class Retry { + public static final Symbol Attempt = AwsGoDependency.AWS_RETRY.pointableSymbol("Attempt"); + public static final Symbol MetricsHeader = AwsGoDependency.AWS_RETRY.pointableSymbol("MetricsHeader"); + } } public static final class Internal { diff --git a/service/internal/checksum/middleware_compute_input_checksum.go b/service/internal/checksum/middleware_compute_input_checksum.go index e17f6824c48..a8bcd7cb28d 100644 --- a/service/internal/checksum/middleware_compute_input_checksum.go +++ b/service/internal/checksum/middleware_compute_input_checksum.go @@ -75,7 +75,7 @@ type computeInputPayloadChecksum struct { useTrailer bool } -type useTrailer struct {} +type useTrailer struct{} // ID provides the middleware's identifier. func (m *computeInputPayloadChecksum) ID() string { diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index df4e63703d3..aa21c74d85f 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -7,16 +7,16 @@ import ( "bytes" "context" "fmt" - "io/ioutil" - "strings" - "testing" - "net/http" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/aws/smithy-go/logging" "github.com/google/go-cmp/cmp" + "io/ioutil" + "net/http" + "strings" + "testing" ) var ( @@ -24,7 +24,7 @@ var ( ) type retryClient struct { - baseClient aws.HTTPClient + baseClient aws.HTTPClient } type mockConnectionError struct{ err error } @@ -40,11 +40,11 @@ func (m mockConnectionError) Unwrap() error { } func (c *retryClient) Do(req *http.Request) (*http.Response, error) { - if isInitialCall { - isInitialCall = false - return nil, mockConnectionError{} - } - return c.baseClient.Do(req) + if isInitialCall { + isInitialCall = false + return nil, mockConnectionError{} + } + return c.baseClient.Do(req) } func TestInteg_ObjectChecksums(t *testing.T) { diff --git a/service/s3/api_client.go b/service/s3/api_client.go index a3fe93b7f20..5e5f27b2d72 100644 --- a/service/s3/api_client.go +++ b/service/s3/api_client.go @@ -777,6 +777,12 @@ func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, op if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) } + if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { + stack.Finalize.Remove((*retry.Attempt)(nil).ID()) + } + if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { + stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) + } stack.Deserialize.Clear() stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) stack.Build.Remove("UserAgent") diff --git a/service/s3/internal/customizations/presign_test.go b/service/s3/internal/customizations/presign_test.go index fee63bd31ed..fb689cba3ba 100644 --- a/service/s3/internal/customizations/presign_test.go +++ b/service/s3/internal/customizations/presign_test.go @@ -41,7 +41,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -63,7 +62,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -86,7 +84,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -108,7 +105,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -127,7 +123,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -147,7 +142,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, "Content-Length": []string{"100"}, }, @@ -169,7 +163,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mfzwi23gnjvgw.mrap.accesspoint.s3-global.amazonaws.com"}, @@ -211,7 +204,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -236,7 +228,6 @@ func TestPutObject_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -324,7 +315,6 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -350,7 +340,6 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -377,7 +366,6 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Content-Length": []string{"11"}, "Content-Type": []string{"application/octet-stream"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, @@ -403,7 +391,6 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, @@ -426,7 +413,6 @@ func TestUploadPart_PresignURL(t *testing.T) { }, expectMethod: "PUT", expectSignedHeader: http.Header{ - "Amz-Sdk-Request": []string{"attempt=1; max=1"}, "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, }, }, From 3a4126805f994a40b67048c1132596bb644b6933 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 2 Jan 2024 14:00:01 -0800 Subject: [PATCH 11/23] add noop sra auth relevant middlewares to imds --- aws/retry/middleware.go | 11 +---- feature/ec2/imds/api_op_GetDynamicData.go | 1 + feature/ec2/imds/api_op_GetIAMInfo.go | 1 + .../api_op_GetInstanceIdentityDocument.go | 1 + feature/ec2/imds/api_op_GetMetadata.go | 3 +- feature/ec2/imds/api_op_GetRegion.go | 1 + feature/ec2/imds/api_op_GetUserData.go | 1 + feature/ec2/imds/auth.go | 49 +++++++++++++++++++ feature/ec2/imds/endpoints.go | 20 ++++++++ feature/ec2/imds/request_middleware.go | 21 ++++++++ 10 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 feature/ec2/imds/auth.go create mode 100644 feature/ec2/imds/endpoints.go diff --git a/aws/retry/middleware.go b/aws/retry/middleware.go index 5875e1db533..dc703d482d2 100644 --- a/aws/retry/middleware.go +++ b/aws/retry/middleware.go @@ -329,15 +329,8 @@ func AddRetryMiddlewares(stack *smithymiddle.Stack, options AddRetryMiddlewaresO }) // index retry to before signing, if signing exists - _, ok := stack.Finalize.Get("Signing") - if !ok { - if err := stack.Finalize.Add(attempt, smithymiddle.After); err != nil { - return err - } - } else { - if err := stack.Finalize.Insert(attempt, "Signing", smithymiddle.Before); err != nil { - return err - } + if err := stack.Finalize.Insert(attempt, "Signing", smithymiddle.Before); err != nil { + return err } if err := stack.Finalize.Insert(&MetricsHeader{}, attempt.ID(), smithymiddle.After); err != nil { diff --git a/feature/ec2/imds/api_op_GetDynamicData.go b/feature/ec2/imds/api_op_GetDynamicData.go index 9e3bdb0e66e..af58b6bb102 100644 --- a/feature/ec2/imds/api_op_GetDynamicData.go +++ b/feature/ec2/imds/api_op_GetDynamicData.go @@ -56,6 +56,7 @@ type GetDynamicDataOutput struct { func addGetDynamicDataMiddleware(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, + "GetDynamicData", buildGetDynamicDataPath, buildGetDynamicDataOutput) } diff --git a/feature/ec2/imds/api_op_GetIAMInfo.go b/feature/ec2/imds/api_op_GetIAMInfo.go index 24845dccd6d..5111cc90cac 100644 --- a/feature/ec2/imds/api_op_GetIAMInfo.go +++ b/feature/ec2/imds/api_op_GetIAMInfo.go @@ -53,6 +53,7 @@ type GetIAMInfoOutput struct { func addGetIAMInfoMiddleware(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, + "GetIAMInfo", buildGetIAMInfoPath, buildGetIAMInfoOutput, ) diff --git a/feature/ec2/imds/api_op_GetInstanceIdentityDocument.go b/feature/ec2/imds/api_op_GetInstanceIdentityDocument.go index a87758ed302..dc8c09edf03 100644 --- a/feature/ec2/imds/api_op_GetInstanceIdentityDocument.go +++ b/feature/ec2/imds/api_op_GetInstanceIdentityDocument.go @@ -54,6 +54,7 @@ type GetInstanceIdentityDocumentOutput struct { func addGetInstanceIdentityDocumentMiddleware(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, + "GetInstanceIdentityDocument", buildGetInstanceIdentityDocumentPath, buildGetInstanceIdentityDocumentOutput, ) diff --git a/feature/ec2/imds/api_op_GetMetadata.go b/feature/ec2/imds/api_op_GetMetadata.go index cb0ce4c0004..4fec055da12 100644 --- a/feature/ec2/imds/api_op_GetMetadata.go +++ b/feature/ec2/imds/api_op_GetMetadata.go @@ -56,8 +56,9 @@ type GetMetadataOutput struct { func addGetMetadataMiddleware(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, + "GetMetadata", buildGetMetadataPath, - buildGetMetadataOutput) + buildGetMetadataOutput,) } func buildGetMetadataPath(params interface{}) (string, error) { diff --git a/feature/ec2/imds/api_op_GetRegion.go b/feature/ec2/imds/api_op_GetRegion.go index 7b9b48912af..8c0572bb5c8 100644 --- a/feature/ec2/imds/api_op_GetRegion.go +++ b/feature/ec2/imds/api_op_GetRegion.go @@ -45,6 +45,7 @@ type GetRegionOutput struct { func addGetRegionMiddleware(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, + "GetRegion", buildGetInstanceIdentityDocumentPath, buildGetRegionOutput, ) diff --git a/feature/ec2/imds/api_op_GetUserData.go b/feature/ec2/imds/api_op_GetUserData.go index 88aa61e9ad9..8903697244a 100644 --- a/feature/ec2/imds/api_op_GetUserData.go +++ b/feature/ec2/imds/api_op_GetUserData.go @@ -45,6 +45,7 @@ type GetUserDataOutput struct { func addGetUserDataMiddleware(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, + "GetUserData", buildGetUserDataPath, buildGetUserDataOutput) } diff --git a/feature/ec2/imds/auth.go b/feature/ec2/imds/auth.go new file mode 100644 index 00000000000..fa982fc8d61 --- /dev/null +++ b/feature/ec2/imds/auth.go @@ -0,0 +1,49 @@ +package imds + +import ( + "context" + "github.com/aws/smithy-go/middleware" +) + +type getIdentityMiddleware struct { + options Options +} + +func (*getIdentityMiddleware) ID() string { + return "GetIdentity" +} + +func (m *getIdentityMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} + +type signRequestMiddleware struct { +} + +func (*signRequestMiddleware) ID() string { + return "Signing" +} + + +func (m *signRequestMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} + +type resolveAuthSchemeMiddleware struct { + operation string + options Options +} + +func (*resolveAuthSchemeMiddleware) ID() string { + return "ResolveAuthScheme" +} + +func (m *resolveAuthSchemeMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} \ No newline at end of file diff --git a/feature/ec2/imds/endpoints.go b/feature/ec2/imds/endpoints.go new file mode 100644 index 00000000000..e9446025594 --- /dev/null +++ b/feature/ec2/imds/endpoints.go @@ -0,0 +1,20 @@ +package imds + +import ( + "context" + "github.com/aws/smithy-go/middleware" +) + +type resolveEndpointV2Middleware struct { + options Options +} + +func (*resolveEndpointV2Middleware) ID() string { + return "ResolveEndpointV2" +} + +func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} \ No newline at end of file diff --git a/feature/ec2/imds/request_middleware.go b/feature/ec2/imds/request_middleware.go index c8abd64916c..77ffc05a327 100644 --- a/feature/ec2/imds/request_middleware.go +++ b/feature/ec2/imds/request_middleware.go @@ -17,9 +17,14 @@ import ( func addAPIRequestMiddleware(stack *middleware.Stack, options Options, + operation string, getPath func(interface{}) (string, error), getOutput func(*smithyhttp.Response) (interface{}, error), ) (err error) { + if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil { + return fmt.Errorf("add protocol finalizers: %v", err) + } + err = addRequestMiddleware(stack, options, "GET", getPath, getOutput) if err != nil { return err @@ -283,3 +288,19 @@ func appendURIPath(base, add string) string { } return reqPath } + +func addProtocolFinalizerMiddlewares(stack *middleware.Stack, options Options, operation string) error { + if err := stack.Finalize.Add(&resolveAuthSchemeMiddleware{operation: operation, options: options}, middleware.Before); err != nil { + return fmt.Errorf("add ResolveAuthScheme: %w", err) + } + if err := stack.Finalize.Insert(&getIdentityMiddleware{options: options}, "ResolveAuthScheme", middleware.After); err != nil { + return fmt.Errorf("add GetIdentity: %v", err) + } + if err := stack.Finalize.Insert(&resolveEndpointV2Middleware{options: options}, "GetIdentity", middleware.After); err != nil { + return fmt.Errorf("add ResolveEndpointV2: %v", err) + } + if err := stack.Finalize.Insert(&signRequestMiddleware{}, "ResolveEndpointV2", middleware.After); err != nil { + return fmt.Errorf("add Signing: %w", err) + } + return nil +} \ No newline at end of file From 8b40b4d1a1511a7a13c63efc7f15692a3db299c8 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 2 Jan 2024 14:09:37 -0800 Subject: [PATCH 12/23] fix minor issues --- service/internal/checksum/middleware_add.go | 3 +-- .../checksum/middleware_compute_input_checksum.go | 5 ++--- service/internal/integrationtest/s3/checksum_test.go | 12 ++++-------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/service/internal/checksum/middleware_add.go b/service/internal/checksum/middleware_add.go index 4b17bb3d5e3..1b727acbe17 100644 --- a/service/internal/checksum/middleware_add.go +++ b/service/internal/checksum/middleware_add.go @@ -98,8 +98,7 @@ func AddInputMiddleware(stack *middleware.Stack, options InputMiddlewareOptions) EnableComputePayloadHash: inputChecksum.EnableComputePayloadHash, EnableDecodedContentLengthHeader: inputChecksum.EnableDecodedContentLengthHeader, } - err = stack.Finalize.Insert(trailerMiddleware, "Retry", middleware.After) - if err != nil { + if err := stack.Finalize.Insert(trailerMiddleware, "Retry", middleware.After); err != nil { return err } } diff --git a/service/internal/checksum/middleware_compute_input_checksum.go b/service/internal/checksum/middleware_compute_input_checksum.go index a8bcd7cb28d..7ffca33f0ef 100644 --- a/service/internal/checksum/middleware_compute_input_checksum.go +++ b/service/internal/checksum/middleware_compute_input_checksum.go @@ -181,7 +181,7 @@ func (m *computeInputPayloadChecksum) HandleFinalize( ctx = v4.SetPayloadHash(ctx, streamingUnsignedPayloadTrailerPayloadHash) } m.useTrailer = true - ctx = context.WithValue(ctx, useTrailer{}, true) + ctx = middleware.WithStackValue(ctx, useTrailer{}, true) return next.HandleFinalize(ctx, in) } @@ -264,8 +264,7 @@ func (m *addInputChecksumTrailer) HandleFinalize( ) ( out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { - v, ok := ctx.Value(useTrailer{}).(bool) - if !ok || !v { + if enabled, _ := middleware.GetStackValue(ctx, useTrailer{}).(bool); !enabled { return next.HandleFinalize(ctx, in) } req, ok := in.Request.(*smithyhttp.Request) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index aa21c74d85f..31f16058913 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -19,11 +19,8 @@ import ( "testing" ) -var ( - isInitialCall = true -) - type retryClient struct { + isRetriedCall bool baseClient aws.HTTPClient } @@ -40,8 +37,8 @@ func (m mockConnectionError) Unwrap() error { } func (c *retryClient) Do(req *http.Request) (*http.Response, error) { - if isInitialCall { - isInitialCall = false + if !c.isRetriedCall { + c.isRetriedCall = true return nil, mockConnectionError{} } return c.baseClient.Do(req) @@ -375,9 +372,8 @@ func TestInteg_ObjectChecksums(t *testing.T) { if c.retry { opts := s3client.Options() - baseClient := opts.HTTPClient opts.HTTPClient = &retryClient{ - baseClient: baseClient, + baseClient: opts.HTTPClient, } s3client = s3.New(opts) } From 4ae572140dfc7019e3f462d2908e61cde7506dec Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 2 Jan 2024 14:54:53 -0800 Subject: [PATCH 13/23] add noop sra auth middlewares to endpointscreds credsprovider --- .../endpointcreds/internal/client/auth.go | 49 +++++++++++++++++++ .../endpointcreds/internal/client/client.go | 1 + .../internal/client/endpoints.go | 20 ++++++++ .../internal/client/middleware.go | 16 ++++++ 4 files changed, 86 insertions(+) create mode 100644 credentials/endpointcreds/internal/client/auth.go create mode 100644 credentials/endpointcreds/internal/client/endpoints.go diff --git a/credentials/endpointcreds/internal/client/auth.go b/credentials/endpointcreds/internal/client/auth.go new file mode 100644 index 00000000000..db9ea88dd53 --- /dev/null +++ b/credentials/endpointcreds/internal/client/auth.go @@ -0,0 +1,49 @@ +package client + +import ( + "context" + "github.com/aws/smithy-go/middleware" +) + +type getIdentityMiddleware struct { + options Options +} + +func (*getIdentityMiddleware) ID() string { + return "GetIdentity" +} + +func (m *getIdentityMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} + +type signRequestMiddleware struct { +} + +func (*signRequestMiddleware) ID() string { + return "Signing" +} + + +func (m *signRequestMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} + +type resolveAuthSchemeMiddleware struct { + operation string + options Options +} + +func (*resolveAuthSchemeMiddleware) ID() string { + return "ResolveAuthScheme" +} + +func (m *resolveAuthSchemeMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} \ No newline at end of file diff --git a/credentials/endpointcreds/internal/client/client.go b/credentials/endpointcreds/internal/client/client.go index df0e7575c44..9a869f89547 100644 --- a/credentials/endpointcreds/internal/client/client.go +++ b/credentials/endpointcreds/internal/client/client.go @@ -101,6 +101,7 @@ func (c *Client) GetCredentials(ctx context.Context, params *GetCredentialsInput stack.Serialize.Add(&serializeOpGetCredential{}, smithymiddleware.After) stack.Build.Add(&buildEndpoint{Endpoint: options.Endpoint}, smithymiddleware.After) stack.Deserialize.Add(&deserializeOpGetCredential{}, smithymiddleware.After) + addProtocolFinalizerMiddlewares(stack, options, "GetCredentials") retry.AddRetryMiddlewares(stack, retry.AddRetryMiddlewaresOptions{Retryer: options.Retryer}) middleware.AddSDKAgentKey(middleware.FeatureMetadata, ServiceID) smithyhttp.AddErrorCloseResponseBodyMiddleware(stack) diff --git a/credentials/endpointcreds/internal/client/endpoints.go b/credentials/endpointcreds/internal/client/endpoints.go new file mode 100644 index 00000000000..05a8fd7011e --- /dev/null +++ b/credentials/endpointcreds/internal/client/endpoints.go @@ -0,0 +1,20 @@ +package client + +import ( + "context" + "github.com/aws/smithy-go/middleware" +) + +type resolveEndpointV2Middleware struct { + options Options +} + +func (*resolveEndpointV2Middleware) ID() string { + return "ResolveEndpointV2" +} + +func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( + out middleware.FinalizeOutput, metadata middleware.Metadata, err error, +) { + return next.HandleFinalize(ctx, in) +} \ No newline at end of file diff --git a/credentials/endpointcreds/internal/client/middleware.go b/credentials/endpointcreds/internal/client/middleware.go index ddb28a66d1c..4a3c9c1d595 100644 --- a/credentials/endpointcreds/internal/client/middleware.go +++ b/credentials/endpointcreds/internal/client/middleware.go @@ -146,3 +146,19 @@ func stof(code int) smithy.ErrorFault { } return smithy.FaultClient } + +func addProtocolFinalizerMiddlewares(stack *smithymiddleware.Stack, options Options, operation string) error { + if err := stack.Finalize.Add(&resolveAuthSchemeMiddleware{operation: operation, options: options}, smithymiddleware.Before); err != nil { + return fmt.Errorf("add ResolveAuthScheme: %w", err) + } + if err := stack.Finalize.Insert(&getIdentityMiddleware{options: options}, "ResolveAuthScheme", smithymiddleware.After); err != nil { + return fmt.Errorf("add GetIdentity: %v", err) + } + if err := stack.Finalize.Insert(&resolveEndpointV2Middleware{options: options}, "GetIdentity", smithymiddleware.After); err != nil { + return fmt.Errorf("add ResolveEndpointV2: %v", err) + } + if err := stack.Finalize.Insert(&signRequestMiddleware{}, "ResolveEndpointV2", smithymiddleware.After); err != nil { + return fmt.Errorf("add Signing: %w", err) + } + return nil +} From 59ad5e3918b7ac215dae91f5df95d11bf0647bd9 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 2 Jan 2024 15:03:25 -0800 Subject: [PATCH 14/23] fix imds unit tests --- feature/ec2/imds/request_middleware_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feature/ec2/imds/request_middleware_test.go b/feature/ec2/imds/request_middleware_test.go index 53fd8b6ed73..9c5ea2740f9 100644 --- a/feature/ec2/imds/request_middleware_test.go +++ b/feature/ec2/imds/request_middleware_test.go @@ -33,6 +33,7 @@ func TestAddRequestMiddleware(t *testing.T) { "api request": { AddMiddleware: func(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, + "TestRequest" func(interface{}) (string, error) { return "/mockPath", nil }, @@ -590,6 +591,7 @@ func TestRequestGetToken(t *testing.T) { func(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, client.options.Copy(), + "TestRequest" func(interface{}) (string, error) { return "/latest/foo", nil }, From be6440cd0c94fac4281cc2c75494f975e59bcd70 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 2 Jan 2024 15:39:13 -0800 Subject: [PATCH 15/23] fix imds unit tests --- feature/ec2/imds/api_op_GetToken.go | 1 + feature/ec2/imds/request_middleware.go | 11 ++++++----- feature/ec2/imds/request_middleware_test.go | 14 +++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/feature/ec2/imds/api_op_GetToken.go b/feature/ec2/imds/api_op_GetToken.go index 841f802c1a3..1f9ee97a5b7 100644 --- a/feature/ec2/imds/api_op_GetToken.go +++ b/feature/ec2/imds/api_op_GetToken.go @@ -49,6 +49,7 @@ func addGetTokenMiddleware(stack *middleware.Stack, options Options) error { err := addRequestMiddleware(stack, options, "PUT", + "GetToken", buildGetTokenPath, buildGetTokenOutput) if err != nil { diff --git a/feature/ec2/imds/request_middleware.go b/feature/ec2/imds/request_middleware.go index 77ffc05a327..322578afdfe 100644 --- a/feature/ec2/imds/request_middleware.go +++ b/feature/ec2/imds/request_middleware.go @@ -21,11 +21,7 @@ func addAPIRequestMiddleware(stack *middleware.Stack, getPath func(interface{}) (string, error), getOutput func(*smithyhttp.Response) (interface{}, error), ) (err error) { - if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil { - return fmt.Errorf("add protocol finalizers: %v", err) - } - - err = addRequestMiddleware(stack, options, "GET", getPath, getOutput) + err = addRequestMiddleware(stack, options, "GET", operation, getPath, getOutput) if err != nil { return err } @@ -49,6 +45,7 @@ func addAPIRequestMiddleware(stack *middleware.Stack, func addRequestMiddleware(stack *middleware.Stack, options Options, method string, + operation string, getPath func(interface{}) (string, error), getOutput func(*smithyhttp.Response) (interface{}, error), ) (err error) { @@ -106,6 +103,10 @@ func addRequestMiddleware(stack *middleware.Stack, return err } + if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil { + return fmt.Errorf("add protocol finalizers: %v", err) + } + // Retry support return retry.AddRetryMiddlewares(stack, retry.AddRetryMiddlewaresOptions{ Retryer: options.Retryer, diff --git a/feature/ec2/imds/request_middleware_test.go b/feature/ec2/imds/request_middleware_test.go index 9c5ea2740f9..04f00f44e64 100644 --- a/feature/ec2/imds/request_middleware_test.go +++ b/feature/ec2/imds/request_middleware_test.go @@ -33,7 +33,7 @@ func TestAddRequestMiddleware(t *testing.T) { "api request": { AddMiddleware: func(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, options, - "TestRequest" + "TestRequest", func(interface{}) (string, error) { return "/mockPath", nil }, @@ -54,9 +54,13 @@ func TestAddRequestMiddleware(t *testing.T) { "UserAgent", }, ExpectFinalize: []string{ + "ResolveAuthScheme", + "GetIdentity", + "ResolveEndpointV2", "Retry", "APITokenProvider", "RetryMetricsHeader", + "Signing", }, ExpectDeserialize: []string{ "APITokenProvider", @@ -67,7 +71,7 @@ func TestAddRequestMiddleware(t *testing.T) { "base request": { AddMiddleware: func(stack *middleware.Stack, options Options) error { - return addRequestMiddleware(stack, options, "POST", + return addRequestMiddleware(stack, options, "POST", "TestRequest", func(interface{}) (string, error) { return "/mockPath", nil }, @@ -88,8 +92,12 @@ func TestAddRequestMiddleware(t *testing.T) { "UserAgent", }, ExpectFinalize: []string{ + "ResolveAuthScheme", + "GetIdentity", + "ResolveEndpointV2", "Retry", "RetryMetricsHeader", + "Signing", }, ExpectDeserialize: []string{ "OperationDeserializer", @@ -591,7 +599,7 @@ func TestRequestGetToken(t *testing.T) { func(stack *middleware.Stack, options Options) error { return addAPIRequestMiddleware(stack, client.options.Copy(), - "TestRequest" + "TestRequest", func(interface{}) (string, error) { return "/latest/foo", nil }, From 8474f646b20a712b0b7917d94b4d5659787370da Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 2 Jan 2024 15:46:33 -0800 Subject: [PATCH 16/23] run make format on whole repos --- credentials/endpointcreds/internal/client/auth.go | 3 +-- credentials/endpointcreds/internal/client/endpoints.go | 2 +- feature/ec2/imds/api_op_GetMetadata.go | 2 +- feature/ec2/imds/auth.go | 3 +-- feature/ec2/imds/endpoints.go | 2 +- feature/ec2/imds/request_middleware.go | 2 +- service/internal/integrationtest/s3/checksum_test.go | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/credentials/endpointcreds/internal/client/auth.go b/credentials/endpointcreds/internal/client/auth.go index db9ea88dd53..c3f5dadcec9 100644 --- a/credentials/endpointcreds/internal/client/auth.go +++ b/credentials/endpointcreds/internal/client/auth.go @@ -26,7 +26,6 @@ func (*signRequestMiddleware) ID() string { return "Signing" } - func (m *signRequestMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { @@ -46,4 +45,4 @@ func (m *resolveAuthSchemeMiddleware) HandleFinalize(ctx context.Context, in mid out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { return next.HandleFinalize(ctx, in) -} \ No newline at end of file +} diff --git a/credentials/endpointcreds/internal/client/endpoints.go b/credentials/endpointcreds/internal/client/endpoints.go index 05a8fd7011e..748ee67244e 100644 --- a/credentials/endpointcreds/internal/client/endpoints.go +++ b/credentials/endpointcreds/internal/client/endpoints.go @@ -17,4 +17,4 @@ func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in mid out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { return next.HandleFinalize(ctx, in) -} \ No newline at end of file +} diff --git a/feature/ec2/imds/api_op_GetMetadata.go b/feature/ec2/imds/api_op_GetMetadata.go index 4fec055da12..869bfc9feb9 100644 --- a/feature/ec2/imds/api_op_GetMetadata.go +++ b/feature/ec2/imds/api_op_GetMetadata.go @@ -58,7 +58,7 @@ func addGetMetadataMiddleware(stack *middleware.Stack, options Options) error { options, "GetMetadata", buildGetMetadataPath, - buildGetMetadataOutput,) + buildGetMetadataOutput) } func buildGetMetadataPath(params interface{}) (string, error) { diff --git a/feature/ec2/imds/auth.go b/feature/ec2/imds/auth.go index fa982fc8d61..ad283cf825f 100644 --- a/feature/ec2/imds/auth.go +++ b/feature/ec2/imds/auth.go @@ -26,7 +26,6 @@ func (*signRequestMiddleware) ID() string { return "Signing" } - func (m *signRequestMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { @@ -46,4 +45,4 @@ func (m *resolveAuthSchemeMiddleware) HandleFinalize(ctx context.Context, in mid out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { return next.HandleFinalize(ctx, in) -} \ No newline at end of file +} diff --git a/feature/ec2/imds/endpoints.go b/feature/ec2/imds/endpoints.go index e9446025594..d7540da3481 100644 --- a/feature/ec2/imds/endpoints.go +++ b/feature/ec2/imds/endpoints.go @@ -17,4 +17,4 @@ func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in mid out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { return next.HandleFinalize(ctx, in) -} \ No newline at end of file +} diff --git a/feature/ec2/imds/request_middleware.go b/feature/ec2/imds/request_middleware.go index 322578afdfe..6d599b49de9 100644 --- a/feature/ec2/imds/request_middleware.go +++ b/feature/ec2/imds/request_middleware.go @@ -304,4 +304,4 @@ func addProtocolFinalizerMiddlewares(stack *middleware.Stack, options Options, o return fmt.Errorf("add Signing: %w", err) } return nil -} \ No newline at end of file +} diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index 31f16058913..8ffd08d1544 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -21,7 +21,7 @@ import ( type retryClient struct { isRetriedCall bool - baseClient aws.HTTPClient + baseClient aws.HTTPClient } type mockConnectionError struct{ err error } From 8bf8242dd5add9c0d9fa035e705ed4f9c685dbd6 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 3 Jan 2024 08:03:46 -0800 Subject: [PATCH 17/23] regen everything --- service/docdb/api_client.go | 6 ++++++ service/ec2/api_client.go | 6 ++++++ service/neptune/api_client.go | 6 ++++++ service/polly/api_client.go | 6 ++++++ service/rds/api_client.go | 6 ++++++ service/sts/api_client.go | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/service/docdb/api_client.go b/service/docdb/api_client.go index b7f8b686a03..72e8e156e3a 100644 --- a/service/docdb/api_client.go +++ b/service/docdb/api_client.go @@ -552,6 +552,12 @@ func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, op if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) } + if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { + stack.Finalize.Remove((*retry.Attempt)(nil).ID()) + } + if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { + stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) + } stack.Deserialize.Clear() stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) stack.Build.Remove("UserAgent") diff --git a/service/ec2/api_client.go b/service/ec2/api_client.go index d8456843cab..84365b955b0 100644 --- a/service/ec2/api_client.go +++ b/service/ec2/api_client.go @@ -568,6 +568,12 @@ func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, op if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) } + if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { + stack.Finalize.Remove((*retry.Attempt)(nil).ID()) + } + if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { + stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) + } stack.Deserialize.Clear() stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) stack.Build.Remove("UserAgent") diff --git a/service/neptune/api_client.go b/service/neptune/api_client.go index 37c3747798d..a56c87a9fac 100644 --- a/service/neptune/api_client.go +++ b/service/neptune/api_client.go @@ -551,6 +551,12 @@ func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, op if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) } + if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { + stack.Finalize.Remove((*retry.Attempt)(nil).ID()) + } + if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { + stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) + } stack.Deserialize.Clear() stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) stack.Build.Remove("UserAgent") diff --git a/service/polly/api_client.go b/service/polly/api_client.go index 24a8dbf0742..f86584d8794 100644 --- a/service/polly/api_client.go +++ b/service/polly/api_client.go @@ -551,6 +551,12 @@ func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, op if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) } + if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { + stack.Finalize.Remove((*retry.Attempt)(nil).ID()) + } + if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { + stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) + } stack.Deserialize.Clear() stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) stack.Build.Remove("UserAgent") diff --git a/service/rds/api_client.go b/service/rds/api_client.go index 4ceb38aabe6..55dd540d55f 100644 --- a/service/rds/api_client.go +++ b/service/rds/api_client.go @@ -552,6 +552,12 @@ func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, op if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) } + if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { + stack.Finalize.Remove((*retry.Attempt)(nil).ID()) + } + if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { + stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) + } stack.Deserialize.Clear() stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) stack.Build.Remove("UserAgent") diff --git a/service/sts/api_client.go b/service/sts/api_client.go index 59cc4c70a38..369de83b8bc 100644 --- a/service/sts/api_client.go +++ b/service/sts/api_client.go @@ -552,6 +552,12 @@ func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, op if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) } + if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { + stack.Finalize.Remove((*retry.Attempt)(nil).ID()) + } + if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { + stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) + } stack.Deserialize.Clear() stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) stack.Build.Remove("UserAgent") From c5d52f6beea571d0789391ea5e4b01b5d2aa0986 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 3 Jan 2024 08:56:47 -0800 Subject: [PATCH 18/23] change formatting to unwrap --- credentials/endpointcreds/internal/client/middleware.go | 4 ++-- feature/ec2/imds/request_middleware.go | 6 +++--- service/internal/integrationtest/s3/checksum_test.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/credentials/endpointcreds/internal/client/middleware.go b/credentials/endpointcreds/internal/client/middleware.go index 4a3c9c1d595..f2820d20eac 100644 --- a/credentials/endpointcreds/internal/client/middleware.go +++ b/credentials/endpointcreds/internal/client/middleware.go @@ -152,10 +152,10 @@ func addProtocolFinalizerMiddlewares(stack *smithymiddleware.Stack, options Opti return fmt.Errorf("add ResolveAuthScheme: %w", err) } if err := stack.Finalize.Insert(&getIdentityMiddleware{options: options}, "ResolveAuthScheme", smithymiddleware.After); err != nil { - return fmt.Errorf("add GetIdentity: %v", err) + return fmt.Errorf("add GetIdentity: %w", err) } if err := stack.Finalize.Insert(&resolveEndpointV2Middleware{options: options}, "GetIdentity", smithymiddleware.After); err != nil { - return fmt.Errorf("add ResolveEndpointV2: %v", err) + return fmt.Errorf("add ResolveEndpointV2: %w", err) } if err := stack.Finalize.Insert(&signRequestMiddleware{}, "ResolveEndpointV2", smithymiddleware.After); err != nil { return fmt.Errorf("add Signing: %w", err) diff --git a/feature/ec2/imds/request_middleware.go b/feature/ec2/imds/request_middleware.go index 6d599b49de9..fc948c27d89 100644 --- a/feature/ec2/imds/request_middleware.go +++ b/feature/ec2/imds/request_middleware.go @@ -104,7 +104,7 @@ func addRequestMiddleware(stack *middleware.Stack, } if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil { - return fmt.Errorf("add protocol finalizers: %v", err) + return fmt.Errorf("add protocol finalizers: %w", err) } // Retry support @@ -295,10 +295,10 @@ func addProtocolFinalizerMiddlewares(stack *middleware.Stack, options Options, o return fmt.Errorf("add ResolveAuthScheme: %w", err) } if err := stack.Finalize.Insert(&getIdentityMiddleware{options: options}, "ResolveAuthScheme", middleware.After); err != nil { - return fmt.Errorf("add GetIdentity: %v", err) + return fmt.Errorf("add GetIdentity: %w", err) } if err := stack.Finalize.Insert(&resolveEndpointV2Middleware{options: options}, "GetIdentity", middleware.After); err != nil { - return fmt.Errorf("add ResolveEndpointV2: %v", err) + return fmt.Errorf("add ResolveEndpointV2: %w", err) } if err := stack.Finalize.Insert(&signRequestMiddleware{}, "ResolveEndpointV2", middleware.After); err != nil { return fmt.Errorf("add Signing: %w", err) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index 8ffd08d1544..a6191dbd6c9 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -30,7 +30,7 @@ func (m mockConnectionError) ConnectionError() bool { return true } func (m mockConnectionError) Error() string { - return fmt.Sprintf("request error: %v", m.err) + return fmt.Sprintf("request error: %w", m.err) } func (m mockConnectionError) Unwrap() error { return m.err From be4660791743298fd5074c838539b10a73cafc44 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 3 Jan 2024 09:10:34 -0800 Subject: [PATCH 19/23] change back sprintf to not unwrap because not supported --- service/internal/integrationtest/s3/checksum_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index a6191dbd6c9..8ffd08d1544 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -30,7 +30,7 @@ func (m mockConnectionError) ConnectionError() bool { return true } func (m mockConnectionError) Error() string { - return fmt.Sprintf("request error: %w", m.err) + return fmt.Sprintf("request error: %v", m.err) } func (m mockConnectionError) Unwrap() error { return m.err From 2b02a90f8e5c0d0f14dfeb90aafc128abc2f6b4c Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 3 Jan 2024 09:21:46 -0800 Subject: [PATCH 20/23] change to unwrap and change the formatting func, because its better --- service/internal/integrationtest/s3/checksum_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index 8ffd08d1544..2339af0d7e3 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -30,7 +30,7 @@ func (m mockConnectionError) ConnectionError() bool { return true } func (m mockConnectionError) Error() string { - return fmt.Sprintf("request error: %v", m.err) + return fmt.Printf("request error: %w", m.err) } func (m mockConnectionError) Unwrap() error { return m.err From 10d07e7f63061172cd71ca0d8edd7043dcecacb5 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 3 Jan 2024 10:08:30 -0800 Subject: [PATCH 21/23] fixed wrong function --- service/internal/integrationtest/s3/checksum_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index 2339af0d7e3..dd75bca6f4e 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -30,7 +30,7 @@ func (m mockConnectionError) ConnectionError() bool { return true } func (m mockConnectionError) Error() string { - return fmt.Printf("request error: %w", m.err) + return fmt.Errorf("request error: %w", m.err) } func (m mockConnectionError) Unwrap() error { return m.err From e5e486ded28f1ed8c370ede752d9e700c171d1b6 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 3 Jan 2024 10:22:24 -0800 Subject: [PATCH 22/23] fix error func return type --- service/internal/integrationtest/s3/checksum_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index dd75bca6f4e..a5d15d9b2cb 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -29,7 +29,7 @@ type mockConnectionError struct{ err error } func (m mockConnectionError) ConnectionError() bool { return true } -func (m mockConnectionError) Error() string { +func (m mockConnectionError) Error() error { return fmt.Errorf("request error: %w", m.err) } func (m mockConnectionError) Unwrap() error { From 133a52fd36af8af62b959af90d825e01692cbbd6 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 3 Jan 2024 10:35:12 -0800 Subject: [PATCH 23/23] error func has to return a string, so this usage cannot use unwrapping --- service/internal/integrationtest/s3/checksum_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index a5d15d9b2cb..8ffd08d1544 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -29,8 +29,8 @@ type mockConnectionError struct{ err error } func (m mockConnectionError) ConnectionError() bool { return true } -func (m mockConnectionError) Error() error { - return fmt.Errorf("request error: %w", m.err) +func (m mockConnectionError) Error() string { + return fmt.Sprintf("request error: %v", m.err) } func (m mockConnectionError) Unwrap() error { return m.err