Skip to content

Commit

Permalink
feedback and doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
skotambkar committed Oct 21, 2020
1 parent db7821d commit a06a201
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import software.amazon.smithy.go.codegen.GoDelegator;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.SmithyGoDependency;
import software.amazon.smithy.go.codegen.SymbolUtils;
import software.amazon.smithy.go.codegen.integration.ConfigField;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
Expand Down Expand Up @@ -148,6 +149,10 @@ private void writeInputGetter(GoWriter writer, Model model, SymbolProvider symbo
}

private void writeS3ControlMiddlewareHelper(GoWriter writer) {
// imports
writer.addUseImports(SmithyGoDependency.SMITHY_MIDDLEWARE);
writer.addUseImports(AwsCustomGoDependency.S3CONTROL_CUSTOMIZATION);

writer.openBlock("func $L(stack *middleware.Stack, options Options) {", "}", UPDATE_ENDPOINT_ADDER, () -> {
writer.write("$T(stack, $T{UseDualstack: options.$L})",
SymbolUtils.createValueSymbolBuilder(UPDATE_ENDPOINT_INTERNAL_ADDER,
Expand All @@ -160,6 +165,10 @@ private void writeS3ControlMiddlewareHelper(GoWriter writer) {
}

private void writeS3MiddlewareHelper(GoWriter writer) {
// imports
writer.addUseImports(SmithyGoDependency.SMITHY_MIDDLEWARE);
writer.addUseImports(AwsCustomGoDependency.S3_CUSTOMIZATION);

writer.openBlock("func $L(stack *middleware.Stack, options Options) {", "}", UPDATE_ENDPOINT_ADDER, () -> {
writer.write("$T(stack, $T{ \n"
+ "Region: options.Region,\n GetBucketFromInput: $L,\n UsePathStyle: options.$L,\n "
Expand Down Expand Up @@ -219,7 +228,7 @@ public List<RuntimeClientPlugin> getClientPlugins() {
.type(SymbolUtils.createValueSymbolBuilder("bool")
.putProperty(SymbolUtils.GO_UNIVERSE_TYPE, true)
.build())
.documentation("")
.documentation("Allows you to enable Dualstack endpoint support for the service.")
.build()
))
.registerMiddleware(MiddlewareRegistrar.builder()
Expand Down
35 changes: 26 additions & 9 deletions service/s3/internal/customizations/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Package customizations provides customizations for the Amazon S3 API client.
This package provides support for following S3 customizations
UpdateEndpoint Middleware: Virtual Host style url addressing
UpdateEndpoint Middleware: resolves a custom endpoint as per s3 config options
processResponseWith200Error Middleware: Deserializing response error with 200 status code
Expand All @@ -12,17 +12,34 @@ Virtual Host style url addressing
Since serializers serialize by default as path style url, we use customization
to modify the endpoint url when `UsePathStyle` option on S3Client is unset or
false.
false. This flag will be ignored if `UseAccelerate` option is set to true.
UpdateEndpoint middleware handler for virtual host url addressing needs to be
Transfer acceleration
By default S3 Transfer acceleration support is disabled. By enabling `UseAccelerate`
option on S3Client, one can enable s3 transfer acceleration support. Transfer
acceleration only works with Virtual Host style addressing, and thus `UsePathStyle`
option if set is ignored. Transfer acceleration is not supported for S3 operations
DeleteBucket, ListBuckets, and CreateBucket.
Dualstack support
By default dualstack support for s3 client is disabled. By enabling `UseDualstack`
option on s3 client, you can enable dualstack endpoint support.
UpdateEndpoint middleware handler for modifying resolved endpoint needs to be
executed after request serialization.
Middleware layering:
Middleware layering:
HTTP Request -> operation serializer -> Update-Endpoint customization -> next middleware
HTTP Request -> operation serializer -> Update-Endpoint customization -> next middleware
Customization option:
UsePathStyle (Disabled by Default)
Customization options:
UsePathStyle (Disabled by Default)
UseAccelerate (Disabled by Default)
UseDualstack (Disabled by Default)
Handle Error response with 200 status code
Expand All @@ -36,9 +53,9 @@ than response deserialization. Since the behavior of Deserialization is in
reverse order to the other stack steps its easier to consider that "after" means
"before".
Middleware layering:
Middleware layering:
HTTP Response -> handle 200 error customization -> deserialize
HTTP Response -> handle 200 error customization -> deserialize
*/
package customizations
49 changes: 25 additions & 24 deletions service/s3/internal/customizations/update_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,38 +111,39 @@ func (u *updateEndpointMiddleware) HandleSerialize(

func (u updateEndpointMiddleware) updateEndpointFromConfig(req *http.Request, bucket string) error {
// do nothing if path style is enforced
if !u.usePathStyle {
if !hostCompatibleBucketName(req.URL, bucket) {
// bucket name must be valid to put into the host
return fmt.Errorf("bucket name %s is not compatible with S3", bucket)
}
if u.usePathStyle {
return nil
}

// accelerate is only supported if use path style is disabled
if u.useAccelerate {
parts := strings.Split(req.URL.Host, ".")
if len(parts) < 3 {
return fmt.Errorf("unable to update endpoint host for S3 accelerate, hostname invalid, %s", req.URL.Host)
}
if !hostCompatibleBucketName(req.URL, bucket) {
// bucket name must be valid to put into the host
return fmt.Errorf("bucket name %s is not compatible with S3", bucket)
}

if parts[0] == "s3" || strings.HasPrefix(parts[0], "s3-") {
parts[0] = "s3-accelerate"
}
// accelerate is only supported if use path style is disabled
if u.useAccelerate {
parts := strings.Split(req.URL.Host, ".")
if len(parts) < 3 {
return fmt.Errorf("unable to update endpoint host for S3 accelerate, hostname invalid, %s", req.URL.Host)
}

for i := 1; i+1 < len(parts); i++ {
if strings.EqualFold(parts[i], u.region) {
parts = append(parts[:i], parts[i+1:]...)
break
}
}
if parts[0] == "s3" || strings.HasPrefix(parts[0], "s3-") {
parts[0] = "s3-accelerate"
}

// construct the url host
req.URL.Host = strings.Join(parts, ".")
for i := 1; i+1 < len(parts); i++ {
if strings.EqualFold(parts[i], u.region) {
parts = append(parts[:i], parts[i+1:]...)
break
}
}

// move bucket to follow virtual host style
moveBucketNameToHost(req.URL, bucket)
// construct the url host
req.URL.Host = strings.Join(parts, ".")
}

// move bucket to follow virtual host style
moveBucketNameToHost(req.URL, bucket)
return nil
}

Expand Down
26 changes: 26 additions & 0 deletions service/s3control/internal/customizations/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Package customizations provides customizations for the Amazon S3-Control API client.
This package provides support for following S3-Control customizations
UpdateEndpoint Middleware: resolves a custom endpoint as per s3-control config options
Dualstack support
By default dualstack support for s3-control client is disabled. By enabling `UseDualstack`
option on s3-control client, you can enable dualstack endpoint support.
UpdateEndpoint middleware handler for modifying resolved endpoint needs to be
executed after request serialization.
Middleware layering:
HTTP Request -> operation serializer -> Update-Endpoint customization -> next middleware
Customization option:
UseDualstack (Disabled by Default)
*/
package customizations

0 comments on commit a06a201

Please sign in to comment.