Skip to content

Commit fbeaab9

Browse files
authored
Remove get/put methods from ConfigBag and Layer (#2807)
This PR removes the non-storable `get`/`put` methods from `ConfigBag` and `Layer`. ---- _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 bb8e19a commit fbeaab9

File tree

44 files changed

+566
-293
lines changed

Some content is hidden

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

44 files changed

+566
-293
lines changed

aws/rust-runtime/aws-http/src/user_agent.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use aws_smithy_http::middleware::MapRequest;
77
use aws_smithy_http::operation::Request;
8+
use aws_smithy_types::config_bag::{Storable, StoreReplace};
89
use aws_types::app_name::AppName;
910
use aws_types::build_metadata::{OsFamily, BUILD_METADATA};
1011
use aws_types::os_shim_internal::Env;
@@ -211,6 +212,10 @@ impl AwsUserAgent {
211212
}
212213
}
213214

215+
impl Storable for AwsUserAgent {
216+
type Storer = StoreReplace<Self>;
217+
}
218+
214219
#[derive(Clone, Copy, Debug)]
215220
struct SdkMetadata {
216221
name: &'static str,
@@ -246,6 +251,10 @@ impl fmt::Display for ApiMetadata {
246251
}
247252
}
248253

254+
impl Storable for ApiMetadata {
255+
type Storer = StoreReplace<Self>;
256+
}
257+
249258
/// Error for when an user agent metadata doesn't meet character requirements.
250259
///
251260
/// Metadata may only have alphanumeric characters and any of these characters:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,18 @@ impl Interceptor for GlacierTreeHashHeaderInterceptor {
130130
context: &mut BeforeTransmitInterceptorContextMut<'_>,
131131
cfg: &mut ConfigBag,
132132
) -> Result<(), BoxError> {
133-
let maybe_loaded_body = cfg.get::<LoadedRequestBody>();
133+
let maybe_loaded_body = cfg.load::<LoadedRequestBody>();
134134
if let Some(LoadedRequestBody::Loaded(body)) = maybe_loaded_body {
135135
let content_sha256 = add_checksum_treehash(context.request_mut(), body)?;
136136

137137
// Override the signing payload with this precomputed hash
138138
let mut signing_config = cfg
139-
.get::<SigV4OperationSigningConfig>()
139+
.load::<SigV4OperationSigningConfig>()
140140
.ok_or("SigV4OperationSigningConfig not found")?
141141
.clone();
142142
signing_config.signing_options.payload_override =
143143
Some(SignableBody::Precomputed(content_sha256));
144-
cfg.interceptor_state().put(signing_config);
144+
cfg.interceptor_state().store_put(signing_config);
145145
} else {
146146
return Err(
147147
"the request body wasn't loaded into memory before the retry loop, \

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,10 @@ fn add_checksum_for_request_body(
132132
// Body is streaming: wrap the body so it will emit a checksum as a trailer.
133133
None => {
134134
tracing::debug!("applying {checksum_algorithm:?} of the request body as a trailer");
135-
if let Some(mut signing_config) = cfg.get::<SigV4OperationSigningConfig>().cloned() {
135+
if let Some(mut signing_config) = cfg.load::<SigV4OperationSigningConfig>().cloned() {
136136
signing_config.signing_options.payload_override =
137137
Some(SignableBody::StreamingUnsignedPayloadTrailer);
138-
139-
let mut layer = Layer::new("http_body_checksum_sigv4_payload_override");
140-
layer.put(signing_config);
141-
cfg.push_layer(layer);
138+
cfg.interceptor_state().store_put(signing_config);
142139
}
143140
wrap_streaming_request_body_in_checksum_calculating_body(request, checksum_algorithm)?;
144141
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use aws_smithy_runtime_api::client::interceptors::{
2222
disable_interceptor, Interceptor, InterceptorRegistrar, SharedInterceptor,
2323
};
2424
use aws_smithy_runtime_api::client::orchestrator::ConfigBagAccessors;
25+
use aws_smithy_runtime_api::client::retries::DynRetryStrategy;
2526
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
2627
use aws_smithy_types::config_bag::{ConfigBag, FrozenLayer, Layer};
2728

@@ -48,11 +49,12 @@ impl Interceptor for SigV4PresigningInterceptor {
4849
_context: &mut BeforeSerializationInterceptorContextMut<'_>,
4950
cfg: &mut ConfigBag,
5051
) -> Result<(), BoxError> {
51-
cfg.interceptor_state().put::<HeaderSerializationSettings>(
52-
HeaderSerializationSettings::new()
53-
.omit_default_content_length()
54-
.omit_default_content_type(),
55-
);
52+
cfg.interceptor_state()
53+
.store_put::<HeaderSerializationSettings>(
54+
HeaderSerializationSettings::new()
55+
.omit_default_content_length()
56+
.omit_default_content_type(),
57+
);
5658
cfg.interceptor_state()
5759
.set_request_time(SharedTimeSource::new(StaticTimeSource::new(
5860
self.config.start_time(),
@@ -65,12 +67,12 @@ impl Interceptor for SigV4PresigningInterceptor {
6567
_context: &mut BeforeTransmitInterceptorContextMut<'_>,
6668
cfg: &mut ConfigBag,
6769
) -> Result<(), BoxError> {
68-
if let Some(mut config) = cfg.get::<SigV4OperationSigningConfig>().cloned() {
70+
if let Some(mut config) = cfg.load::<SigV4OperationSigningConfig>().cloned() {
6971
config.signing_options.expires_in = Some(self.config.expires());
7072
config.signing_options.signature_type = HttpSignatureType::HttpRequestQueryParams;
7173
config.signing_options.payload_override = Some(self.payload_override.clone());
7274
cfg.interceptor_state()
73-
.put::<SigV4OperationSigningConfig>(config);
75+
.store_put::<SigV4OperationSigningConfig>(config);
7476
Ok(())
7577
} else {
7678
Err(
@@ -101,10 +103,10 @@ impl SigV4PresigningRuntimePlugin {
101103
impl RuntimePlugin for SigV4PresigningRuntimePlugin {
102104
fn config(&self) -> Option<FrozenLayer> {
103105
let mut layer = Layer::new("Presigning");
104-
layer.set_retry_strategy(NeverRetryStrategy::new());
105-
layer.put(disable_interceptor::<InvocationIdInterceptor>("presigning"));
106-
layer.put(disable_interceptor::<RequestInfoInterceptor>("presigning"));
107-
layer.put(disable_interceptor::<UserAgentInterceptor>("presigning"));
106+
layer.set_retry_strategy(DynRetryStrategy::new(NeverRetryStrategy::new()));
107+
layer.store_put(disable_interceptor::<InvocationIdInterceptor>("presigning"));
108+
layer.store_put(disable_interceptor::<RequestInfoInterceptor>("presigning"));
109+
layer.store_put(disable_interceptor::<UserAgentInterceptor>("presigning"));
108110
Some(layer.freeze())
109111
}
110112

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use aws_smithy_runtime_api::client::auth::{
1414
};
1515
use aws_smithy_runtime_api::client::identity::{Identity, IdentityResolver, IdentityResolvers};
1616
use aws_smithy_runtime_api::client::orchestrator::{ConfigBagAccessors, HttpRequest};
17-
use aws_smithy_types::config_bag::ConfigBag;
17+
use aws_smithy_types::config_bag::{ConfigBag, Storable, StoreReplace};
1818
use aws_smithy_types::Document;
1919
use aws_types::region::{Region, SigningRegion};
2020
use aws_types::SigningService;
@@ -169,6 +169,10 @@ pub struct SigV4OperationSigningConfig {
169169
pub signing_options: SigningOptions,
170170
}
171171

172+
impl Storable for SigV4OperationSigningConfig {
173+
type Storer = StoreReplace<Self>;
174+
}
175+
172176
/// SigV4 HTTP request signer.
173177
#[derive(Debug, Default)]
174178
pub struct SigV4HttpRequestSigner;
@@ -253,11 +257,11 @@ impl SigV4HttpRequestSigner {
253257
config_bag: &'a ConfigBag,
254258
) -> Result<Cow<'a, SigV4OperationSigningConfig>, SigV4SigningError> {
255259
let operation_config = config_bag
256-
.get::<SigV4OperationSigningConfig>()
260+
.load::<SigV4OperationSigningConfig>()
257261
.ok_or(SigV4SigningError::MissingOperationSigningConfig)?;
258262

259-
let signing_region = config_bag.get::<SigningRegion>();
260-
let signing_service = config_bag.get::<SigningService>();
263+
let signing_region = config_bag.load::<SigningRegion>();
264+
let signing_service = config_bag.load::<SigningService>();
261265

262266
let EndpointAuthSchemeConfig {
263267
signing_region_override,
@@ -365,7 +369,7 @@ impl HttpRequestSigner for SigV4HttpRequestSigner {
365369
use aws_smithy_eventstream::frame::DeferredSignerSender;
366370
use event_stream::SigV4MessageSigner;
367371

368-
if let Some(signer_sender) = config_bag.get::<DeferredSignerSender>() {
372+
if let Some(signer_sender) = config_bag.load::<DeferredSignerSender>() {
369373
let time_source = config_bag.request_time().unwrap_or_default();
370374
signer_sender
371375
.send(Box::new(SigV4MessageSigner::new(
@@ -559,7 +563,7 @@ mod tests {
559563
#[test]
560564
fn endpoint_config_overrides_region_and_service() {
561565
let mut layer = Layer::new("test");
562-
layer.put(SigV4OperationSigningConfig {
566+
layer.store_put(SigV4OperationSigningConfig {
563567
region: Some(SigningRegion::from(Region::new("override-this-region"))),
564568
service: Some(SigningService::from_static("override-this-service")),
565569
signing_options: Default::default(),
@@ -597,7 +601,7 @@ mod tests {
597601
#[test]
598602
fn endpoint_config_supports_fallback_when_region_or_service_are_unset() {
599603
let mut layer = Layer::new("test");
600-
layer.put(SigV4OperationSigningConfig {
604+
layer.store_put(SigV4OperationSigningConfig {
601605
region: Some(SigningRegion::from(Region::new("us-east-1"))),
602606
service: Some(SigningService::from_static("qldb")),
603607
signing_options: Default::default(),

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use aws_smithy_runtime_api::box_error::BoxError;
77
use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
88
use aws_smithy_runtime_api::client::interceptors::Interceptor;
9-
use aws_smithy_types::config_bag::ConfigBag;
9+
use aws_smithy_types::config_bag::{ConfigBag, Storable, StoreReplace};
1010
use http::{HeaderName, HeaderValue};
1111
use std::fmt::Debug;
1212
use uuid::Uuid;
@@ -24,6 +24,27 @@ pub trait InvocationIdGenerator: Debug + Send + Sync {
2424
fn generate(&self) -> Result<Option<InvocationId>, BoxError>;
2525
}
2626

27+
/// Dynamic dispatch implementation of [`InvocationIdGenerator`]
28+
#[derive(Debug)]
29+
pub struct DynInvocationIdGenerator(Box<dyn InvocationIdGenerator>);
30+
31+
impl DynInvocationIdGenerator {
32+
/// Creates a new [`DynInvocationIdGenerator`].
33+
pub fn new(gen: impl InvocationIdGenerator + 'static) -> Self {
34+
Self(Box::new(gen))
35+
}
36+
}
37+
38+
impl InvocationIdGenerator for DynInvocationIdGenerator {
39+
fn generate(&self) -> Result<Option<InvocationId>, BoxError> {
40+
self.0.generate()
41+
}
42+
}
43+
44+
impl Storable for DynInvocationIdGenerator {
45+
type Storer = StoreReplace<Self>;
46+
}
47+
2748
/// This interceptor generates a UUID and attaches it to all request attempts made as part of this operation.
2849
#[non_exhaustive]
2950
#[derive(Debug, Default)]
@@ -43,12 +64,12 @@ impl Interceptor for InvocationIdInterceptor {
4364
cfg: &mut ConfigBag,
4465
) -> Result<(), BoxError> {
4566
let id = cfg
46-
.get::<Box<dyn InvocationIdGenerator>>()
67+
.load::<DynInvocationIdGenerator>()
4768
.map(|gen| gen.generate())
4869
.transpose()?
4970
.flatten();
5071
cfg.interceptor_state()
51-
.put::<InvocationId>(id.unwrap_or_default());
72+
.store_put::<InvocationId>(id.unwrap_or_default());
5273

5374
Ok(())
5475
}
@@ -60,7 +81,7 @@ impl Interceptor for InvocationIdInterceptor {
6081
) -> Result<(), BoxError> {
6182
let headers = ctx.request_mut().headers_mut();
6283
let id = cfg
63-
.get::<InvocationId>()
84+
.load::<InvocationId>()
6485
.ok_or("Expected an InvocationId in the ConfigBag but none was present")?;
6586
headers.append(AMZ_SDK_INVOCATION_ID, id.0.clone());
6687
Ok(())
@@ -90,6 +111,10 @@ impl Default for InvocationId {
90111
}
91112
}
92113

114+
impl Storable for InvocationId {
115+
type Storer = StoreReplace<Self>;
116+
}
117+
93118
#[cfg(feature = "test-util")]
94119
mod test_util {
95120
use super::*;
@@ -188,7 +213,7 @@ mod tests {
188213
.modify_before_transmit(&mut ctx, &mut cfg)
189214
.unwrap();
190215

191-
let expected = cfg.get::<InvocationId>().expect("invocation ID was set");
216+
let expected = cfg.load::<InvocationId>().expect("invocation ID was set");
192217
let header = expect_header(&ctx, "amz-sdk-invocation-id");
193218
assert_eq!(expected.0, header, "the invocation ID in the config bag must match the invocation ID in the request header");
194219
// UUID should include 32 chars and 4 dashes

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl RequestInfoInterceptor {
4343
cfg: &ConfigBag,
4444
) -> Option<(Cow<'static, str>, Cow<'static, str>)> {
4545
let request_attempts = cfg
46-
.get::<RequestAttempts>()
46+
.load::<RequestAttempts>()
4747
.map(|r_a| r_a.attempts())
4848
.unwrap_or(0);
4949
let request_attempts = request_attempts.to_string();
@@ -54,7 +54,7 @@ impl RequestInfoInterceptor {
5454
&self,
5555
cfg: &ConfigBag,
5656
) -> Option<(Cow<'static, str>, Cow<'static, str>)> {
57-
if let Some(retry_config) = cfg.get::<RetryConfig>() {
57+
if let Some(retry_config) = cfg.load::<RetryConfig>() {
5858
let max_attempts = retry_config.max_attempts().to_string();
5959
Some((Cow::Borrowed("max"), Cow::Owned(max_attempts)))
6060
} else {
@@ -63,9 +63,9 @@ impl RequestInfoInterceptor {
6363
}
6464

6565
fn build_ttl_pair(&self, cfg: &ConfigBag) -> Option<(Cow<'static, str>, Cow<'static, str>)> {
66-
let timeout_config = cfg.get::<TimeoutConfig>()?;
66+
let timeout_config = cfg.load::<TimeoutConfig>()?;
6767
let socket_read = timeout_config.read_timeout()?;
68-
let estimated_skew: Duration = cfg.get::<ServiceClockSkew>().cloned()?.into();
68+
let estimated_skew: Duration = cfg.load::<ServiceClockSkew>().cloned()?.into();
6969
let current_time = SystemTime::now();
7070
let ttl = current_time.checked_add(socket_read + estimated_skew)?;
7171
let mut timestamp = DateTime::from(ttl);
@@ -191,8 +191,8 @@ mod tests {
191191
context.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());
192192

193193
let mut layer = Layer::new("test");
194-
layer.put(RetryConfig::standard());
195-
layer.put(
194+
layer.store_put(RetryConfig::standard());
195+
layer.store_put(
196196
TimeoutConfig::builder()
197197
.read_timeout(Duration::from_secs(30))
198198
.build(),

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ impl Interceptor for UserAgentInterceptor {
7777
cfg: &mut ConfigBag,
7878
) -> Result<(), BoxError> {
7979
let api_metadata = cfg
80-
.get::<ApiMetadata>()
80+
.load::<ApiMetadata>()
8181
.ok_or(UserAgentInterceptorError::MissingApiMetadata)?;
8282

8383
// Allow for overriding the user agent by an earlier interceptor (so, for example,
8484
// tests can use `AwsUserAgent::for_tests()`) by attempting to grab one out of the
8585
// config bag before creating one.
8686
let ua: Cow<'_, AwsUserAgent> = cfg
87-
.get::<AwsUserAgent>()
87+
.load::<AwsUserAgent>()
8888
.map(Cow::Borrowed)
8989
.unwrap_or_else(|| {
9090
let mut ua = AwsUserAgent::new_from_environment(Env::real(), api_metadata.clone());
9191

92-
let maybe_app_name = cfg.get::<AppName>();
92+
let maybe_app_name = cfg.load::<AppName>();
9393
if let Some(app_name) = maybe_app_name {
9494
ua.set_app_name(app_name.clone());
9595
}
@@ -139,8 +139,8 @@ mod tests {
139139
let mut context = context();
140140

141141
let mut layer = Layer::new("test");
142-
layer.put(AwsUserAgent::for_tests());
143-
layer.put(ApiMetadata::new("unused", "unused"));
142+
layer.store_put(AwsUserAgent::for_tests());
143+
layer.store_put(ApiMetadata::new("unused", "unused"));
144144
let mut cfg = ConfigBag::of_layers(vec![layer]);
145145

146146
let interceptor = UserAgentInterceptor::new();
@@ -165,7 +165,7 @@ mod tests {
165165

166166
let api_metadata = ApiMetadata::new("some-service", "some-version");
167167
let mut layer = Layer::new("test");
168-
layer.put(api_metadata.clone());
168+
layer.store_put(api_metadata.clone());
169169
let mut config = ConfigBag::of_layers(vec![layer]);
170170

171171
let interceptor = UserAgentInterceptor::new();
@@ -195,8 +195,8 @@ mod tests {
195195

196196
let api_metadata = ApiMetadata::new("some-service", "some-version");
197197
let mut layer = Layer::new("test");
198-
layer.put(api_metadata);
199-
layer.put(AppName::new("my_awesome_app").unwrap());
198+
layer.store_put(api_metadata);
199+
layer.store_put(AppName::new("my_awesome_app").unwrap());
200200
let mut config = ConfigBag::of_layers(vec![layer]);
201201

202202
let interceptor = UserAgentInterceptor::new();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod sdk_config;
2525
pub use aws_smithy_client::http_connector;
2626
pub use sdk_config::SdkConfig;
2727

28+
use aws_smithy_types::config_bag::{Storable, StoreReplace};
2829
use std::borrow::Cow;
2930

3031
/// The name of the service used to sign this request
@@ -56,3 +57,7 @@ impl From<&'static str> for SigningService {
5657
Self::from_static(service)
5758
}
5859
}
60+
61+
impl Storable for SigningService {
62+
type Storer = StoreReplace<Self>;
63+
}

aws/rust-runtime/aws-types/src/region.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,7 @@ impl SigningRegion {
8282
SigningRegion(Cow::Borrowed(region))
8383
}
8484
}
85+
86+
impl Storable for SigningRegion {
87+
type Storer = StoreReplace<Self>;
88+
}

0 commit comments

Comments
 (0)