Skip to content

Commit 68c4649

Browse files
authored
Track accountID endpoint mode in user-agent (#3000)
1 parent c45eaac commit 68c4649

File tree

63 files changed

+378
-22
lines changed

Some content is hidden

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

63 files changed

+378
-22
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "1c8f914e-6b9a-4aef-9418-a60e7fe62de2",
3+
"type": "feature",
4+
"description": "Track AccountID endpoint mode in user-agent.",
5+
"modules": [
6+
"service/dynamodb"
7+
]
8+
}

aws/middleware/user_agent.go

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,39 @@ type UserAgentFeature string
7676

7777
// Enumerates UserAgentFeature.
7878
const (
79-
UserAgentFeatureResourceModel UserAgentFeature = "A" // n/a (we don't generate separate resource types)
80-
UserAgentFeatureWaiter = "B"
81-
UserAgentFeaturePaginator = "C"
82-
UserAgentFeatureRetryModeLegacy = "D" // n/a (equivalent to standard)
83-
UserAgentFeatureRetryModeStandard = "E"
84-
UserAgentFeatureRetryModeAdaptive = "F"
85-
UserAgentFeatureS3Transfer = "G"
86-
UserAgentFeatureS3CryptoV1N = "H" // n/a (crypto client is external)
87-
UserAgentFeatureS3CryptoV2 = "I" // n/a
88-
UserAgentFeatureS3ExpressBucket = "J"
89-
UserAgentFeatureS3AccessGrants = "K" // not yet implemented
90-
UserAgentFeatureGZIPRequestCompression = "L"
91-
UserAgentFeatureProtocolRPCV2CBOR = "M"
92-
UserAgentFeatureRequestChecksumCRC32 = "U"
93-
UserAgentFeatureRequestChecksumCRC32C = "V"
94-
UserAgentFeatureRequestChecksumCRC64 = "W"
95-
UserAgentFeatureRequestChecksumSHA1 = "X"
96-
UserAgentFeatureRequestChecksumSHA256 = "Y"
97-
UserAgentFeatureRequestChecksumWhenSupported = "Z"
98-
UserAgentFeatureRequestChecksumWhenRequired = "a"
99-
UserAgentFeatureResponseChecksumWhenSupported = "b"
100-
UserAgentFeatureResponseChecksumWhenRequired = "c"
79+
UserAgentFeatureResourceModel UserAgentFeature = "A" // n/a (we don't generate separate resource types)
80+
81+
UserAgentFeatureWaiter = "B"
82+
UserAgentFeaturePaginator = "C"
83+
84+
UserAgentFeatureRetryModeLegacy = "D" // n/a (equivalent to standard)
85+
UserAgentFeatureRetryModeStandard = "E"
86+
UserAgentFeatureRetryModeAdaptive = "F"
87+
88+
UserAgentFeatureS3Transfer = "G"
89+
UserAgentFeatureS3CryptoV1N = "H" // n/a (crypto client is external)
90+
UserAgentFeatureS3CryptoV2 = "I" // n/a
91+
UserAgentFeatureS3ExpressBucket = "J"
92+
UserAgentFeatureS3AccessGrants = "K" // not yet implemented
93+
94+
UserAgentFeatureGZIPRequestCompression = "L"
95+
96+
UserAgentFeatureProtocolRPCV2CBOR = "M"
97+
98+
UserAgentFeatureAccountIDEndpoint = "O" // DO NOT IMPLEMENT: rules output is not currently defined. SDKs should not parse endpoints for feature information.
99+
UserAgentFeatureAccountIDModePreferred = "P"
100+
UserAgentFeatureAccountIDModeDisabled = "Q"
101+
UserAgentFeatureAccountIDModeRequired = "R"
102+
103+
UserAgentFeatureRequestChecksumCRC32 = "U"
104+
UserAgentFeatureRequestChecksumCRC32C = "V"
105+
UserAgentFeatureRequestChecksumCRC64 = "W"
106+
UserAgentFeatureRequestChecksumSHA1 = "X"
107+
UserAgentFeatureRequestChecksumSHA256 = "Y"
108+
UserAgentFeatureRequestChecksumWhenSupported = "Z"
109+
UserAgentFeatureRequestChecksumWhenRequired = "a"
110+
UserAgentFeatureResponseChecksumWhenSupported = "b"
111+
UserAgentFeatureResponseChecksumWhenRequired = "c"
101112
)
102113

