From d0f7746f5960d2fcff9f73634831dbaafc8c4c37 Mon Sep 17 00:00:00 2001 From: Eren Yeager <92114074+wty-Bryant@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:28:08 -0500 Subject: [PATCH 1/3] Add accountID into endpoint2.0 param binding (#496) * Add accountID endpoint builtin and aid mode config * Modify endpoint builtin codegen --------- Co-authored-by: Tianyi Wang --- .../go/codegen/auth/AuthParametersResolverGenerator.java | 8 +++++--- .../auth/ResolveAuthSchemeMiddlewareGenerator.java | 2 +- .../go/codegen/endpoints/EndpointMiddlewareGenerator.java | 2 +- .../endpoints/EndpointParameterBindingsGenerator.java | 4 +++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/AuthParametersResolverGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/AuthParametersResolverGenerator.java index 8dda1b970..316be0b18 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/AuthParametersResolverGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/AuthParametersResolverGenerator.java @@ -18,6 +18,7 @@ import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; import java.util.ArrayList; +import software.amazon.smithy.go.codegen.GoStdlibTypes; import software.amazon.smithy.go.codegen.GoWriter; import software.amazon.smithy.go.codegen.integration.ProtocolGenerator; import software.amazon.smithy.utils.MapUtils; @@ -42,7 +43,7 @@ public GoWriter.Writable generate() { loadResolvers(); return goTemplate(""" - func $name:L(operation string, input interface{}, options Options) $params:P { + func $name:L(ctx $context:T, operation string, input interface{}, options Options) $params:P { params := &$params:T{ Operation: operation, } @@ -55,14 +56,15 @@ public GoWriter.Writable generate() { MapUtils.of( "name", FUNC_NAME, "params", AuthParametersGenerator.STRUCT_SYMBOL, - "bindings", generateResolvers() + "bindings", generateResolvers(), + "context", GoStdlibTypes.Context.Context )); } private GoWriter.Writable generateResolvers() { return (writer) -> { for (var resolver: resolvers) { - writer.write("$T(params, input, options)", resolver.resolver()); + writer.write("$T(ctx, params, input, options)", resolver.resolver()); } }; } diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/ResolveAuthSchemeMiddlewareGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/ResolveAuthSchemeMiddlewareGenerator.java index b8eeca564..23c7a2b7a 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/ResolveAuthSchemeMiddlewareGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/ResolveAuthSchemeMiddlewareGenerator.java @@ -66,7 +66,7 @@ private GoWriter.Writable generateFields() { private GoWriter.Writable generateBody() { return goTemplate(""" - params := $1L(m.operation, getOperationInput(ctx), m.options) + params := $1L(ctx, m.operation, getOperationInput(ctx), m.options) options, err := m.options.AuthSchemeResolver.ResolveAuthSchemes(ctx, params) if err != nil { return out, metadata, $2T("resolve auth scheme: %w", err) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointMiddlewareGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointMiddlewareGenerator.java index 683056d8a..b2640dc52 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointMiddlewareGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointMiddlewareGenerator.java @@ -126,7 +126,7 @@ private GoWriter.Writable generateAssertResolver() { private GoWriter.Writable generateResolveEndpoint() { return goTemplate(""" - params := bindEndpointParams(getOperationInput(ctx), m.options) + params := bindEndpointParams(ctx, getOperationInput(ctx), m.options) endpt, err := m.options.EndpointResolverV2.ResolveEndpoint(ctx, *params) if err != nil { return out, metadata, $1T("failed to resolve service endpoint, %w", err) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParameterBindingsGenerator.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParameterBindingsGenerator.java index e7884dff2..0860680cc 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParameterBindingsGenerator.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/endpoints/EndpointParameterBindingsGenerator.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; +import software.amazon.smithy.go.codegen.GoStdlibTypes; import software.amazon.smithy.go.codegen.GoWriter; import software.amazon.smithy.go.codegen.integration.ProtocolGenerator; import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter; @@ -56,7 +57,7 @@ public GoWriter.Writable generate() { bindEndpointParams(*EndpointParameters) } - func bindEndpointParams(input interface{}, options Options) *EndpointParameters { + func bindEndpointParams(ctx $context:T, input interface{}, options Options) *EndpointParameters { params := &EndpointParameters{} $builtinBindings:W @@ -71,6 +72,7 @@ func bindEndpointParams(input interface{}, options Options) *EndpointParameters } """, MapUtils.of( + "context", GoStdlibTypes.Context.Context, "builtinBindings", generateBuiltinBindings(), "clientContextBindings", generateClientContextBindings() )); From 63aaa33dbba57410c5956164d7741a4e06f21543 Mon Sep 17 00:00:00 2001 From: Tianyi Wang Date: Mon, 12 Feb 2024 18:42:46 -0500 Subject: [PATCH 2/3] add changelog --- .changelog/df65633a5ad44d44824adf6b784199e7.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changelog/df65633a5ad44d44824adf6b784199e7.json diff --git a/.changelog/df65633a5ad44d44824adf6b784199e7.json b/.changelog/df65633a5ad44d44824adf6b784199e7.json new file mode 100644 index 000000000..a7062e3b0 --- /dev/null +++ b/.changelog/df65633a5ad44d44824adf6b784199e7.json @@ -0,0 +1,8 @@ +{ + "id": "df65633a-5ad4-4d44-824a-df6b784199e7", + "type": "feature", + "description": "add ctx into endpoint param binding func as input", + "modules": [ + "." + ] +} \ No newline at end of file From e6a6f6bd227d9a395ba1977d1687af8e02ac4717 Mon Sep 17 00:00:00 2001 From: Tianyi Wang Date: Mon, 17 Jun 2024 12:00:17 -0400 Subject: [PATCH 3/3] fix changelog --- .changelog/df65633a5ad44d44824adf6b784199e7.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/df65633a5ad44d44824adf6b784199e7.json b/.changelog/df65633a5ad44d44824adf6b784199e7.json index a7062e3b0..30f96f35b 100644 --- a/.changelog/df65633a5ad44d44824adf6b784199e7.json +++ b/.changelog/df65633a5ad44d44824adf6b784199e7.json @@ -1,7 +1,7 @@ { "id": "df65633a-5ad4-4d44-824a-df6b784199e7", "type": "feature", - "description": "add ctx into endpoint param binding func as input", + "description": "Add ctx into endpoint param binding to support accountID-based endpoint routing downstream", "modules": [ "." ]