Skip to content

Commit efc0e20

Browse files
Merge branch 'main' into RFC30/tests
2 parents 4f65d8d + 8dc8963 commit efc0e20

File tree

107 files changed

+14602
-472
lines changed

Some content is hidden

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

107 files changed

+14602
-472
lines changed

.github/workflows/ci-main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Checkout
3333
uses: actions/checkout@v3
3434
- name: Acquire credentials
35-
uses: aws-actions/configure-aws-credentials@v1-node16
35+
uses: aws-actions/configure-aws-credentials@v2.2.0
3636
with:
3737
role-to-assume: ${{ secrets.SMITHY_RS_PUBLIC_ECR_PUSH_ROLE_ARN }}
3838
role-session-name: GitHubActions

.github/workflows/ci-merge-queue.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Attempt to load a docker login password
34-
uses: aws-actions/configure-aws-credentials@v1-node16
34+
uses: aws-actions/configure-aws-credentials@v2.2.0
3535
with:
3636
role-to-assume: ${{ secrets.SMITHY_RS_PUBLIC_ECR_PUSH_ROLE_ARN }}
3737
role-session-name: GitHubActions
@@ -67,7 +67,7 @@ jobs:
6767
DOCKER_BUILDKIT: 1
6868
run: ./smithy-rs/.github/scripts/acquire-build-image
6969
- name: Acquire credentials
70-
uses: aws-actions/configure-aws-credentials@v1-node16
70+
uses: aws-actions/configure-aws-credentials@v2.2.0
7171
with:
7272
role-to-assume: ${{ secrets.SMITHY_RS_PUBLIC_ECR_PUSH_ROLE_ARN }}
7373
role-session-name: GitHubActions

.github/workflows/ci-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Attempt to load a docker login password
34-
uses: aws-actions/configure-aws-credentials@v1-node16
34+
uses: aws-actions/configure-aws-credentials@v2.2.0
3535
with:
3636
role-to-assume: ${{ secrets.SMITHY_RS_PUBLIC_ECR_PUSH_ROLE_ARN }}
3737
role-session-name: GitHubActions
@@ -69,7 +69,7 @@ jobs:
6969
DOCKER_BUILDKIT: 1
7070
run: ./smithy-rs/.github/scripts/acquire-build-image
7171
- name: Acquire credentials
72-
uses: aws-actions/configure-aws-credentials@v1-node16
72+
uses: aws-actions/configure-aws-credentials@v2.2.0
7373
with:
7474
role-to-assume: ${{ secrets.SMITHY_RS_PUBLIC_ECR_PUSH_ROLE_ARN }}
7575
role-session-name: GitHubActions

.github/workflows/pull-request-bot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
with:
5656
action: generate-codegen-diff
5757
action-arguments: ${{ inputs.base_revision }}
58-
- uses: aws-actions/configure-aws-credentials@v1-node16
58+
- uses: aws-actions/configure-aws-credentials@v2.2.0
5959
name: Acquire credentials for uploading to S3
6060
with:
6161
role-to-assume: ${{ secrets.SMITHY_RS_PULL_REQUEST_CDN_ROLE_ARN }}
@@ -125,7 +125,7 @@ jobs:
125125
./tools/ci-scripts/generate-doc-preview-index.sh ${{ inputs.base_revision }}
126126
127127
echo 'bot-message=A [new doc preview](https://d2luzm2xt3nokh.cloudfront.net/docs/'${{ inputs.head_revision }}'/index.html) is ready to view.' >> "${GITHUB_OUTPUT}"
128-
- uses: aws-actions/configure-aws-credentials@v1-node16
128+
- uses: aws-actions/configure-aws-credentials@v2.2.0
129129
name: Acquire credentials for uploading to S3
130130
with:
131131
role-to-assume: ${{ secrets.SMITHY_RS_PULL_REQUEST_CDN_ROLE_ARN }}

CHANGELOG.next.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
1212
# author = "rcoh"
1313

