Skip to content

Commit 2392a24

Browse files
authored
Thread through BehaviorVersion to S3 Express identity provider (#3478)
## Motivation and Context A follow-up task that resolves one of the `TODO(Post S3Express release)` ## Description This PR ensures that `BehaviorVersion` is threaded through from an outer S3 client to the inner S3 client when `DefaultS3ExpressIdentityProvider` is constructed. I considered the alternative where `BehaviorVersion` would be stored in `ConfigBag`using another flavor like `StoreOnce` and obtained from the bag within `DefaultS3ExpressIdentityProvider::express_session_credentials`. But ensuring `StoreOnce` per `ConfigBag` was not enough for `BehaviorVersion` since there could be nested `ConfigBag`s where each `ConfigBag` was separate. `BehaviorVersion` needs to be unique across those different `ConfigBag`s and the fact that we store `BehaviorVersion` outside `RuntimeComponents` or `ConfigBag` is a reasonable choice from that perspective (the ease of guaranteeing the uniqueness of `BehaviorVersion`). ## Testing Relied on existing tests in CI. ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] 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._
1 parent 1e55d75 commit 2392a24

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

CHANGELOG.next.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ message = "Increased minimum version of wasi crate dependency in aws-smithy-wasm
1616
references = ["smithy-rs#3476"]
1717
meta = { "breaking" = false, "tada" = false, "bug" = false }
1818
authors = ["landonxjames"]
19+
20+
[[aws-sdk-rust]]
21+
message = "`DefaultS3ExpressIdentityProvider` now uses `BehaviorVersion` threaded through from the outer S3 client, instead of always creating `BehaviorVersion::latest()` on the fly."
22+
references = ["smithy-rs#3478"]
23+
meta = { "breaking" = false, "bug" = true, "tada" = false }
24+
author = "ysaito1001"

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ pub(crate) mod identity_provider {
464464

465465
#[derive(Debug)]
466466
pub(crate) struct DefaultS3ExpressIdentityProvider {
467+
behavior_version: crate::config::BehaviorVersion,
467468
cache: S3ExpressIdentityCache,
468469
}
469470

@@ -542,9 +543,8 @@ pub(crate) mod identity_provider {
542543
runtime_components: &'a RuntimeComponents,
543544
config_bag: &'a ConfigBag,
544545
) -> Result<SessionCredentials, BoxError> {
545-
// TODO(Post S3Express release): Thread through `BehaviorVersion` from the outer S3 client
546546
let mut config_builder = crate::config::Builder::from_config_bag(config_bag)
547-
.behavior_version(crate::config::BehaviorVersion::latest());
547+
.behavior_version(self.behavior_version.clone());
548548

549549
// inherits all runtime components from a current S3 operation but clears out
550550
// out interceptors configured for that operation
@@ -568,11 +568,26 @@ pub(crate) mod identity_provider {
568568

569569
#[derive(Default)]
570570
pub(crate) struct Builder {
571+
behavior_version: Option<crate::config::BehaviorVersion>,
571572
time_source: Option<SharedTimeSource>,
572573
buffer_time: Option<Duration>,
573574
}
574575

575576
impl Builder {
577+
pub(crate) fn behavior_version(
578+
mut self,
579+
behavior_version: crate::config::BehaviorVersion,
580+
) -> Self {
581+
self.set_behavior_version(Some(behavior_version));
582+
self
583+
}
584+
pub(crate) fn set_behavior_version(
585+
&mut self,
586+
behavior_version: Option<crate::config::BehaviorVersion>,
587+
) -> &mut Self {
588+
self.behavior_version = behavior_version;
589+
self
590+
}
576591
pub(crate) fn time_source(mut self, time_source: impl TimeSource + 'static) -> Self {
577592
self.set_time_source(time_source.into_shared());
578593
self
@@ -593,6 +608,9 @@ pub(crate) mod identity_provider {
593608
}
594609
pub(crate) fn build(self) -> DefaultS3ExpressIdentityProvider {
595610
DefaultS3ExpressIdentityProvider {
611+
behavior_version: self
612+
.behavior_version
613+
.expect("required field `behavior_version` should be set"),
596614
cache: S3ExpressIdentityCache::new(
597615
DEFAULT_MAX_CACHE_CAPACITY,
598616
self.time_source.unwrap_or_default(),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.writable
2828
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
2929
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
3030
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
31+
import software.amazon.smithy.rust.codegen.core.util.dq
3132
import software.amazon.smithy.rust.codegen.core.util.getTrait
3233
import software.amazon.smithy.rustsdk.AwsCargoDependency
3334
import software.amazon.smithy.rustsdk.AwsRuntimeType
@@ -105,6 +106,9 @@ private class S3ExpressServiceRuntimePluginCustomization(codegenContext: ClientC
105106
.resolve("client::identity::SharedIdentityResolver"),
106107
)
107108
}
109+
val behaviorVersionError =
110+
"Invalid client configuration: A behavior version must be set when creating an inner S3 client. " +
111+
"A behavior version should be set in the outer S3 client, so it needs to be passed down to the inner client."
108112

109113
override fun section(section: ServiceRuntimePluginSection): Writable =
110114
writable {
@@ -126,6 +130,7 @@ private class S3ExpressServiceRuntimePluginCustomization(codegenContext: ClientC
126130
rustTemplate(
127131
"""
128132
#{DefaultS3ExpressIdentityProvider}::builder()
133+
.behavior_version(${section.serviceConfigName}.behavior_version.clone().expect(${behaviorVersionError.dq()}))
129134
.time_source(${section.serviceConfigName}.time_source().unwrap_or_default())
130135
.build()
131136
""",

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,14 @@ private fun baseClientRuntimePluginsFn(
486486
) -> #{RuntimePlugins} {
487487
let mut configured_plugins = #{Vec}::new();
488488
::std::mem::swap(&mut config.runtime_plugins, &mut configured_plugins);
489-
##[allow(unused_mut)]
490-
let mut behavior_version = config.behavior_version.clone();
491489
#{update_bmv}
492490
493491
let mut plugins = #{RuntimePlugins}::new()
494492
// defaults
495493
.with_client_plugins(#{default_plugins}(
496494
#{DefaultPluginParams}::new()
497495
.with_retry_partition_name(${codegenContext.serviceShape.sdkId().dq()})
498-
.with_behavior_version(behavior_version.expect(${behaviorVersionError.dq()}))
496+
.with_behavior_version(config.behavior_version.clone().expect(${behaviorVersionError.dq()}))
499497
))
500498
// user config
501499
.with_client_plugin(
@@ -532,8 +530,8 @@ private fun baseClientRuntimePluginsFn(
532530
featureGatedBlock(BehaviorVersionLatest) {
533531
rustTemplate(
534532
"""
535-
if behavior_version.is_none() {
536-
behavior_version = Some(#{BehaviorVersion}::latest());
533+
if config.behavior_version.is_none() {
534+
config.behavior_version = Some(#{BehaviorVersion}::latest());
537535
}
538536
539537
""",

0 commit comments

Comments
 (0)