From 10bc32de51bd49119e85a98e67152044d625b675 Mon Sep 17 00:00:00 2001 From: skotambkar Date: Wed, 20 Jan 2021 13:41:59 -0800 Subject: [PATCH] codegen endpoint resolver helper functions --- .../aws/go/codegen/AddAwsConfigFields.java | 45 ++++++++++++++----- .../aws/go/codegen/AwsEndpointGenerator.java | 4 +- .../aws/go/codegen/AwsGoDependency.java | 2 +- .../aws/go/codegen/EndpointGenerator.java | 21 +++++++++ .../customization/AwsCustomGoDependency.java | 6 +-- 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java index 5f9ad89858e..21dc7653989 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java @@ -108,17 +108,6 @@ public class AddAwsConfigFields implements GoIntegration { .build() ); - /** - * Gets the sort order of the customization from -128 to 127, with lowest - * executed first. - * - * @return Returns the sort order, defaults to -50. - */ - @Override - public byte getOrder() { - return -50; - } - private static Symbol getAwsCoreSymbol(String symbolName) { return SymbolUtils.createValueSymbolBuilder(symbolName, AwsGoDependency.AWS_CORE).build(); @@ -139,6 +128,17 @@ private static Symbol getAwsRetrySymbol(String symbolName) { AwsGoDependency.AWS_RETRY).build(); } + /** + * Gets the sort order of the customization from -128 to 127, with lowest + * executed first. + * + * @return Returns the sort order, defaults to -50. + */ + @Override + public byte getOrder() { + return -50; + } + @Override public void writeAdditionalFiles( GoSettings settings, @@ -178,7 +178,8 @@ private void writeHttpClientResolver(GoWriter writer) { writer.openBlock("func $L(o *Options) {", "}", RESOLVE_HTTP_CLIENT, () -> { writer.openBlock("if o.$L != nil {", "}", HTTP_CLIENT_CONFIG_NAME, () -> writer.write("return")); writer.write("o.$L = $T()", HTTP_CLIENT_CONFIG_NAME, - SymbolUtils.createValueSymbolBuilder("NewBuildableClient", AwsGoDependency.AWS_HTTP_TRANSPORT).build()); + SymbolUtils.createValueSymbolBuilder("NewBuildableClient", + AwsGoDependency.AWS_HTTP_TRANSPORT).build()); }); writer.write(""); } @@ -305,6 +306,14 @@ private Builder() { super(); } + /** + * This sets the Config field on Client Options structure. By default this is true. + * If set to false, this field won't be generated on the Client options, but will be used by + * the NewFromConfig (to copy values from the aws config to client options). + * + * @param generatedOnClient bool indicating config field generation on client option structure + * @return + */ public Builder generatedOnClient(boolean generatedOnClient) { this.generatedOnClient = generatedOnClient; return this; @@ -347,6 +356,18 @@ public Builder documentation(String documentation) { super.documentation(documentation); return this; } + + @Override + public Builder withHelper(Boolean withHelper) { + super.withHelper(withHelper); + return this; + } + + @Override + public Builder withHelper() { + super.withHelper(); + return this; + } } } } diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointGenerator.java index c321d7405a2..cb9f34531ca 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointGenerator.java @@ -33,6 +33,7 @@ * Generates an endpoint resolver from endpoints.json. */ public final class AwsEndpointGenerator implements GoIntegration { + public static final String ENDPOINT_RESOLVER_CONFIG_NAME = "EndpointResolver"; @Override public void writeAdditionalFiles( @@ -49,10 +50,11 @@ public List getClientPlugins() { return ListUtils.of(RuntimeClientPlugin.builder() .configFields(SetUtils.of( ConfigField.builder() - .name("EndpointResolver") + .name(ENDPOINT_RESOLVER_CONFIG_NAME) .type(SymbolUtils.createValueSymbolBuilder(EndpointGenerator.RESOLVER_INTERFACE_NAME) .build()) .documentation("The service endpoint resolver.") + .withHelper(true) .build(), ConfigField.builder() .name("EndpointOptions") diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java index d2ec14a0b13..994ffd7250a 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java @@ -84,6 +84,6 @@ protected static GoDependency module( } private static final class Versions { - private static final String AWS_SDK = "v0.31.1-0.20210108204630-4822f3195720"; + private static final String AWS_SDK = "v1.0.0"; } } diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java index 91353ce296a..db4e401c552 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/EndpointGenerator.java @@ -53,6 +53,9 @@ public class EndpointGenerator implements Runnable { public static final String CLIENT_CONFIG_RESOLVER = "resolveDefaultEndpointConfiguration"; public static final String RESOLVER_CONSTRUCTOR_NAME = "NewDefaultEndpointResolver"; public static final String AWS_ENDPOINT_RESOLVER_HELPER = "withEndpointResolver"; + private static final String EndpointResolverFromURL = "EndpointResolverFromURL"; + private static final Symbol AWS_ENDPOINT = SymbolUtils.createPointableSymbolBuilder( + "Endpoint", AwsGoDependency.AWS_CORE).build(); private static final int ENDPOINT_MODEL_VERSION = 3; private static final String INTERNAL_ENDPOINT_PACKAGE = "internal/endpoints"; @@ -369,6 +372,24 @@ private void generatePublicResolverTypes(GoWriter writer) { writer.openBlock("if o.EndpointResolver != nil {", "}", () -> writer.write("return")); writer.write("o.EndpointResolver = $L()", RESOLVER_CONSTRUCTOR_NAME); }); + + // Generate EndpointResolverFromURL helper + writer.writeDocs(String.format("%s returns an EndpointResolver configured using the provided endpoint url. " + + "By default, the resolved endpoint resolver uses the client region as signing region. " + + "You can provide functional options to configure endpoint values for the resolved endpoint.", + EndpointResolverFromURL)); + writer.openBlock("func $L(url string, optFns ...func($P)) EndpointResolver {", "}", + EndpointResolverFromURL, AWS_ENDPOINT, () -> { + writer.write("e := $T{ URL : url, }", AWS_ENDPOINT); + writer.write("for _, fn := range optFns { fn(&e) }"); + writer.write(""); + + writer.openBlock("return $T(", ")", resolverFuncSymbol, () -> { + writer.write("func(region string, options $L) ($T, error) {", RESOLVER_OPTIONS, AWS_ENDPOINT); + writer.write("if len(e.SigningRegion) == 0 { e.SigningRegion = region }"); + writer.write("return e, nil },"); + }); + }); } private void writeExternalResolveEndpointImplementation( diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/AwsCustomGoDependency.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/AwsCustomGoDependency.java index ef9d2a99de0..64cf0ac1cd7 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/AwsCustomGoDependency.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/AwsCustomGoDependency.java @@ -48,8 +48,8 @@ private AwsCustomGoDependency() { } private static final class Versions { - private static final String INTERNAL_S3SHARED = "v0.4.1-0.20210108204630-4822f3195720"; - private static final String INTERNAL_ACCEPTENCODING = "v0.4.1-0.20210108204630-4822f3195720"; - private static final String INTERNAL_PRESIGNURL = "v0.2.1-0.20210108204630-4822f3195720"; + private static final String INTERNAL_S3SHARED = "v1.0.0"; + private static final String INTERNAL_ACCEPTENCODING = "v1.0.0"; + private static final String INTERNAL_PRESIGNURL = "v1.0.0"; } }