Skip to content

Commit

Permalink
Add context into endpoint param binding inputs (#498)
Browse files Browse the repository at this point in the history
* 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 <wty@amazon.com>

* add changelog

* fix changelog

---------

Co-authored-by: Tianyi Wang <wty@amazon.com>
  • Loading branch information
wty-Bryant and Tianyi Wang authored Jun 17, 2024
1 parent bced1e1 commit e421cf2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .changelog/df65633a5ad44d44824adf6b784199e7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "df65633a-5ad4-4d44-824a-df6b784199e7",
"type": "feature",
"description": "Add ctx into endpoint param binding to support accountID-based endpoint routing downstream",
"modules": [
"."
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
}
Expand All @@ -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());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -71,6 +72,7 @@ func bindEndpointParams(input interface{}, options Options) *EndpointParameters
}
""",
MapUtils.of(
"context", GoStdlibTypes.Context.Context,
"builtinBindings", generateBuiltinBindings(),
"clientContextBindings", generateClientContextBindings()
));
Expand Down

0 comments on commit e421cf2

Please sign in to comment.