103114
// RequestUserAgent is a build middleware that set the User-Agent for the request.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package software.amazon.smithy.aws.go.codegen.customization;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import software.amazon.smithy.aws.go.codegen.AwsGoDependency;
6+
import software.amazon.smithy.codegen.core.SymbolProvider;
7+
import software.amazon.smithy.go.codegen.GoCodegenContext;
8+
import software.amazon.smithy.go.codegen.GoDelegator;
9+
import software.amazon.smithy.go.codegen.GoSettings;
10+
import software.amazon.smithy.go.codegen.SmithyGoDependency;
11+
import software.amazon.smithy.go.codegen.integration.GoIntegration;
12+
import software.amazon.smithy.go.codegen.integration.MiddlewareRegistrar;
13+
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
14+
import software.amazon.smithy.model.Model;
15+
16+
import static software.amazon.smithy.aws.go.codegen.customization.AccountIDEndpointRouting.hasAccountIdEndpoints;
17+
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;
18+
import static software.amazon.smithy.go.codegen.SymbolUtils.buildPackageSymbol;
19+
20+
/**
21+
* Tracks the retry mode being used by the caller.
22+
*/
23+
public class AccountIdEndpointModeUserAgent implements GoIntegration {
24+
private static final MiddlewareRegistrar MIDDLEWARE = MiddlewareRegistrar.builder()
25+
.resolvedFunction(buildPackageSymbol("addUserAgentAccountIDEndpointMode"))
26+
.useClientOptions()
27+
.build();
28+
29+
@Override
30+
public List<RuntimeClientPlugin> getClientPlugins() {
31+
return List.of(
32+
RuntimeClientPlugin.builder()
33+
.servicePredicate(AccountIDEndpointRouting::hasAccountIdEndpoints)
34+
.registerMiddleware(MIDDLEWARE)
35+
.build()
36+
);
37+
}
38+
39+
@Override
40+
public void writeAdditionalFiles(GoCodegenContext ctx) {
41+
if (!hasAccountIdEndpoints(ctx.model(), ctx.settings().getService(ctx.model()))) {
42+
return;
43+
}
44+
45+
ctx.writerDelegator().useFileWriter("api_client.go", ctx.settings().getModuleName(), goTemplate("""
46+
$aws:D $awsMiddleware:D
47+
func addUserAgentAccountIDEndpointMode(stack $stack:P, options Options) error {
48+
ua, err := getOrAddRequestUserAgent(stack)
49+
if err != nil {
50+
return err
51+
}
52+
53+
switch options.AccountIDEndpointMode {
54+
case aws.AccountIDEndpointModePreferred:
55+
ua.AddUserAgentFeature(awsmiddleware.UserAgentFeatureAccountIDModePreferred)
56+
case aws.AccountIDEndpointModeRequired:
57+
ua.AddUserAgentFeature(awsmiddleware.UserAgentFeatureAccountIDModeRequired)
58+
case aws.AccountIDEndpointModeDisabled:
59+
ua.AddUserAgentFeature(awsmiddleware.UserAgentFeatureAccountIDModeDisabled)
60+
}
61+
return nil
62+
}""",
63+
Map.of(
64+
"aws", AwsGoDependency.AWS_CORE,
65+
"awsMiddleware", AwsGoDependency.AWS_MIDDLEWARE,
66+
"stack", SmithyGoDependency.SMITHY_MIDDLEWARE.struct("Stack")
67+
)));
68+
}
69+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ software.amazon.smithy.aws.go.codegen.customization.BackfillRequiredTrait
8888
software.amazon.smithy.aws.go.codegen.customization.DeprecateService
8989
software.amazon.smithy.aws.go.codegen.customization.BasicUserAgentFeatures
9090
software.amazon.smithy.aws.go.codegen.customization.ChecksumMetricsTracking
91+
software.amazon.smithy.aws.go.codegen.customization.AccountIdEndpointModeUserAgent

service/dynamodb/api_client.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_BatchExecuteStatement.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_BatchGetItem.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_BatchWriteItem.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_CreateBackup.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_CreateGlobalTable.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_CreateTable.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DeleteBackup.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DeleteItem.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DeleteResourcePolicy.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DeleteTable.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeBackup.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeContinuousBackups.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeContributorInsights.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeEndpoints.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeExport.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeGlobalTable.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeGlobalTableSettings.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeImport.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeKinesisStreamingDestination.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeLimits.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeTable.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dynamodb/api_op_DescribeTableReplicaAutoScaling.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)