Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context into endpoint param binding inputs #498

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading