Skip to content

Commit ee324f2

Browse files
authored
Fix bug in WriteGetObjectResponse endpoint (#2560)
1 parent cfade88 commit ee324f2

File tree

3 files changed

+80
-15
lines changed

3 files changed

+80
-15
lines changed

CHANGELOG.next.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,9 @@ message = "Add `into_segments` method to `AggregatedBytes`, for zero-copy conver
8080
references = ["smithy-rs#2525"]
8181
meta = { "breaking" = false, "tada" = false, "bug" = false }
8282
author = "parker-timmerman"
83+
84+
[[aws-sdk-rust]]
85+
message = "Fix but where an incorrect endpoint was produced for WriteGetObjectResponse"
86+
references = ["smithy-rs#781", "aws-sdk-rust#781"]
87+
meta = { "breaking" = false, "tada" = false, "bug" = true }
88+
author = "rcoh"

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

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import software.amazon.smithy.model.shapes.Shape
1414
import software.amazon.smithy.model.shapes.ShapeId
1515
import software.amazon.smithy.model.shapes.StructureShape
1616
import software.amazon.smithy.model.transform.ModelTransformer
17+
import software.amazon.smithy.rulesengine.traits.EndpointTestCase
18+
import software.amazon.smithy.rulesengine.traits.EndpointTestOperationInput
19+
import software.amazon.smithy.rulesengine.traits.EndpointTestsTrait
1720
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
1821
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
1922
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointCustomization
@@ -31,7 +34,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap
3134
import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestXml
3235
import software.amazon.smithy.rust.codegen.core.smithy.traits.AllowInvalidXmlRoot
3336
import software.amazon.smithy.rust.codegen.core.util.letIf
34-
import software.amazon.smithy.rustsdk.endpoints.stripEndpointTrait
3537
import software.amazon.smithy.rustsdk.getBuiltIn
3638
import software.amazon.smithy.rustsdk.toWritable
3739
import java.util.logging.Logger
@@ -63,23 +65,39 @@ class S3Decorator : ClientCodegenDecorator {
6365
logger.info("Adding AllowInvalidXmlRoot trait to $it")
6466
(it as StructureShape).toBuilder().addTrait(AllowInvalidXmlRoot()).build()
6567
}
66-
}.let(StripBucketFromHttpPath()::transform).let(stripEndpointTrait("RequestRoute"))
68+
}
69+
// the model has the bucket in the path
70+
.let(StripBucketFromHttpPath()::transform)
71+
// the tests in EP2 are incorrect and are missing request route
72+
.let(
73+
FilterEndpointTests(
74+
operationInputFilter = { input ->
75+
when (input.operationName) {
76+
// it's impossible to express HostPrefix behavior in the current EP2 rules schema :-/
77+
// A handwritten test was written to cover this behavior
78+
"WriteGetObjectResponse" -> null
79+
else -> input
80+
}
81+
},
82+
)::transform,
83+
)
6784

6885
override fun endpointCustomizations(codegenContext: ClientCodegenContext): List<EndpointCustomization> {
69-
return listOf(object : EndpointCustomization {
70-
override fun setBuiltInOnServiceConfig(name: String, value: Node, configBuilderRef: String): Writable? {
71-
if (!name.startsWith("AWS::S3")) {
72-
return null
73-
}
74-
val builtIn = codegenContext.getBuiltIn(name) ?: return null
75-
return writable {
76-
rustTemplate(
77-
"let $configBuilderRef = $configBuilderRef.${builtIn.name.rustName()}(#{value});",
78-
"value" to value.toWritable(),
79-
)
86+
return listOf(
87+
object : EndpointCustomization {
88+
override fun setBuiltInOnServiceConfig(name: String, value: Node, configBuilderRef: String): Writable? {
89+
if (!name.startsWith("AWS::S3")) {
90+
return null
91+
}
92+
val builtIn = codegenContext.getBuiltIn(name) ?: return null
93+
return writable {
94+
rustTemplate(
95+
"let $configBuilderRef = $configBuilderRef.${builtIn.name.rustName()}(#{value});",
96+
"value" to value.toWritable(),
97+
)
98+
}
8099
}
81-
}
82-
},
100+
},
83101
)
84102
}
85103

@@ -88,6 +106,28 @@ class S3Decorator : ClientCodegenDecorator {
88106
}
89107
}
90108

109+
class FilterEndpointTests(
110+
private val testFilter: (EndpointTestCase) -> EndpointTestCase? = { a -> a },
111+
private val operationInputFilter: (EndpointTestOperationInput) -> EndpointTestOperationInput? = { a -> a },
112+
) {
113+
fun updateEndpointTests(endpointTests: List<EndpointTestCase>): List<EndpointTestCase> {
114+
val filteredTests = endpointTests.mapNotNull { test -> testFilter(test) }
115+
return filteredTests.map { test ->
116+
val operationInputs = test.operationInputs
117+
test.toBuilder().operationInputs(operationInputs.mapNotNull { operationInputFilter(it) }).build()
118+
}
119+
}
120+
121+
fun transform(model: Model) = ModelTransformer.create().mapTraits(model) { _, trait ->
122+
when (trait) {
123+
is EndpointTestsTrait -> EndpointTestsTrait.builder().testCases(updateEndpointTests(trait.testCases))
124+
.version(trait.version).build()
125+
126+
else -> trait
127+
}
128+
}
129+
}
130+
91131
class S3ProtocolOverride(codegenContext: CodegenContext) : RestXml(codegenContext) {
92132
private val runtimeConfig = codegenContext.runtimeConfig
93133
private val errorScope = arrayOf(

aws/sdk/integration-tests/s3/tests/endpoints.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,22 @@ async fn s3_object_lambda_no_cross_region() {
135135
err
136136
);
137137
}
138+
139+
#[tokio::test]
140+
async fn write_get_object_response() {
141+
let (req, client) = test_client(|b| b);
142+
let _write = client
143+
.write_get_object_response()
144+
.request_route("req-route")
145+
.request_token("token")
146+
.status_code(200)
147+
.body(vec![1, 2, 3].into())
148+
.send()
149+
.await;
150+
151+
let captured_request = req.expect_request();
152+
assert_eq!(
153+
captured_request.uri().to_string(),
154+
"https://req-route.s3-object-lambda.us-west-4.amazonaws.com/WriteGetObjectResponse?x-id=WriteGetObjectResponse"
155+
);
156+
}

0 commit comments

Comments
 (0)