14+
[[aws-sdk-rust]]
15+
message = "Add accessors to Builders"
16+
references = ["smithy-rs#2791"]
17+
meta = { "breaking" = false, "tada" = false, "bug" = false }
18+
author = "davidsouther"
19+
20+
[[smithy-rs]]
21+
message = "Add accessors to Builders"
22+
references = ["smithy-rs#2791"]
23+
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
24+
author = "davidsouther"
25+
26+
[[smithy-rs]]
27+
message = "Avoid intermediate vec allocations in AggregatedBytes::to_vec."
28+
author = "yotamofek"
29+
references = ["smithy-rs#2786"]
30+
meta = { "breaking" = false, "tada" = false, "bug" = false }
31+
1432
[[smithy-rs]]
1533
message = "Fix bug in AWS JSON 1.x routers where, if a service had more than 14 operations, the router was created without the route for the 15th operation."
1634
author = "thor-bjorgvinsson"

aws/rust-runtime/aws-inlineable/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub mod glacier_interceptors;
4646
/// Default middleware stack for AWS services
4747
pub mod middleware;
4848

49+
/// Strip prefixes from IDs returned by Route53 operations when those IDs are used to construct requests
50+
pub mod route53_resource_id_preprocessor_middleware;
51+
4952
/// Strip prefixes from IDs returned by Route53 operations when those IDs are used to construct requests
5053
pub mod route53_resource_id_preprocessor;
5154

