Skip to content

Commit

Permalink
service/s3control/internal/customization: Remove dual-stack endpoint …
Browse files Browse the repository at this point in the history
…customization
  • Loading branch information
skmcgrail committed May 25, 2021
1 parent 361b6eb commit 1c66ddf
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 29 deletions.
21 changes: 10 additions & 11 deletions service/s3control/internal/customizations/update_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ type UpdateEndpointOptions struct {
EndpointResolverOptions EndpointResolverOptions
}

// IsUseDualStack returns whether dual-stack endpoint resolution is enabled
func (o UpdateEndpointOptions) IsUseDualStack() bool {
if o.EndpointResolverOptions.UseDualStack != internalendpoints.UnsetDualStackEndpoint {
return o.EndpointResolverOptions.UseDualStack == internalendpoints.EnableDualStackEndpoint
}
return o.UseDualstack
}

// UpdateEndpoint adds the middleware to the middleware stack based on the UpdateEndpointOptions.
func UpdateEndpoint(stack *middleware.Stack, options UpdateEndpointOptions) (err error) {
// validate and backfill account id from ARN
Expand All @@ -82,7 +90,7 @@ func UpdateEndpoint(stack *middleware.Stack, options UpdateEndpointOptions) (err
CopyInput: options.Accessor.CopyInput,
UpdateARNField: options.Accessor.UpdateARNField,
UseARNRegion: options.UseARNRegion,
UseDualstack: options.UseDualstack,
UseDualstack: options.IsUseDualStack(),
EndpointResolver: options.EndpointResolver,
EndpointResolverOptions: options.EndpointResolverOptions,
}, "OperationSerializer", middleware.Before)
Expand All @@ -93,19 +101,10 @@ func UpdateEndpoint(stack *middleware.Stack, options UpdateEndpointOptions) (err
// outpostID middleware
err = stack.Serialize.Insert(&processOutpostIDMiddleware{
GetOutpostID: options.Accessor.GetOutpostIDInput,
UseDualstack: options.UseDualstack,
UseDualstack: options.IsUseDualStack(),
}, (*processARNResource)(nil).ID(), middleware.Before)
if err != nil {
return err
}

// enable dual stack support
err = stack.Serialize.Insert(&s3shared.EnableDualstack{
UseDualstack: options.UseDualstack,
DefaultServiceID: "s3-control",
}, "OperationSerializer", middleware.After)
if err != nil {
return err
}
return err
}
90 changes: 72 additions & 18 deletions service/s3control/internal/customizations/update_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (
"strings"
"testing"

"github.com/aws/smithy-go/ptr"

"github.com/aws/aws-sdk-go-v2/aws"
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
"github.com/aws/aws-sdk-go-v2/internal/awstesting/unit"
"github.com/aws/aws-sdk-go-v2/service/s3control"

"github.com/aws/smithy-go/middleware"
"github.com/aws/smithy-go/ptr"
smithyhttp "github.com/aws/smithy-go/transport/http"
)

Expand Down Expand Up @@ -42,9 +40,9 @@ func TestUpdateEndpointBuild(t *testing.T) {
"DualStack": {
useDualstack: true,
tests: []s3controlEndpointTest{
{"abc", "123456789012", "https://123456789012.s3-control.dualstack.mock-region.amazonaws.com/v20180820/bucket/abc", ""},
{"a.b.c", "123456789012", "https://123456789012.s3-control.dualstack.mock-region.amazonaws.com/v20180820/bucket/a.b.c", ""},
{"a$b$c", "123456789012", "https://123456789012.s3-control.dualstack.mock-region.amazonaws.com/v20180820/bucket/a%24b%24c", ""},
{"abc", "123456789012", "https://123456789012.s3-control.dualstack.mock-region.aws/v20180820/bucket/abc", ""},
{"a.b.c", "123456789012", "https://123456789012.s3-control.dualstack.mock-region.aws/v20180820/bucket/a.b.c", ""},
{"a$b$c", "123456789012", "https://123456789012.s3-control.dualstack.mock-region.aws/v20180820/bucket/a%24b%24c", ""},
},
},
},
Expand All @@ -61,18 +59,6 @@ func TestUpdateEndpointBuild(t *testing.T) {
{"a$b$c", "123456789012", "https://example.region.amazonaws.com/v20180820/bucket/a%24b%24c", ""},
},
},
"DualStack": {
useDualstack: true,
customEndpoint: &aws.Endpoint{
URL: "https://example.region.amazonaws.com",
HostnameImmutable: true,
},
tests: []s3controlEndpointTest{
{"abc", "123456789012", "https://example.region.amazonaws.com/v20180820/bucket/abc", ""},
{"a.b.c", "123456789012", "https://example.region.amazonaws.com/v20180820/bucket/a.b.c", ""},
{"a$b$c", "123456789012", "https://example.region.amazonaws.com/v20180820/bucket/a%24b%24c", ""},
},
},
},
}

Expand Down Expand Up @@ -825,6 +811,74 @@ func TestInputIsNotModified(t *testing.T) {
}
}

func TestUseDualStackClientBehavior(t *testing.T) {
cases := map[string]testCaseForEndpointCustomization{
"client options dual-stack false, endpoint resolver dual-stack unset": {
options: s3control.Options{
Region: "us-west-2",
UseDualstack: false,
},
expectedReqURL: "https://012345678901.s3-control.us-west-2.amazonaws.com/v20180820/bucket/test-bucket",
expectedSigningRegion: "us-west-2",
expectedSigningName: "s3",
},
"client options dual-stack true, endpoint resolver dual-stack unset": {
options: s3control.Options{
Region: "us-west-2",
UseDualstack: true,
},
expectedReqURL: "https://012345678901.s3-control.dualstack.us-west-2.amazonaws.com/v20180820/bucket/test-bucket",
expectedSigningRegion: "us-west-2",
expectedSigningName: "s3",
},
"client options dual-stack off, endpoint resolver dual-stack disabled": {
options: s3control.Options{
Region: "us-west-2",
EndpointOptions: s3control.EndpointResolverOptions{
UseDualStack: s3control.DisableDualStackEndpoint,
},
},
expectedReqURL: "https://012345678901.s3-control.us-west-2.amazonaws.com/v20180820/bucket/test-bucket",
expectedSigningRegion: "us-west-2",
expectedSigningName: "s3",
},
"client options dual-stack off, endpoint resolver dual-stack enabled": {
options: s3control.Options{
Region: "us-west-2",
EndpointOptions: s3control.EndpointResolverOptions{
UseDualStack: s3control.EnableDualStackEndpoint,
},
},
expectedReqURL: "https://012345678901.s3-control.dualstack.us-west-2.amazonaws.com/v20180820/bucket/test-bucket",
expectedSigningRegion: "us-west-2",
expectedSigningName: "s3",
},
"client options dual-stack on, endpoint resolver dual-stack disabled": {
options: s3control.Options{
Region: "us-west-2",
UseDualstack: true,
EndpointOptions: s3control.EndpointResolverOptions{
UseDualStack: s3control.DisableDualStackEndpoint,
},
},
expectedReqURL: "https://012345678901.s3-control.us-west-2.amazonaws.com/v20180820/bucket/test-bucket",
expectedSigningRegion: "us-west-2",
expectedSigningName: "s3",
},
}
for name, tt := range cases {
t.Run(name, func(t *testing.T) {
tt.operation = func(ctx context.Context, client *s3control.Client, retrieverMiddleware *requestRetrieverMiddleware) (interface{}, error) {
return client.GetBucket(ctx, &s3control.GetBucketInput{
AccountId: aws.String("012345678901"),
Bucket: aws.String("test-bucket"),
}, addRequestRetriever(retrieverMiddleware))
}
runValidations(t, tt)
})
}
}

func (*requestRetrieverMiddleware) ID() string { return "S3:requestRetrieverMiddleware" }

func (rm *requestRetrieverMiddleware) HandleSerialize(
Expand Down

0 comments on commit 1c66ddf

Please sign in to comment.