Skip to content

Commit 97bf21a

Browse files
authored
add interceptors (#3143)
1 parent f82e8c9 commit 97bf21a

File tree

36,604 files changed

+729481
-1380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

36,604 files changed

+729481
-1380
lines changed

.changelog/5e1864bad1c34d96a76929f148c61b52.json

Lines changed: 467 additions & 0 deletions
Large diffs are not rendered by default.

SMITHY_GO_CODEGEN_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
107eb1414a9c309076941ef37a6c71465ec397f6
1+
a22818fe19b9bc7d4926501907b154d813b309a5

aws/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
smithybearer "github.com/aws/smithy-go/auth/bearer"
77
"github.com/aws/smithy-go/logging"
88
"github.com/aws/smithy-go/middleware"
9+
smithyhttp "github.com/aws/smithy-go/transport/http"
910
)
1011

1112
// HTTPClient provides the interface to provide custom HTTPClients. Generally
@@ -192,6 +193,9 @@ type Config struct {
192193
// This variable is sourced from environment variable AWS_RESPONSE_CHECKSUM_VALIDATION or
193194
// the shared config profile attribute "response_checksum_validation".
194195
ResponseChecksumValidation ResponseChecksumValidation
196+
197+
// Registry of HTTP interceptors.
198+
Interceptors smithyhttp.InterceptorRegistry
195199
}
196200

197201
// NewConfig returns a new Config pointer that can be chained with builder

aws/protocol/eventstream/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream
22

33
go 1.22
44

5-
require github.com/aws/smithy-go v1.22.4
5+
require github.com/aws/smithy-go v1.22.5
66

77
replace github.com/aws/aws-sdk-go-v2 => ../../../

aws/protocol/eventstream/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/aws/smithy-go v1.22.4 h1:uqXzVZNuNexwc/xrh6Tb56u89WDlJY6HS+KC0S4QSjw=
2-
github.com/aws/smithy-go v1.22.4/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
1+
github.com/aws/smithy-go v1.22.5 h1:P9ATCXPMb2mPjYBgueqJNCA5S9UfktsW0tTxi+a7eqw=
2+
github.com/aws/smithy-go v1.22.5/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ public class AddAwsConfigFields implements GoIntegration {
260260
.type(SdkGoTypes.Aws.ResponseChecksumValidation)
261261
.documentation("Indicates how user opt-in/out response checksum validation")
262262
.servicePredicate(AwsHttpChecksumGenerator::hasOutputChecksumTrait)
263+
.build(),
264+
AwsConfigField.builder()
265+
.name("Interceptors")
266+
.type(SmithyGoDependency.SMITHY_HTTP_TRANSPORT.struct("InterceptorRegistry"))
267+
.generatedOnClient(false)
268+
.awsResolveFunction(buildPackageSymbol("resolveInterceptors"))
263269
.build()
264270
);
265271

@@ -324,6 +330,15 @@ private void writeAwsDefaultResolvers(GoWriter writer) {
324330
writeRetryerResolvers(writer);
325331
writeRetryMaxAttemptsFinalizers(writer);
326332
writeAwsConfigEndpointResolver(writer);
333+
writeInterceptorResolver(writer);
334+
}
335+
336+
private void writeInterceptorResolver(GoWriter writer) {
337+
writer.write("""
338+
func resolveInterceptors(cfg aws.Config, o *Options) {
339+
o.Interceptors = cfg.Interceptors.Copy()
340+
}
341+
""");
327342
}
328343

329344
private void writerAwsDefaultResolversTests(GoWriter writer) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package software.amazon.smithy.aws.go.codegen.customization;
2+
3+
import static software.amazon.smithy.go.codegen.SymbolUtils.buildPackageSymbol;
4+
5+
import java.util.List;
6+
import software.amazon.smithy.go.codegen.GoCodegenContext;
7+
import software.amazon.smithy.go.codegen.integration.GoIntegration;
8+
import software.amazon.smithy.go.codegen.integration.MiddlewareRegistrar;
9+
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
10+
11+
// We add retry interceptors here since Smithy clients don't have a retry loop atm.
12+
public class RetryInterceptors implements GoIntegration {
13+
private static RuntimeClientPlugin interceptor(String name) {
14+
return RuntimeClientPlugin.builder()
15+
.registerMiddleware(
16+
MiddlewareRegistrar.builder()
17+
.resolvedFunction(buildPackageSymbol(name))
18+
.useClientOptions()
19+
.build()
20+
)
21+
.build();
22+
}
23+
24+
@Override
25+
public byte getOrder() {
26+
return 127;
27+
}
28+
29+
@Override
30+
public List<RuntimeClientPlugin> getClientPlugins() {
31+
return List.of(
32+
interceptor("addInterceptBeforeRetryLoop"),
33+
interceptor("addInterceptAttempt")
34+
);
35+
}
36+
37+
@Override
38+
public void writeAdditionalFiles(GoCodegenContext ctx) {
39+
ctx.writerDelegator().useFileWriter("api_client.go", ctx.settings().getModuleName(), writer -> {
40+
writer.write("""
41+
func addInterceptBeforeRetryLoop(stack *middleware.Stack, opts Options) error {
42+
return stack.Finalize.Insert(&smithyhttp.InterceptBeforeRetryLoop{
43+
Interceptors: opts.Interceptors.BeforeRetryLoop,
44+
}, "Retry", middleware.Before)
45+
}
46+
47+
func addInterceptAttempt(stack *middleware.Stack, opts Options) error {
48+
return stack.Finalize.Insert(&smithyhttp.InterceptAttempt{
49+
BeforeAttempt: opts.Interceptors.BeforeAttempt,
50+
AfterAttempt: opts.Interceptors.AfterAttempt,
51+
}, "Retry", middleware.After)
52+
}
53+
""");
54+
});
55+
}
56+
}

codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ software.amazon.smithy.aws.go.codegen.customization.ChecksumMetricsTracking
9191
software.amazon.smithy.aws.go.codegen.customization.AccountIdEndpointModeUserAgent
9292
software.amazon.smithy.aws.go.codegen.CredentialSourceFeatureTrackerGenerator
9393
software.amazon.smithy.aws.go.codegen.customization.SraOperationOrderTest
94-
software.amazon.smithy.aws.go.codegen.customization.service.bedrockruntime.RemoveOperations
94+
software.amazon.smithy.aws.go.codegen.customization.service.bedrockruntime.RemoveOperations
95+
software.amazon.smithy.aws.go.codegen.customization.RetryInterceptors

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ var defaultAWSConfigResolvers = []awsConfigResolver{
8989

9090
// Sets the ResponseChecksumValidation if present in env var or shared config profile
9191
resolveResponseChecksumValidation,
92+
93+
resolveInterceptors,
9294
}
9395

9496
// A Config represents a generic configuration value or set of values. This type

config/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/aws/aws-sdk-go-v2/service/sso v1.25.6
1111
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.4
1212
github.com/aws/aws-sdk-go-v2/service/sts v1.34.1
13-
github.com/aws/smithy-go v1.22.4
13+
github.com/aws/smithy-go v1.22.5
1414
)
1515

1616
require (

0 commit comments

Comments
 (0)