Skip to content

Commit d755bd2

Browse files
author
Zelda Hessler
authored
don't apply stalled stream protection to CopyObject (#3649)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> Disables SSP for S3's CopyObject ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent c45dc12 commit d755bd2

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCus
2727
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationGenerator
2828
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationSection
2929
import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientRestXmlFactory
30+
import software.amazon.smithy.rust.codegen.client.smithy.traits.IncompatibleWithStalledStreamProtectionTrait
3031
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
3132
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate
3233
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
@@ -59,6 +60,10 @@ class S3Decorator : ClientCodegenDecorator {
5960
// API returns ListAllMyDirectoryBucketsResult instead of ListDirectoryBucketsOutput
6061
ShapeId.from("com.amazonaws.s3#ListDirectoryBucketsOutput"),
6162
)
63+
private val operationsIncompatibleWithStalledStreamProtection =
64+
setOf(
65+
ShapeId.from("com.amazonaws.s3#CopyObject"),
66+
)
6267

6368
override fun protocols(
6469
serviceId: ShapeId,
@@ -81,6 +86,9 @@ class S3Decorator : ClientCodegenDecorator {
8186
shape.letIf(isInInvalidXmlRootAllowList(shape)) {
8287
logger.info("Adding AllowInvalidXmlRoot trait to $it")
8388
(it as StructureShape).toBuilder().addTrait(AllowInvalidXmlRoot()).build()
89+
}.letIf(operationsIncompatibleWithStalledStreamProtection.contains(shape.id)) {
90+
logger.info("Adding IncompatibleWithStalledStreamProtection trait to $it")
91+
(it as OperationShape).toBuilder().addTrait(IncompatibleWithStalledStreamProtectionTrait()).build()
8492
}
8593
}
8694
// the model has the bucket in the path

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/StalledStreamProtectionConfigCustomization.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.configReexport
1111
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
1212
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCustomization
1313
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationSection
14+
import software.amazon.smithy.rust.codegen.client.smithy.traits.IncompatibleWithStalledStreamProtectionTrait
1415
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
1516
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
1617
import software.amazon.smithy.rust.codegen.core.rustlang.writable
@@ -34,7 +35,7 @@ class StalledStreamProtectionDecorator : ClientCodegenDecorator {
3435
operation: OperationShape,
3536
baseCustomizations: List<OperationCustomization>,
3637
): List<OperationCustomization> {
37-
return baseCustomizations + StalledStreamProtectionOperationCustomization(codegenContext)
38+
return baseCustomizations + StalledStreamProtectionOperationCustomization(codegenContext, operation)
3839
}
3940
}
4041

@@ -111,11 +112,17 @@ class StalledStreamProtectionConfigCustomization(codegenContext: ClientCodegenCo
111112

112113
class StalledStreamProtectionOperationCustomization(
113114
codegenContext: ClientCodegenContext,
115+
private val operationShape: OperationShape,
114116
) : OperationCustomization() {
115117
private val rc = codegenContext.runtimeConfig
116118

117119
override fun section(section: OperationSection): Writable =
118120
writable {
121+
// Don't add the stalled stream protection interceptor if the operation is incompatible with it
122+
if (operationShape.hasTrait(IncompatibleWithStalledStreamProtectionTrait.ID)) {
123+
return@writable
124+
}
125+
119126
when (section) {
120127
is OperationSection.AdditionalInterceptors -> {
121128
val stalledStreamProtectionModule = RuntimeType.smithyRuntime(rc).resolve("client::stalled_stream_protection")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.client.smithy.traits
7+
8+
import software.amazon.smithy.model.node.Node
9+
import software.amazon.smithy.model.shapes.ShapeId
10+
import software.amazon.smithy.model.traits.AnnotationTrait
11+
12+
/**
13+
* Indicates that an operation shape is incompatible with stalled stream protection.
14+
*/
15+
class IncompatibleWithStalledStreamProtectionTrait : AnnotationTrait(ID, Node.objectNode()) {
16+
companion object {
17+
val ID: ShapeId = ShapeId.from("software.amazon.smithy.rust.codegen.client.smithy.traits#incompatibleWithStalledStreamProtectionTrait")
18+
}
19+
}

0 commit comments

Comments
 (0)