Skip to content

Commit a85cef6

Browse files
rcohjdisantiZelda Hessler
authored
Add configurable runtime plugin to send_v2 so that it is usable (#2635)
## Motivation and Context - `send_v2()` doesn't work for a very small number of reasons—allow it one last final runtime_plugin so that we can use it to make an e2e request ## Description - update a few decorators to be deterministic ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: John DiSanti <jdisanti@amazon.com> Co-authored-by: Zelda Hessler <zhessler@amazon.com>
1 parent e3ecb6c commit a85cef6

File tree

16 files changed

+286
-296
lines changed

16 files changed

+286
-296
lines changed

aws/rust-runtime/aws-runtime/src/auth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub mod sigv4 {
196196
&self,
197197
request: &mut HttpRequest,
198198
identity: &Identity,
199+
// TODO(enableNewSmithyRuntime): should this be the config bag?
199200
signing_properties: &PropertyBag,
200201
) -> Result<(), BoxError> {
201202
let operation_config = signing_properties

aws/rust-runtime/aws-runtime/src/invocation_id.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const AMZ_SDK_INVOCATION_ID: HeaderName = HeaderName::from_static("amz-sdk-invoc
1717
#[non_exhaustive]
1818
#[derive(Debug)]
1919
pub struct InvocationIdInterceptor {
20-
id: HeaderValue,
20+
id: InvocationId,
2121
}
2222

2323
impl InvocationIdInterceptor {
@@ -29,12 +29,9 @@ impl InvocationIdInterceptor {
2929

3030
impl Default for InvocationIdInterceptor {
3131
fn default() -> Self {
32-
let id = Uuid::new_v4();
33-
let id = id
34-
.to_string()
35-
.parse()
36-
.expect("UUIDs always produce a valid header value");
37-
Self { id }
32+
Self {
33+
id: InvocationId::from_uuid(),
34+
}
3835
}
3936
}
4037

@@ -45,11 +42,33 @@ impl Interceptor<HttpRequest, HttpResponse> for InvocationIdInterceptor {
4542
_cfg: &mut ConfigBag,
4643
) -> Result<(), BoxError> {
4744
let headers = context.request_mut()?.headers_mut();
48-
headers.append(AMZ_SDK_INVOCATION_ID, self.id.clone());
45+
let id = _cfg.get::<InvocationId>().unwrap_or(&self.id);
46+
headers.append(AMZ_SDK_INVOCATION_ID, id.0.clone());
4947
Ok(())
5048
}
5149
}
5250

51+
/// InvocationId provides a consistent ID across retries
52+
#[derive(Debug)]
53+
pub struct InvocationId(HeaderValue);
54+
impl InvocationId {
55+
/// A test invocation id to allow deterministic requests
56+
pub fn for_tests() -> Self {
57+
InvocationId(HeaderValue::from_static(
58+
"00000000-0000-4000-8000-000000000000",
59+
))
60+
}
61+
62+
fn from_uuid() -> Self {
63+
let id = Uuid::new_v4();
64+
let id = id
65+
.to_string()
66+
.parse()
67+
.expect("UUIDs always produce a valid header value");
68+
Self(id)
69+
}
70+
}
71+
5372
#[cfg(test)]
5473
mod tests {
5574
use crate::invocation_id::InvocationIdInterceptor;
@@ -84,8 +103,8 @@ mod tests {
84103
.unwrap();
85104

86105
let header = expect_header(&context, "amz-sdk-invocation-id");
87-
assert_eq!(&interceptor.id, header);
106+
assert_eq!(&interceptor.id.0, header);
88107
// UUID should include 32 chars and 4 dashes
89-
assert_eq!(interceptor.id.len(), 36);
108+
assert_eq!(interceptor.id.0.len(), 36);
90109
}
91110
}

aws/sra-test/integration-tests/aws-sdk-s3/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ aws-sdk-s3 = { path = "../../build/sdk/aws-sdk-s3", features = ["test-util"] }
1313
aws-sigv4 = { path = "../../../rust-runtime/aws-sigv4" }
1414
aws-types = { path = "../../../rust-runtime/aws-types" }
1515
aws-smithy-async = { path = "../../../../rust-runtime/aws-smithy-async", features = ["rt-tokio"] }
16-
aws-smithy-client = { path = "../../../../rust-runtime/aws-smithy-client", features = ["test-util"] }
16+
aws-smithy-client = { path = "../../../../rust-runtime/aws-smithy-client", features = ["test-util", "rustls"] }
1717
aws-smithy-types = { path = "../../../../rust-runtime/aws-smithy-types" }
1818
aws-smithy-http = { path = "../../../../rust-runtime/aws-smithy-http" }
1919
aws-smithy-runtime = { path = "../../../../rust-runtime/aws-smithy-runtime", features = ["test-util"] }
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"events": [
3+
{
4+
"connection_id": 0,
5+
"action": {
6+
"Request": {
7+
"request": {
8+
"uri": "https://test-bucket.s3.us-east-1.amazonaws.com/?list-type=2&prefix=prefix~",
9+
"headers": {
10+
"x-amz-security-token": [
11+
"notarealsessiontoken"
12+
],
13+
"authorization": [
14+
"AWS4-HMAC-SHA256 Credential=ANOTREAL/20210618/us-east-1/s3/aws4_request, SignedHeaders=amz-sdk-invocation-id;host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=e7eccf4e792113f5f17a50bfd8f1719479e89ba0b476894e6f3dba030dc87f82"
15+
],
16+
"x-amz-user-agent": [
17+
"aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0"
18+
],
19+
"x-amz-date": [
20+
"20210618T170728Z"
21+
],
22+
"x-amz-content-sha256": [
23+
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
24+
],
25+
"amz-sdk-invocation-id": [
26+
"00000000-0000-4000-8000-000000000000"
27+
],
28+
"user-agent": [
29+
"aws-sdk-rust/0.123.test os/windows/XPSP3 lang/rust/1.50.0"
30+
]
31+
},
32+
"method": "GET"
33+
}
34+
}
35+
}
36+
},
37+
{
38+
"connection_id": 0,
39+
"action": {
40+
"Eof": {
41+
"ok": true,
42+
"direction": "Request"
43+
}
44+
}
45+
},
46+
{
47+
"connection_id": 0,
48+
"action": {
49+
"Response": {
50+
"response": {
51+
"Ok": {
52+
"status": 200,
53+
"version": "HTTP/1.1",
54+
"headers": {
55+
"x-amz-request-id": [
56+
"9X5E7C9EAB6AQEP2"
57+
],
58+
"x-amz-id-2": [
59+
"gZsrBxajPyo1Q0DE2plGf7T6kAnxd4Xx7/S+8lq18GegL6kFbnVXLLh1LnBzpEpFiHN9XoNHkeA="
60+
],
61+
"content-type": [
62+
"application/xml"
63+
],
64+
"transfer-encoding": [
65+
"chunked"
66+
],
67+
"server": [
68+
"AmazonS3"
69+
],
70+
"date": [
71+
"Wed, 26 Apr 2023 14:00:24 GMT"
72+
],
73+
"x-amz-bucket-region": [
74+
"us-east-1"
75+
]
76+
}
77+
}
78+
}
79+
}
80+
}
81+
},
82+
{
83+
"connection_id": 0,
84+
"action": {
85+
"Data": {
86+
"data": {
87+
"Utf8": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ListBucketResult>\n <Name>test-bucket</Name>\n <Prefix>prefix~</Prefix>\n <KeyCount>1</KeyCount>\n <MaxKeys>1000</MaxKeys>\n <IsTruncated>false</IsTruncated>\n <Contents>\n <Key>some-file.file</Key>\n <LastModified>2009-10-12T17:50:30.000Z</LastModified>\n <Size>434234</Size>\n <StorageClass>STANDARD</StorageClass>\n </Contents>\n</ListBucketResult>"
88+
},
89+
"direction": "Response"
90+
}
91+
}
92+
},
93+
{
94+
"connection_id": 0,
95+
"action": {
96+
"Eof": {
97+
"ok": true,
98+
"direction": "Response"
99+
}
100+
}
101+
}
102+
],
103+
"docs": "Test sending an S3 ListObjectsV2 operation with a successful response.",
104+
"version": "V0"
105+
}

0 commit comments

Comments
 (0)