aws/rust-runtime/aws-inlineable/src/route53_resource_id_preprocessor.rs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
#![allow(dead_code)]
7+
8+
use aws_smithy_runtime_api::client::interceptors::{
9+
BeforeSerializationInterceptorContextMut, BoxError, Interceptor,
10+
};
11+
use aws_smithy_types::config_bag::ConfigBag;
12+
use std::fmt;
13+
use std::marker::PhantomData;
14+
615
// This function is only used to strip prefixes from resource IDs at the time they're passed as
716
// input to a request. Resource IDs returned in responses may or may not include a prefix.
817
/// Strip the resource type prefix from resource ID return
9-
pub fn trim_resource_id(resource_id: &mut Option<String>) {
18+
fn trim_resource_id(resource_id: &mut Option<String>) {
1019
const PREFIXES: &[&str] = &[
1120
"/hostedzone/",
1221
"hostedzone/",
@@ -28,9 +37,55 @@ pub fn trim_resource_id(resource_id: &mut Option<String>) {
2837
}
2938
}
3039

40+
pub(crate) struct Route53ResourceIdInterceptor<G, T>
41+
where
42+
G: for<'a> Fn(&'a mut T) -> &'a mut Option<String>,
43+
{
44+
get_mut_resource_id: G,
45+
_phantom: PhantomData<T>,
46+
}
47+
48+
impl<G, T> fmt::Debug for Route53ResourceIdInterceptor<G, T>
49+
where
50+
G: for<'a> Fn(&'a mut T) -> &'a mut Option<String>,
51+
{
52+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53+
f.debug_struct("Route53ResourceIdInterceptor").finish()
54+
}
55+
}
56+
57+
impl<G, T> Route53ResourceIdInterceptor<G, T>
58+
where
59+
G: for<'a> Fn(&'a mut T) -> &'a mut Option<String>,
60+
{
61+
pub(crate) fn new(get_mut_resource_id: G) -> Self {
62+
Self {
63+
get_mut_resource_id,
64+
_phantom: Default::default(),
65+
}
66+
}
67+
}
68+
69+
impl<G, T> Interceptor for Route53ResourceIdInterceptor<G, T>
70+
where
71+
G: for<'a> Fn(&'a mut T) -> &'a mut Option<String>,
72+
T: fmt::Debug + Send + Sync + 'static,
73+
{
74+
fn modify_before_serialization(
75+
&self,
76+
context: &mut BeforeSerializationInterceptorContextMut<'_>,
77+
_cfg: &mut ConfigBag,
78+
) -> Result<(), BoxError> {
79+
let input: &mut T = context.input_mut().downcast_mut().expect("correct type");
80+
let field = (self.get_mut_resource_id)(input);
81+
trim_resource_id(field);
82+
Ok(())
83+
}
84+
}
85+
3186
#[cfg(test)]
3287
mod test {
33-
use crate::route53_resource_id_preprocessor::trim_resource_id;
88+
use super::trim_resource_id;
3489

3590
#[test]
3691
fn does_not_change_regular_zones() {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
// TODO(enableNewSmithyRuntimeCleanup): Delete this module
7+
8+
// This function is only used to strip prefixes from resource IDs at the time they're passed as
9+
// input to a request. Resource IDs returned in responses may or may not include a prefix.
10+
/// Strip the resource type prefix from resource ID return
11+
pub fn trim_resource_id(resource_id: &mut Option<String>) {
12+
const PREFIXES: &[&str] = &[
13+
"/hostedzone/",
14+
"hostedzone/",
15+
"/change/",
16+
"change/",
17+
"/delegationset/",
18+
"delegationset/",
19+
];
20+
21+
for prefix in PREFIXES {
22+
if let Some(id) = resource_id
23+
.as_deref()
24+
.unwrap_or_default()
25+
.strip_prefix(prefix)
26+
{
27+
*resource_id = Some(id.to_string());
28+
return;
29+
}
30+
}
31+
}
32+
33+
#[cfg(test)]
34+
mod test {
35+
use crate::route53_resource_id_preprocessor_middleware::trim_resource_id;
36+
37+
#[test]
38+
fn does_not_change_regular_zones() {
39+
struct OperationInput {
40+
resource: Option<String>,
41+
}
42+
43+
let mut operation = OperationInput {
44+
resource: Some("Z0441723226OZ66S5ZCNZ".to_string()),
45+
};
46+
trim_resource_id(&mut operation.resource);
47+
assert_eq!(
48+
&operation.resource.unwrap_or_default(),
49+
"Z0441723226OZ66S5ZCNZ"
50+
);
51+
}
52+
53+
#[test]
54+
fn sanitizes_prefixed_zone() {
55+
struct OperationInput {
56+
change_id: Option<String>,
57+
}
58+
59+
let mut operation = OperationInput {
60+
change_id: Some("/change/Z0441723226OZ66S5ZCNZ".to_string()),
61+
};
62+
trim_resource_id(&mut operation.change_id);
63+
assert_eq!(
64+
&operation.change_id.unwrap_or_default(),
65+
"Z0441723226OZ66S5ZCNZ"
66+
);
67+
}
68+
69+
#[test]
70+
fn allow_no_leading_slash() {
71+
struct OperationInput {
72+
hosted_zone: Option<String>,
73+
}
74+
75+
let mut operation = OperationInput {
76+
hosted_zone: Some("hostedzone/Z0441723226OZ66S5ZCNZ".to_string()),
77+
};
78+
trim_resource_id(&mut operation.hosted_zone);
79+
assert_eq!(
80+
&operation.hosted_zone.unwrap_or_default(),
81+
"Z0441723226OZ66S5ZCNZ"
82+
);
83+
}
84+
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,25 @@ class AwsFluentClientDecorator : ClientCodegenDecorator {
103103
baseGenerator.protocolSupport,
104104
baseGenerator.operationShape,
105105
renderClientCreation = { params ->
106+
rust("let mut ${params.configBuilderName} = ${params.configBuilderName};")
107+
if (codegenContext.smithyRuntimeMode.defaultToOrchestrator) {
108+
// TODO(enableNewSmithyRuntimeLaunch): A builder field could not be accessed directly in the orchestrator
109+
// mode when this code change was made. smithy-rs#2792 will enable us to use getters in builders.
110+
// Make this `set_region` conditional by checking if `config_builder.region().is_none()` once the PR
111+
// has been merged to main.
112+
rust("""${params.configBuilderName}.set_region(Some(crate::config::Region::new("us-east-1")));""")
113+
} else {
114+
rust(
115+
"""
116+
// If the test case was missing endpoint parameters, default a region so it doesn't fail
117+
if ${params.configBuilderName}.region.is_none() {
118+
${params.configBuilderName}.set_region(Some(crate::config::Region::new("us-east-1")));
119+
}
120+
""",
121+
)
122+
}
106123
rustTemplate(
107124
"""
108-
// If the test case was missing endpoint parameters, default a region so it doesn't fail
109-
let mut ${params.configBuilderName} = ${params.configBuilderName};
110-
if ${params.configBuilderName}.region.is_none() {
111-
${params.configBuilderName}.set_region(Some(crate::config::Region::new("us-east-1")));
112-
}
113125
let config = ${params.configBuilderName}.http_connector(${params.connectorName}).build();
114126
let ${params.clientName} = #{Client}::from_conf(config);
115127
""",

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust
1717
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
1818
import software.amazon.smithy.rust.codegen.core.rustlang.writable
1919
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
20+
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
21+
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
2022
import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization
2123
import software.amazon.smithy.rust.codegen.core.smithy.customize.adhocCustomization
2224

@@ -53,8 +55,10 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
5355
private val runtimeConfig = codegenContext.runtimeConfig
5456
private val runtimeMode = codegenContext.smithyRuntimeMode
5557
private val codegenScope = arrayOf(
58+
*preludeScope,
5659
"CredentialsCache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("cache::CredentialsCache"),
5760
"DefaultProvider" to defaultProvider(),
61+
"SharedAsyncSleep" to RuntimeType.smithyAsync(runtimeConfig).resolve("rt::sleep::SharedAsyncSleep"),
5862
"SharedCredentialsCache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("cache::SharedCredentialsCache"),
5963
"SharedCredentialsProvider" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("provider::SharedCredentialsProvider"),
6064
)
@@ -95,35 +99,57 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
9599
}
96100

97101
ServiceConfig.BuilderStruct ->
98-
rustTemplate("credentials_cache: Option<#{CredentialsCache}>,", *codegenScope)
102+
if (runtimeMode.defaultToMiddleware) {
103+
rustTemplate("credentials_cache: #{Option}<#{CredentialsCache}>,", *codegenScope)
104+
}
99105

100106
ServiceConfig.BuilderImpl -> {
101107
rustTemplate(
102108
"""
103109
/// Sets the credentials cache for this service
104110
pub fn credentials_cache(mut self, credentials_cache: #{CredentialsCache}) -> Self {
105-
self.set_credentials_cache(Some(credentials_cache));
111+
self.set_credentials_cache(#{Some}(credentials_cache));
106112
self
107113
}
108114
109-
/// Sets the credentials cache for this service
110-
pub fn set_credentials_cache(&mut self, credentials_cache: Option<#{CredentialsCache}>) -> &mut Self {
111-
self.credentials_cache = credentials_cache;
112-
self
113-
}
114115
""",
115116
*codegenScope,
116117
)
118+
119+
if (runtimeMode.defaultToOrchestrator) {
120+
rustTemplate(
121+
"""
122+
/// Sets the credentials cache for this service
123+
pub fn set_credentials_cache(&mut self, credentials_cache: #{Option}<#{CredentialsCache}>) -> &mut Self {
124+
self.inner.store_or_unset(credentials_cache);
125+
self
126+
}
127+
""",
128+
*codegenScope,
129+
)
130+
} else {
131+
rustTemplate(
132+
"""
133+
/// Sets the credentials cache for this service
134+
pub fn set_credentials_cache(&mut self, credentials_cache: Option<#{CredentialsCache}>) -> &mut Self {
135+
self.credentials_cache = credentials_cache;
136+
self
137+
}
138+
""",
139+
*codegenScope,
140+
)
141+
}
117142
}
118143

119144
ServiceConfig.BuilderBuild -> {
120145
if (runtimeMode.defaultToOrchestrator) {
121146
rustTemplate(
122147
"""
123148
layer.store_put(
124-
self.credentials_cache
149+
layer.load::<#{CredentialsCache}>()
150+
.cloned()
125151
.unwrap_or_else({
126-
let sleep = self.sleep_impl.clone();
152+
let sleep = layer.load::<#{SharedAsyncSleep}>().cloned();
127153
|| match sleep {
128154
Some(sleep) => {
129155
#{CredentialsCache}::lazy_builder()
@@ -133,9 +159,9 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
133159
None => #{CredentialsCache}::lazy(),
134160
}
135161
})
136-
.create_cache(self.credentials_provider.unwrap_or_else(|| {
162+
.create_cache(layer.load::<#{SharedCredentialsProvider}>().cloned().unwrap_or_else(|| {
137163
#{SharedCredentialsProvider}::new(#{DefaultProvider})
138-
})),
164+
}))
139165
);
140166
""",
141167
*codegenScope,

0 commit comments

Comments
 (0)