Skip to content

Commit 7cdc03a

Browse files
committed
Apply AwsChunkedContentEncodingDecorator only to S3
This commit addresses #4504 (comment)
1 parent ad0be20 commit 7cdc03a

4 files changed

Lines changed: 39 additions & 26 deletions

File tree

aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/AwsChunkedContentEncodingDecorator.kt

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,19 @@ class AwsChunkedContentEncodingDecorator : ClientCodegenDecorator {
3131
// This decorator must decorate after any of the following:
3232
// - HttpRequestChecksumDecorator
3333
// - HttpRequestCompressionDecorator
34+
//
35+
// TODO(https://github.com/smithy-lang/smithy-rs/issues/4382): Change ORDER to -1 once
36+
// a dedicated Smithy trait is available.
37+
// Why ORDER -2 is needed temporarily:
38+
// - AwsChunkedContentEncodingDecorator is part of AwsSdkCodegenDecorator (ORDER -1),
39+
// which only applies to S3
40+
// - HttpChecksumTest needs aws-chunked for flexible checksums but uses a non-S3 model
41+
// - To test this, AwsChunkedContentEncodingDecorator must be passed separately to
42+
// awsSdkIntegrationTest alongside AwsSdkCodegenDecorator
43+
// - Since HttpRequestChecksumDecorator is in AwsSdkCodegenDecorator (ORDER -1),
44+
// we need ORDER -2 to run before it
3445
override val order: Byte =
35-
(minOf(HttpRequestChecksumDecorator.ORDER, HttpRequestCompressionDecorator.ORDER) - 1).toByte()
46+
(minOf(HttpRequestChecksumDecorator.ORDER, HttpRequestCompressionDecorator.ORDER) - 2).toByte()
3647

3748
override fun configCustomizations(
3849
codegenContext: ClientCodegenContext,
@@ -46,38 +57,16 @@ class AwsChunkedContentEncodingDecorator : ClientCodegenDecorator {
4657
) = baseCustomizations + AwsChunkedOperationCustomization(codegenContext, operation)
4758
}
4859

49-
// TODO(https://github.com/smithy-lang/smithy-rs/issues/4382): Replace this heuristic with a dedicated
50-
// Smithy trait once available to determine whether operations require aws-chunked encoding.
51-
private fun operationRequiresAwsChunked(
52-
codegenContext: ClientCodegenContext,
53-
operation: OperationShape,
54-
): Boolean {
55-
val checksumTrait = operation.getTrait<HttpChecksumTrait>() ?: return false
56-
val requestAlgorithmMember =
57-
checksumTrait.requestAlgorithmMemberShape(codegenContext, operation) ?: return false
58-
requestAlgorithmMember.getTrait<HttpHeaderTrait>()?.value ?: return false
59-
val input = codegenContext.model.expectShape(operation.inputShape, StructureShape::class.java)
60-
return input.hasStreamingMember(codegenContext.model)
61-
}
62-
63-
private fun serviceRequiresAwsChunked(codegenContext: ClientCodegenContext): Boolean =
64-
codegenContext.serviceShape.allOperations.any { operationId ->
65-
val operation = codegenContext.model.expectShape(operationId, OperationShape::class.java)
66-
operationRequiresAwsChunked(codegenContext, operation)
67-
}
68-
6960
private class AwsChunkedConfigCustomization(
7061
codegenContext: ClientCodegenContext,
7162
) : ConfigCustomization() {
7263
private val runtimeConfig = codegenContext.runtimeConfig
7364
private val moduleUseName = codegenContext.moduleUseName()
74-
private val serviceRequiresChunking = serviceRequiresAwsChunked(codegenContext)
7565

7666
override fun section(section: ServiceConfig) =
7767
writable {
7868
when (section) {
7969
ServiceConfig.BuilderImpl -> {
80-
if (!serviceRequiresChunking) return@writable
8170
rustTemplate(
8271
"""
8372
/// Sets the chunk size for [`aws-chunked encoding`].
@@ -144,6 +133,20 @@ private class AwsChunkedConfigCustomization(
144133
}
145134
}
146135

136+
// TODO(https://github.com/smithy-lang/smithy-rs/issues/4382): Replace this condition with a dedicated
137+
// Smithy trait once available to determine whether operations require aws-chunked encoding.
138+
private fun operationRequiresAwsChunked(
139+
codegenContext: ClientCodegenContext,
140+
operation: OperationShape,
141+
): Boolean {
142+
val checksumTrait = operation.getTrait<HttpChecksumTrait>() ?: return false
143+
val requestAlgorithmMember =
144+
checksumTrait.requestAlgorithmMemberShape(codegenContext, operation) ?: return false
145+
requestAlgorithmMember.getTrait<HttpHeaderTrait>()?.value ?: return false
146+
val input = codegenContext.model.expectShape(operation.inputShape, StructureShape::class.java)
147+
return input.hasStreamingMember(codegenContext.model)
148+
}
149+
147150
private class AwsChunkedOperationCustomization(
148151
private val codegenContext: ClientCodegenContext,
149152
private val operation: OperationShape,

aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ val DECORATORS: List<ClientCodegenDecorator> =
5858
SdkConfigDecorator(),
5959
ServiceConfigDecorator(),
6060
AwsPresigningDecorator(),
61-
AwsChunkedContentEncodingDecorator(),
6261
AwsCrateDocsDecorator(),
6362
AwsEndpointsStdLib(),
6463
*PromotedBuiltInsDecorators,
@@ -99,6 +98,9 @@ val DECORATORS: List<ClientCodegenDecorator> =
9998
S3ExtendedRequestIdDecorator(),
10099
IsTruncatedPaginatorDecorator(),
101100
S3ExpiresDecorator(),
101+
// TODO(https://github.com/smithy-lang/smithy-rs/issues/4382): Apply this decorator based on
102+
// a dedicated Smithy trait once available.
103+
AwsChunkedContentEncodingDecorator(),
102104
),
103105
S3ControlDecorator().onlyApplyTo("com.amazonaws.s3control#AWSS3ControlServiceV20180820"),
104106
STSDecorator().onlyApplyTo("com.amazonaws.sts#AWSSecurityTokenServiceV20110615"),

aws/codegen-aws-sdk/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,13 @@ internal class HttpChecksumTest {
144144
}
145145

146146
@Test
147-
fun requestChecksumWorks() {
148-
awsSdkIntegrationTest(model) { context, rustCrate ->
147+
fun requestResponseChecksumWorks() {
148+
awsSdkIntegrationTest(
149+
model,
150+
// TODO(https://github.com/smithy-lang/smithy-rs/issues/4382): Remove this additional decorator
151+
// and update the test model above with a dedicated Smithy trait once available.
152+
additionalDecorators = listOf(AwsChunkedContentEncodingDecorator()),
153+
) { context, rustCrate ->
149154
// Allows us to use the user-agent test-utils in aws-runtime
150155
rustCrate.mergeFeature(Feature("test-util", true, listOf("aws-runtime/test-util")))
151156
val rc = context.runtimeConfig

aws/codegen-aws-sdk/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import software.amazon.smithy.model.node.ObjectNode
1010
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
1111
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings
1212
import software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin
13+
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
1314
import software.amazon.smithy.rust.codegen.client.testutil.ClientDecoratableBuildPlugin
1415
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
1516
import software.amazon.smithy.rust.codegen.client.testutil.testClientCodegenContext
@@ -44,12 +45,14 @@ fun awsTestCodegenContext(
4445
fun awsSdkIntegrationTest(
4546
model: Model,
4647
params: IntegrationTestParams = awsIntegrationTestParams(),
48+
additionalDecorators: List<ClientCodegenDecorator> = listOf(),
4749
buildPlugin: ClientDecoratableBuildPlugin = RustClientCodegenPlugin(),
4850
environment: Map<String, String> = mapOf(),
4951
test: (ClientCodegenContext, RustCrate) -> Unit = { _, _ -> },
5052
) = clientIntegrationTest(
5153
model,
5254
params,
55+
additionalDecorators = additionalDecorators,
5356
buildPlugin = buildPlugin,
5457
environment = environment,
5558
test = test,

0 commit comments

Comments
 (0)