aws_sdk_s3/config.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#![allow(clippy::empty_line_after_doc_comments)]
3/// Configuration for a aws_sdk_s3 service client.
4///
5
6/// Service configuration allows for customization of endpoints, region, credentials providers,
7/// and retry configuration. Generally, it is constructed automatically for you from a shared
8/// configuration loaded by the `aws-config` crate. For example:
9///
10/// ```ignore
11/// // Load a shared config from the environment
12/// let shared_config = aws_config::from_env().load().await;
13/// // The client constructor automatically converts the shared config into the service config
14/// let client = Client::new(&shared_config);
15/// ```
16///
17/// The service config can also be constructed manually using its builder.
18///
19#[derive(::std::clone::Clone, ::std::fmt::Debug)]
20pub struct Config {
21 // Both `config` and `cloneable` are the same config, but the cloneable one
22 // is kept around so that it is possible to convert back into a builder. This can be
23 // optimized in the future.
24 pub(crate) config: crate::config::FrozenLayer,
25 cloneable: ::aws_smithy_types::config_bag::CloneableLayer,
26 pub(crate) runtime_components: crate::config::RuntimeComponentsBuilder,
27 pub(crate) runtime_plugins: ::std::vec::Vec<crate::config::SharedRuntimePlugin>,
28 pub(crate) behavior_version: ::std::option::Option<crate::config::BehaviorVersion>,
29}
30impl Config {
31 ///
32 /// Constructs a config builder.
33 /// <div class="warning">
34 /// Note that a config created from this builder will not have the same safe defaults as one created by
35 /// the <a href="https://crates.io/crates/aws-config" target="_blank">aws-config</a> crate.
36 /// </div>
37 ///
38 pub fn builder() -> Builder {
39 Builder::default()
40 }
41 /// Converts this config back into a builder so that it can be tweaked.
42 pub fn to_builder(&self) -> Builder {
43 Builder {
44 config: self.cloneable.clone(),
45 runtime_components: self.runtime_components.clone(),
46 runtime_plugins: self.runtime_plugins.clone(),
47 behavior_version: self.behavior_version,
48 }
49 }
50 /// Return a reference to the stalled stream protection configuration contained in this config, if any.
51 pub fn stalled_stream_protection(&self) -> ::std::option::Option<&crate::config::StalledStreamProtectionConfig> {
52 self.config.load::<crate::config::StalledStreamProtectionConfig>()
53 }
54 /// Return the [`SharedHttpClient`](crate::config::SharedHttpClient) to use when making requests, if any.
55 pub fn http_client(&self) -> Option<crate::config::SharedHttpClient> {
56 self.runtime_components.http_client()
57 }
58 /// Return the auth schemes configured on this service config
59 pub fn auth_schemes(&self) -> impl Iterator<Item = ::aws_smithy_runtime_api::client::auth::SharedAuthScheme> + '_ {
60 self.runtime_components.auth_schemes()
61 }
62
63 /// Return the auth scheme resolver configured on this service config
64 pub fn auth_scheme_resolver(&self) -> ::std::option::Option<::aws_smithy_runtime_api::client::auth::SharedAuthSchemeOptionResolver> {
65 self.runtime_components.auth_scheme_option_resolver()
66 }
67 /// Returns the configured auth scheme preference
68 pub fn auth_scheme_preference(&self) -> ::std::option::Option<&::aws_smithy_runtime_api::client::auth::AuthSchemePreference> {
69 self.config.load::<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>()
70 }
71
72 /// Returns the endpoint resolver.
73 pub fn endpoint_resolver(&self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver {
74 self.runtime_components.endpoint_resolver().expect("resolver defaulted if not set")
75 }
76 /// Return a reference to the retry configuration contained in this config, if any.
77 pub fn retry_config(&self) -> ::std::option::Option<&::aws_smithy_types::retry::RetryConfig> {
78 self.config.load::<::aws_smithy_types::retry::RetryConfig>()
79 }
80
81 /// Return a cloned shared async sleep implementation from this config, if any.
82 pub fn sleep_impl(&self) -> ::std::option::Option<crate::config::SharedAsyncSleep> {
83 self.runtime_components.sleep_impl()
84 }
85
86 /// Return a reference to the timeout configuration contained in this config, if any.
87 pub fn timeout_config(&self) -> ::std::option::Option<&::aws_smithy_types::timeout::TimeoutConfig> {
88 self.config.load::<::aws_smithy_types::timeout::TimeoutConfig>()
89 }
90
91 /// Returns a reference to the retry partition contained in this config, if any.
92 ///
93 /// WARNING: This method is unstable and may be removed at any time. Do not rely on this
94 /// method for anything!
95 pub fn retry_partition(&self) -> ::std::option::Option<&::aws_smithy_runtime::client::retries::RetryPartition> {
96 self.config.load::<::aws_smithy_runtime::client::retries::RetryPartition>()
97 }
98 /// Returns the configured identity cache for auth.
99 pub fn identity_cache(&self) -> ::std::option::Option<crate::config::SharedIdentityCache> {
100 self.runtime_components.identity_cache()
101 }
102 /// Returns interceptors currently registered by the user.
103 pub fn interceptors(&self) -> impl Iterator<Item = crate::config::SharedInterceptor> + '_ {
104 self.runtime_components.interceptors()
105 }
106 /// Return time source used for this service.
107 pub fn time_source(&self) -> ::std::option::Option<::aws_smithy_async::time::SharedTimeSource> {
108 self.runtime_components.time_source()
109 }
110 /// Returns retry classifiers currently registered by the user.
111 pub fn retry_classifiers(&self) -> impl Iterator<Item = ::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier> + '_ {
112 self.runtime_components.retry_classifiers()
113 }
114 /// Returns the name of the app that is using the client, if it was provided.
115 ///
116 /// This _optional_ name is used to identify the application in the user agent that
117 /// gets sent along with requests.
118 pub fn app_name(&self) -> ::std::option::Option<&::aws_types::app_name::AppName> {
119 self.config.load::<::aws_types::app_name::AppName>()
120 }
121 /// Returns the framework metadata that has been configured, if any.
122 ///
123 /// This _optional_ metadata identifies software frameworks or third-party libraries
124 /// being used with the client, rendered into the user agent as `lib/{name}/{version}`.
125 /// Entries are returned in first-seen (insertion) order, matching the order they are
126 /// rendered into the user agent.
127 pub fn framework_metadata(&self) -> ::std::vec::Vec<&::aws_types::sdk_ua_metadata::FrameworkMetadata> {
128 // `StoreAppend` loads entries newest-first; reverse to first-seen order so
129 // this getter agrees with both the user agent and `SdkConfig::framework_metadata`.
130 let mut entries: ::std::vec::Vec<&::aws_types::sdk_ua_metadata::FrameworkMetadata> =
131 self.config.load::<::aws_types::sdk_ua_metadata::FrameworkMetadata>().collect();
132 entries.reverse();
133 entries
134 }
135 /// Returns the invocation ID generator if one was given in config.
136 ///
137 /// The invocation ID generator generates ID values for the `amz-sdk-invocation-id` header. By default, this will be a random UUID. Overriding it may be useful in tests that examine the HTTP request and need to be deterministic.
138 pub fn invocation_id_generator(&self) -> ::std::option::Option<::aws_runtime::invocation_id::SharedInvocationIdGenerator> {
139 self.config.load::<::aws_runtime::invocation_id::SharedInvocationIdGenerator>().cloned()
140 }
141 /// Creates a new [service config](crate::Config) from a [shared `config`](::aws_types::sdk_config::SdkConfig).
142 pub fn new(config: &::aws_types::sdk_config::SdkConfig) -> Self {
143 Builder::from(config).build()
144 }
145 /// Return a reference to the response_checksum_validation value contained in this config, if any.
146 pub fn response_checksum_validation(&self) -> ::std::option::Option<&crate::config::ResponseChecksumValidation> {
147 self.config.load::<crate::config::ResponseChecksumValidation>()
148 }
149 /// Return a reference to the request_checksum_calculation value contained in this config, if any.
150 pub fn request_checksum_calculation(&self) -> ::std::option::Option<&crate::config::RequestChecksumCalculation> {
151 self.config.load::<crate::config::RequestChecksumCalculation>()
152 }
153 /// The signature version 4 service signing name to use in the credential scope when signing requests.
154 ///
155 /// The signing service may be overridden by the `Endpoint`, or by specifying a custom
156 /// [`SigningName`](aws_types::SigningName) during operation construction
157 pub fn signing_name(&self) -> &'static str {
158 "s3"
159 }
160 /// Returns the SigV4a signing region set, if configured.
161 pub fn sigv4a_signing_region_set(&self) -> Option<&::aws_types::region::SigningRegionSet> {
162 self.config.load::<::aws_types::region::SigningRegionSet>()
163 }
164 /// Returns the AWS region, if it was provided.
165 pub fn region(&self) -> ::std::option::Option<&crate::config::Region> {
166 self.config.load::<crate::config::Region>()
167 }
168 /// This function was intended to be removed, and has been broken since release-2023-11-15 as it always returns a `None`. Do not use.
169 #[deprecated(
170 note = "This function was intended to be removed, and has been broken since release-2023-11-15 as it always returns a `None`. Do not use."
171 )]
172 pub fn credentials_provider(&self) -> Option<crate::config::SharedCredentialsProvider> {
173 ::std::option::Option::None
174 }
175}
176/// Builder for creating a `Config`.
177#[derive(::std::clone::Clone, ::std::fmt::Debug)]
178pub struct Builder {
179 pub(crate) config: ::aws_smithy_types::config_bag::CloneableLayer,
180 pub(crate) runtime_components: crate::config::RuntimeComponentsBuilder,
181 pub(crate) runtime_plugins: ::std::vec::Vec<crate::config::SharedRuntimePlugin>,
182 pub(crate) behavior_version: ::std::option::Option<crate::config::BehaviorVersion>,
183}
184impl ::std::default::Default for Builder {
185 fn default() -> Self {
186 Self {
187 config: ::std::default::Default::default(),
188 runtime_components: crate::config::RuntimeComponentsBuilder::new("service config"),
189 runtime_plugins: ::std::default::Default::default(),
190 behavior_version: ::std::default::Default::default(),
191 }
192 }
193}
194impl Builder {
195 ///
196 /// Constructs a config builder.
197 /// <div class="warning">
198 /// Note that a config created from this builder will not have the same safe defaults as one created by
199 /// the <a href="https://crates.io/crates/aws-config" target="_blank">aws-config</a> crate.
200 /// </div>
201 ///
202 pub fn new() -> Self {
203 Self::default()
204 }
205 /// Constructs a config builder from the given `config_bag`, setting only fields stored in the config bag,
206 /// but not those in runtime components.
207 #[allow(unused)]
208 pub(crate) fn from_config_bag(config_bag: &::aws_smithy_types::config_bag::ConfigBag) -> Self {
209 let mut builder = Self::new();
210 builder.set_stalled_stream_protection(config_bag.load::<crate::config::StalledStreamProtectionConfig>().cloned());
211 builder.set_auth_scheme_preference(config_bag.load::<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>().cloned());
212 builder.set_force_path_style(config_bag.load::<crate::config::ForcePathStyle>().map(|ty| ty.0));
213
214 builder.set_use_arn_region(config_bag.load::<crate::config::UseArnRegion>().map(|ty| ty.0));
215
216 builder.set_disable_multi_region_access_points(config_bag.load::<crate::config::DisableMultiRegionAccessPoints>().map(|ty| ty.0));
217
218 builder.set_accelerate(config_bag.load::<crate::config::Accelerate>().map(|ty| ty.0));
219
220 builder.set_disable_s3_express_session_auth(config_bag.load::<crate::config::DisableS3ExpressSessionAuth>().map(|ty| ty.0));
221 builder.set_retry_config(config_bag.load::<::aws_smithy_types::retry::RetryConfig>().cloned());
222 builder.set_timeout_config(config_bag.load::<::aws_smithy_types::timeout::TimeoutConfig>().cloned());
223 builder.set_retry_partition(config_bag.load::<::aws_smithy_runtime::client::retries::RetryPartition>().cloned());
224 builder.set_app_name(config_bag.load::<::aws_types::app_name::AppName>().cloned());
225 for framework_metadata in config_bag.load::<::aws_types::sdk_ua_metadata::FrameworkMetadata>() {
226 builder.push_framework_metadata(framework_metadata.clone());
227 }
228 builder.set_endpoint_url(config_bag.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()));
229 builder.set_use_dual_stack(config_bag.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0));
230 builder.set_use_fips(config_bag.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0));
231 builder.set_response_checksum_validation(config_bag.load::<crate::config::ResponseChecksumValidation>().cloned());
232 builder.set_request_checksum_calculation(config_bag.load::<crate::config::RequestChecksumCalculation>().cloned());
233 builder.set_sigv4a_signing_region_set(config_bag.load::<::aws_types::region::SigningRegionSet>().cloned());
234 builder.set_region(config_bag.load::<crate::config::Region>().cloned());
235 builder
236 }
237 /// Names operation-input members whose values are captured *and* emitted as
238 /// attributes on the client's built-in metrics (e.g. `["Bucket"]`).
239 ///
240 /// Emitting implies capture, so an emitted member is also readable in-process
241 /// via `CapturedTelemetryAttributes` on the config bag. Names are Smithy input
242 /// member names; only string-valued, non-sensitive members are eligible, and
243 /// naming any other member has no effect. Off by default.
244 ///
245 /// Prefer bounded identifiers here: an emitted member becomes a metric label, so
246 /// high-cardinality values (like object keys) fragment the metrics and inflate
247 /// cost. Use [`Self::capture_input_attributes`] for values you want to read
248 /// in-process without emitting them on the metrics.
249 pub fn emit_input_attributes(mut self, names: impl ::std::iter::IntoIterator<Item = impl ::std::convert::Into<::std::string::String>>) -> Self {
250 let mut requested = self
251 .config
252 .load::<::aws_smithy_types::telemetry::RequestedTelemetryAttributes>()
253 .cloned()
254 .unwrap_or_default();
255 requested.emit(names.into_iter().map(|n| n.into()));
256 self.config.store_put(requested);
257 self
258 }
259
260 /// Names operation-input members whose values are captured into
261 /// `CapturedTelemetryAttributes` for in-process reads (e.g. from a custom
262 /// interceptor), but are **not** emitted on the built-in metrics.
263 ///
264 /// Use this for values you need during the operation lifecycle but do not want on
265 /// the metric label set (for example, high-cardinality identifiers). Names follow
266 /// the same eligibility rules as [`Self::emit_input_attributes`]. Off by default.
267 pub fn capture_input_attributes(
268 mut self,
269 names: impl ::std::iter::IntoIterator<Item = impl ::std::convert::Into<::std::string::String>>,
270 ) -> Self {
271 let mut requested = self
272 .config
273 .load::<::aws_smithy_types::telemetry::RequestedTelemetryAttributes>()
274 .cloned()
275 .unwrap_or_default();
276 requested.capture_only(names.into_iter().map(|n| n.into()));
277 self.config.store_put(requested);
278 self
279 }
280 /// Set the [`StalledStreamProtectionConfig`](crate::config::StalledStreamProtectionConfig)
281 /// to configure protection for stalled streams.
282 pub fn stalled_stream_protection(mut self, stalled_stream_protection_config: crate::config::StalledStreamProtectionConfig) -> Self {
283 self.set_stalled_stream_protection(::std::option::Option::Some(stalled_stream_protection_config));
284 self
285 }
286 /// Set the [`StalledStreamProtectionConfig`](crate::config::StalledStreamProtectionConfig)
287 /// to configure protection for stalled streams.
288 pub fn set_stalled_stream_protection(
289 &mut self,
290 stalled_stream_protection_config: ::std::option::Option<crate::config::StalledStreamProtectionConfig>,
291 ) -> &mut Self {
292 self.config.store_or_unset(stalled_stream_protection_config);
293 self
294 }
295 /// Sets the idempotency token provider to use for service calls that require tokens.
296 pub fn idempotency_token_provider(
297 mut self,
298 idempotency_token_provider: impl ::std::convert::Into<crate::idempotency_token::IdempotencyTokenProvider>,
299 ) -> Self {
300 self.set_idempotency_token_provider(::std::option::Option::Some(idempotency_token_provider.into()));
301 self
302 }
303 /// Sets the idempotency token provider to use for service calls that require tokens.
304 pub fn set_idempotency_token_provider(
305 &mut self,
306 idempotency_token_provider: ::std::option::Option<crate::idempotency_token::IdempotencyTokenProvider>,
307 ) -> &mut Self {
308 self.config.store_or_unset(idempotency_token_provider);
309 self
310 }
311 /// Sets the HTTP client to use when making requests.
312 ///
313 /// # Examples
314 /// ```no_run
315 /// # #[cfg(test)]
316 /// # mod tests {
317 /// # #[test]
318 /// # fn example() {
319 /// use std::time::Duration;
320 /// use aws_sdk_s3::config::Config;
321 /// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
322 ///
323 /// let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
324 /// .with_webpki_roots()
325 /// .https_only()
326 /// .enable_http1()
327 /// .enable_http2()
328 /// .build();
329 /// let hyper_client = HyperClientBuilder::new().build(https_connector);
330 ///
331 /// // This connector can then be given to a generated service Config
332 /// let config = my_service_client::Config::builder()
333 /// .endpoint_url("https://example.com")
334 /// .http_client(hyper_client)
335 /// .build();
336 /// let client = my_service_client::Client::from_conf(config);
337 /// # }
338 /// # }
339 /// ```
340 pub fn http_client(mut self, http_client: impl crate::config::HttpClient + 'static) -> Self {
341 self.set_http_client(::std::option::Option::Some(crate::config::IntoShared::into_shared(http_client)));
342 self
343 }
344
345 /// Sets the HTTP client to use when making requests.
346 ///
347 /// # Examples
348 /// ```no_run
349 /// # #[cfg(test)]
350 /// # mod tests {
351 /// # #[test]
352 /// # fn example() {
353 /// use std::time::Duration;
354 /// use aws_sdk_s3::config::{Builder, Config};
355 /// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
356 ///
357 /// fn override_http_client(builder: &mut Builder) {
358 /// let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
359 /// .with_webpki_roots()
360 /// .https_only()
361 /// .enable_http1()
362 /// .enable_http2()
363 /// .build();
364 /// let hyper_client = HyperClientBuilder::new().build(https_connector);
365 /// builder.set_http_client(Some(hyper_client));
366 /// }
367 ///
368 /// let mut builder = aws_sdk_s3::Config::builder();
369 /// override_http_client(&mut builder);
370 /// let config = builder.build();
371 /// # }
372 /// # }
373 /// ```
374 pub fn set_http_client(&mut self, http_client: Option<crate::config::SharedHttpClient>) -> &mut Self {
375 self.runtime_components.set_http_client(http_client);
376 self
377 }
378 /// Adds an auth scheme to the builder
379 ///
380 /// If `auth_scheme` has an existing [AuthSchemeId](aws_smithy_runtime_api::client::auth::AuthSchemeId) in the runtime, the current identity
381 /// resolver and signer for that scheme will be replaced by those from `auth_scheme`.
382 ///
383 /// _Important:_ When introducing a custom auth scheme, ensure you override either
384 /// [`Self::auth_scheme_resolver`] or [`Self::set_auth_scheme_resolver`]
385 /// so that the custom auth scheme is included in the list of resolved auth scheme options.
386 /// [The default auth scheme resolver](crate::config::auth::DefaultAuthSchemeResolver) will not recognize your custom auth scheme.
387 ///
388 /// # Examples
389 /// ```no_run
390 /// # use aws_smithy_runtime_api::{
391 /// # box_error::BoxError,
392 /// # client::{
393 /// # auth::{
394 /// # AuthScheme, AuthSchemeEndpointConfig, AuthSchemeId, AuthSchemeOption,
395 /// # AuthSchemeOptionsFuture, Sign,
396 /// # },
397 /// # identity::{Identity, IdentityFuture, ResolveIdentity, SharedIdentityResolver},
398 /// # orchestrator::HttpRequest,
399 /// # runtime_components::{GetIdentityResolver, RuntimeComponents},
400 /// # },
401 /// # shared::IntoShared,
402 /// # };
403 /// # use aws_smithy_types::config_bag::ConfigBag;
404 /// // Auth scheme with customer identity resolver and signer
405 /// #[derive(Debug)]
406 /// struct CustomAuthScheme {
407 /// id: AuthSchemeId,
408 /// identity_resolver: SharedIdentityResolver,
409 /// signer: CustomSigner,
410 /// }
411 /// impl Default for CustomAuthScheme {
412 /// fn default() -> Self {
413 /// Self {
414 /// id: AuthSchemeId::new("custom"),
415 /// identity_resolver: CustomIdentityResolver.into_shared(),
416 /// signer: CustomSigner,
417 /// }
418 /// }
419 /// }
420 /// impl AuthScheme for CustomAuthScheme {
421 /// fn scheme_id(&self) -> AuthSchemeId {
422 /// self.id.clone()
423 /// }
424 /// fn identity_resolver(
425 /// &self,
426 /// _identity_resolvers: &dyn GetIdentityResolver,
427 /// ) -> Option<SharedIdentityResolver> {
428 /// Some(self.identity_resolver.clone())
429 /// }
430 /// fn signer(&self) -> &dyn Sign {
431 /// &self.signer
432 /// }
433 /// }
434 ///
435 /// #[derive(Debug, Default)]
436 /// struct CustomSigner;
437 /// impl Sign for CustomSigner {
438 /// fn sign_http_request(
439 /// &self,
440 /// _request: &mut HttpRequest,
441 /// _identity: &Identity,
442 /// _auth_scheme_endpoint_config: AuthSchemeEndpointConfig<'_>,
443 /// _runtime_components: &RuntimeComponents,
444 /// _config_bag: &ConfigBag,
445 /// ) -> Result<(), BoxError> {
446 /// // --snip--
447 /// # todo!()
448 /// }
449 /// }
450 ///
451 /// #[derive(Debug)]
452 /// struct CustomIdentityResolver;
453 /// impl ResolveIdentity for CustomIdentityResolver {
454 /// fn resolve_identity<'a>(
455 /// &'a self,
456 /// _runtime_components: &'a RuntimeComponents,
457 /// _config_bag: &'a ConfigBag,
458 /// ) -> IdentityFuture<'a> {
459 /// // --snip--
460 /// # todo!()
461 /// }
462 /// }
463 ///
464 /// // Auth scheme resolver that favors `CustomAuthScheme`
465 /// #[derive(Debug)]
466 /// struct CustomAuthSchemeResolver;
467 /// impl aws_sdk_s3::config::auth::ResolveAuthScheme for CustomAuthSchemeResolver {
468 /// fn resolve_auth_scheme<'a>(
469 /// &'a self,
470 /// _params: &'a aws_sdk_s3::config::auth::Params,
471 /// _cfg: &'a ConfigBag,
472 /// _runtime_components: &'a RuntimeComponents,
473 /// ) -> AuthSchemeOptionsFuture<'a> {
474 /// AuthSchemeOptionsFuture::ready(Ok(vec![AuthSchemeOption::from(AuthSchemeId::new(
475 /// "custom",
476 /// ))]))
477 /// }
478 /// }
479 ///
480 /// let config = aws_sdk_s3::Config::builder()
481 /// .push_auth_scheme(CustomAuthScheme::default())
482 /// .auth_scheme_resolver(CustomAuthSchemeResolver)
483 /// // other configurations
484 /// .build();
485 /// ```
486 pub fn push_auth_scheme(mut self, auth_scheme: impl ::aws_smithy_runtime_api::client::auth::AuthScheme + 'static) -> Self {
487 self.runtime_components.push_auth_scheme(auth_scheme);
488 self
489 }
490
491 /// Set the auth scheme resolver for the builder
492 ///
493 /// # Examples
494 /// ```no_run
495 /// # use aws_smithy_runtime_api::{
496 /// # client::{
497 /// # auth::AuthSchemeOptionsFuture,
498 /// # runtime_components::RuntimeComponents,
499 /// # },
500 /// # };
501 /// # use aws_smithy_types::config_bag::ConfigBag;
502 /// #[derive(Debug)]
503 /// struct CustomAuthSchemeResolver;
504 /// impl aws_sdk_s3::config::auth::ResolveAuthScheme for CustomAuthSchemeResolver {
505 /// fn resolve_auth_scheme<'a>(
506 /// &'a self,
507 /// _params: &'a aws_sdk_s3::config::auth::Params,
508 /// _cfg: &'a ConfigBag,
509 /// _runtime_components: &'a RuntimeComponents,
510 /// ) -> AuthSchemeOptionsFuture<'a> {
511 /// // --snip--
512 /// # todo!()
513 /// }
514 /// }
515 ///
516 /// let config = aws_sdk_s3::Config::builder()
517 /// .auth_scheme_resolver(CustomAuthSchemeResolver)
518 /// // other configurations
519 /// .build();
520 /// ```
521 pub fn auth_scheme_resolver(mut self, auth_scheme_resolver: impl crate::config::auth::ResolveAuthScheme + 'static) -> Self {
522 self.set_auth_scheme_resolver(auth_scheme_resolver);
523 self
524 }
525
526 /// Set the auth scheme resolver for the builder
527 ///
528 /// # Examples
529 /// See an example for [`Self::auth_scheme_resolver`].
530 pub fn set_auth_scheme_resolver(&mut self, auth_scheme_resolver: impl crate::config::auth::ResolveAuthScheme + 'static) -> &mut Self {
531 self.runtime_components
532 .set_auth_scheme_option_resolver(::std::option::Option::Some(auth_scheme_resolver.into_shared_resolver()));
533 self
534 }
535
536 /// Enable no authentication regardless of what authentication mechanisms operations support
537 ///
538 /// This adds [NoAuthScheme](aws_smithy_runtime::client::auth::no_auth::NoAuthScheme) as a fallback
539 /// and the auth scheme resolver will use it when no other auth schemes are applicable.
540 pub fn allow_no_auth(mut self) -> Self {
541 self.set_allow_no_auth();
542 self
543 }
544
545 /// Enable no authentication regardless of what authentication mechanisms operations support
546 ///
547 /// This adds [NoAuthScheme](aws_smithy_runtime::client::auth::no_auth::NoAuthScheme) as a fallback
548 /// and the auth scheme resolver will use it when no other auth schemes are applicable.
549 pub fn set_allow_no_auth(&mut self) -> &mut Self {
550 self.push_runtime_plugin(::aws_smithy_runtime::client::auth::no_auth::NoAuthRuntimePluginV2::new().into_shared());
551 self
552 }
553 /// Set the auth scheme preference for an auth scheme resolver
554 /// (typically the default auth scheme resolver).
555 ///
556 /// Each operation has a predefined order of auth schemes, as determined by the service,
557 /// for auth scheme resolution. By using the auth scheme preference, customers
558 /// can reorder the schemes resolved by the auth scheme resolver.
559 ///
560 /// The preference list is intended as a hint rather than a strict override.
561 /// Any schemes not present in the originally resolved auth schemes will be ignored.
562 ///
563 /// # Examples
564 ///
565 /// ```no_run
566 /// # use aws_smithy_runtime_api::client::auth::AuthSchemeId;
567 /// let config = aws_sdk_s3::Config::builder()
568 /// .auth_scheme_preference([AuthSchemeId::from("scheme1"), AuthSchemeId::from("scheme2")])
569 /// // ...
570 /// .build();
571 /// let client = aws_sdk_s3::Client::from_conf(config);
572 /// ```
573
574 pub fn auth_scheme_preference(
575 mut self,
576 preference: impl ::std::convert::Into<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>,
577 ) -> Self {
578 self.set_auth_scheme_preference(::std::option::Option::Some(preference.into()));
579 self
580 }
581
582 /// Set the auth scheme preference for an auth scheme resolver
583 /// (typically the default auth scheme resolver).
584 ///
585 /// Each operation has a predefined order of auth schemes, as determined by the service,
586 /// for auth scheme resolution. By using the auth scheme preference, customers
587 /// can reorder the schemes resolved by the auth scheme resolver.
588 ///
589 /// The preference list is intended as a hint rather than a strict override.
590 /// Any schemes not present in the originally resolved auth schemes will be ignored.
591 ///
592 /// # Examples
593 ///
594 /// ```no_run
595 /// # use aws_smithy_runtime_api::client::auth::AuthSchemeId;
596 /// let config = aws_sdk_s3::Config::builder()
597 /// .auth_scheme_preference([AuthSchemeId::from("scheme1"), AuthSchemeId::from("scheme2")])
598 /// // ...
599 /// .build();
600 /// let client = aws_sdk_s3::Client::from_conf(config);
601 /// ```
602
603 pub fn set_auth_scheme_preference(
604 &mut self,
605 preference: ::std::option::Option<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>,
606 ) -> &mut Self {
607 self.config.store_or_unset(preference);
608 self
609 }
610 /// Forces this client to use path-style addressing for buckets.
611 pub fn force_path_style(mut self, force_path_style: impl Into<bool>) -> Self {
612 self.set_force_path_style(Some(force_path_style.into()));
613 self
614 }
615 /// Forces this client to use path-style addressing for buckets.
616 pub fn set_force_path_style(&mut self, force_path_style: Option<bool>) -> &mut Self {
617 self.config.store_or_unset(force_path_style.map(crate::config::ForcePathStyle));
618 self
619 }
620
621 /// Enables this client to use an ARN's region when constructing an endpoint instead of the client's configured region.
622 pub fn use_arn_region(mut self, use_arn_region: impl Into<bool>) -> Self {
623 self.set_use_arn_region(Some(use_arn_region.into()));
624 self
625 }
626 /// Enables this client to use an ARN's region when constructing an endpoint instead of the client's configured region.
627 pub fn set_use_arn_region(&mut self, use_arn_region: Option<bool>) -> &mut Self {
628 self.config.store_or_unset(use_arn_region.map(crate::config::UseArnRegion));
629 self
630 }
631
632 /// Disables this client's usage of Multi-Region Access Points.
633 pub fn disable_multi_region_access_points(mut self, disable_multi_region_access_points: impl Into<bool>) -> Self {
634 self.set_disable_multi_region_access_points(Some(disable_multi_region_access_points.into()));
635 self
636 }
637 /// Disables this client's usage of Multi-Region Access Points.
638 pub fn set_disable_multi_region_access_points(&mut self, disable_multi_region_access_points: Option<bool>) -> &mut Self {
639 self.config
640 .store_or_unset(disable_multi_region_access_points.map(crate::config::DisableMultiRegionAccessPoints));
641 self
642 }
643
644 /// Enables this client to use S3 Transfer Acceleration endpoints.
645 pub fn accelerate(mut self, accelerate: impl Into<bool>) -> Self {
646 self.set_accelerate(Some(accelerate.into()));
647 self
648 }
649 /// Enables this client to use S3 Transfer Acceleration endpoints.
650 pub fn set_accelerate(&mut self, accelerate: Option<bool>) -> &mut Self {
651 self.config.store_or_unset(accelerate.map(crate::config::Accelerate));
652 self
653 }
654
655 /// Disables this client's usage of Session Auth for S3Express buckets and reverts to using conventional SigV4 for those.
656 pub fn disable_s3_express_session_auth(mut self, disable_s3_express_session_auth: impl Into<bool>) -> Self {
657 self.set_disable_s3_express_session_auth(Some(disable_s3_express_session_auth.into()));
658 self
659 }
660 /// Disables this client's usage of Session Auth for S3Express buckets and reverts to using conventional SigV4 for those.
661 pub fn set_disable_s3_express_session_auth(&mut self, disable_s3_express_session_auth: Option<bool>) -> &mut Self {
662 self.config
663 .store_or_unset(disable_s3_express_session_auth.map(crate::config::DisableS3ExpressSessionAuth));
664 self
665 }
666 /// Sets the endpoint resolver to use when making requests.
667 ///
668 ///
669 /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
670 /// rules for `aws_sdk_s3`.
671 ///
672 ///
673 /// Note: setting an endpoint resolver will replace any endpoint URL that has been set.
674 /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to
675 /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`].
676 ///
677 /// # Examples
678 /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production.
679 /// ```no_run
680 /// use aws_sdk_s3::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint};
681 /// #[derive(Debug)]
682 /// struct StageResolver { stage: String }
683 /// impl ResolveEndpoint for StageResolver {
684 /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> {
685 /// let stage = &self.stage;
686 /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build()))
687 /// }
688 /// }
689 /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() };
690 /// let config = aws_sdk_s3::Config::builder().endpoint_resolver(resolver).build();
691 /// let client = aws_sdk_s3::Client::from_conf(config);
692 /// ```
693 pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self {
694 self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver()));
695 self
696 }
697
698 /// Sets the endpoint resolver to use when making requests.
699 ///
700 ///
701 /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
702 /// rules for `aws_sdk_s3`.
703 ///
704 pub fn set_endpoint_resolver(
705 &mut self,
706 endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>,
707 ) -> &mut Self {
708 self.runtime_components.set_endpoint_resolver(endpoint_resolver);
709 self
710 }
711 /// Set the retry_config for the builder
712 ///
713 /// # Examples
714 /// ```no_run
715 /// use aws_sdk_s3::config::Config;
716 /// use aws_sdk_s3::config::retry::RetryConfig;
717 ///
718 /// let retry_config = RetryConfig::standard().with_max_attempts(5);
719 /// let config = Config::builder().retry_config(retry_config).build();
720 /// ```
721 ///
722 /// # Retry token bucket
723 ///
724 /// [`RetryConfig`](::aws_smithy_types::retry::RetryConfig) controls *how many* times to retry and *how long* to back
725 /// off. Retries are **also** gated by a retry token bucket (also called the retry quota) that
726 /// is shared across a [`RetryPartition`](::aws_smithy_runtime::client::retries::RetryPartition). To configure the token bucket — for
727 /// example, to set
728 /// its capacity or to give a workload its own bucket — see [`Self::retry_partition`] and
729 /// [`RetryPartition::custom`](::aws_smithy_runtime::client::retries::RetryPartition::custom).
730 pub fn retry_config(mut self, retry_config: ::aws_smithy_types::retry::RetryConfig) -> Self {
731 self.set_retry_config(Some(retry_config));
732 self
733 }
734
735 /// Set the retry_config for the builder
736 ///
737 /// # Examples
738 /// ```no_run
739 /// use aws_sdk_s3::config::{Builder, Config};
740 /// use aws_sdk_s3::config::retry::RetryConfig;
741 ///
742 /// fn disable_retries(builder: &mut Builder) {
743 /// let retry_config = RetryConfig::standard().with_max_attempts(1);
744 /// builder.set_retry_config(Some(retry_config));
745 /// }
746 ///
747 /// let mut builder = Config::builder();
748 /// disable_retries(&mut builder);
749 /// let config = builder.build();
750 /// ```
751 pub fn set_retry_config(&mut self, retry_config: ::std::option::Option<::aws_smithy_types::retry::RetryConfig>) -> &mut Self {
752 retry_config.map(|r| self.config.store_put(r));
753 self
754 }
755 /// Set the sleep_impl for the builder
756 ///
757 /// # Examples
758 ///
759 /// ```no_run
760 /// use aws_sdk_s3::config::{AsyncSleep, Config, SharedAsyncSleep, Sleep};
761 ///
762 /// #[derive(Debug)]
763 /// pub struct ForeverSleep;
764 ///
765 /// impl AsyncSleep for ForeverSleep {
766 /// fn sleep(&self, duration: std::time::Duration) -> Sleep {
767 /// Sleep::new(std::future::pending())
768 /// }
769 /// }
770 ///
771 /// let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
772 /// let config = Config::builder().sleep_impl(sleep_impl).build();
773 /// ```
774 pub fn sleep_impl(mut self, sleep_impl: impl crate::config::AsyncSleep + 'static) -> Self {
775 self.set_sleep_impl(Some(::aws_smithy_runtime_api::shared::IntoShared::into_shared(sleep_impl)));
776 self
777 }
778
779 /// Set the sleep_impl for the builder
780 ///
781 /// # Examples
782 ///
783 /// ```no_run
784 /// use aws_sdk_s3::config::{AsyncSleep, Builder, Config, SharedAsyncSleep, Sleep};
785 ///
786 /// #[derive(Debug)]
787 /// pub struct ForeverSleep;
788 ///
789 /// impl AsyncSleep for ForeverSleep {
790 /// fn sleep(&self, duration: std::time::Duration) -> Sleep {
791 /// Sleep::new(std::future::pending())
792 /// }
793 /// }
794 ///
795 /// fn set_never_ending_sleep_impl(builder: &mut Builder) {
796 /// let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
797 /// builder.set_sleep_impl(Some(sleep_impl));
798 /// }
799 ///
800 /// let mut builder = Config::builder();
801 /// set_never_ending_sleep_impl(&mut builder);
802 /// let config = builder.build();
803 /// ```
804 pub fn set_sleep_impl(&mut self, sleep_impl: ::std::option::Option<crate::config::SharedAsyncSleep>) -> &mut Self {
805 self.runtime_components.set_sleep_impl(sleep_impl);
806 self
807 }
808 /// Set the timeout_config for the builder
809 ///
810 /// # Examples
811 ///
812 /// ```no_run
813 /// # use std::time::Duration;
814 /// use aws_sdk_s3::config::Config;
815 /// use aws_sdk_s3::config::timeout::TimeoutConfig;
816 ///
817 /// let timeout_config = TimeoutConfig::builder()
818 /// .operation_attempt_timeout(Duration::from_secs(1))
819 /// .build();
820 /// let config = Config::builder().timeout_config(timeout_config).build();
821 /// ```
822 pub fn timeout_config(mut self, timeout_config: ::aws_smithy_types::timeout::TimeoutConfig) -> Self {
823 self.set_timeout_config(Some(timeout_config));
824 self
825 }
826
827 /// Set the timeout_config for the builder.
828 ///
829 /// Setting this to `None` has no effect if another source of configuration has set timeouts. If you
830 /// are attempting to disable timeouts, use [`TimeoutConfig::disabled`](::aws_smithy_types::timeout::TimeoutConfig::disabled)
831 ///
832 ///
833 /// # Examples
834 ///
835 /// ```no_run
836 /// # use std::time::Duration;
837 /// use aws_sdk_s3::config::{Builder, Config};
838 /// use aws_sdk_s3::config::timeout::TimeoutConfig;
839 ///
840 /// fn set_request_timeout(builder: &mut Builder) {
841 /// let timeout_config = TimeoutConfig::builder()
842 /// .operation_attempt_timeout(Duration::from_secs(1))
843 /// .build();
844 /// builder.set_timeout_config(Some(timeout_config));
845 /// }
846 ///
847 /// let mut builder = Config::builder();
848 /// set_request_timeout(&mut builder);
849 /// let config = builder.build();
850 /// ```
851 pub fn set_timeout_config(&mut self, timeout_config: ::std::option::Option<::aws_smithy_types::timeout::TimeoutConfig>) -> &mut Self {
852 // passing None has no impact.
853 let Some(mut timeout_config) = timeout_config else { return self };
854
855 if let Some(base) = self.config.load::<::aws_smithy_types::timeout::TimeoutConfig>() {
856 timeout_config.take_defaults_from(base);
857 }
858 self.config.store_put(timeout_config);
859 self
860 }
861 /// Set the partition for retry-related state. When clients share a retry partition, they will
862 /// also share components such as token buckets and client rate limiters.
863 /// See the [`RetryPartition`](::aws_smithy_runtime::client::retries::RetryPartition) documentation for more details.
864 ///
865 /// # Default Behavior
866 ///
867 /// When no retry partition is explicitly set, the SDK automatically creates a default retry partition named `s3`
868 /// (or `s3-<region>` if a region is configured).
869 /// All S3 clients without an explicit retry partition will share this default partition.
870 ///
871 /// # Notes
872 ///
873 /// - This is an advanced setting. A common reason to set it is to size or isolate the retry
874 /// token bucket — for example, giving a high-throughput workload its own bucket. Otherwise
875 /// most users won't need to modify it.
876 /// - A configured client rate limiter has no effect unless [`RetryConfig::adaptive`](::aws_smithy_types::retry::RetryConfig::adaptive) is used.
877 ///
878 /// # Examples
879 ///
880 /// Creating a custom retry partition with a token bucket:
881 /// ```no_run
882 /// use aws_sdk_s3::config::Config;
883 /// use aws_sdk_s3::config::retry::{RetryPartition, TokenBucket};
884 ///
885 /// let token_bucket = TokenBucket::new(10);
886 /// let config = Config::builder()
887 /// .retry_partition(RetryPartition::custom("custom")
888 /// .token_bucket(token_bucket)
889 /// .build()
890 /// )
891 /// .build();
892 /// ```
893 ///
894 /// Sizing the retry token bucket (for example, for a high-throughput workload), or giving a
895 /// workload its own bucket:
896 /// ```no_run
897 /// use aws_sdk_s3::config::Config;
898 /// use aws_sdk_s3::config::retry::{RetryPartition, TokenBucket};
899 ///
900 /// let config = Config::builder()
901 /// .retry_partition(
902 /// RetryPartition::custom("high-throughput")
903 /// .token_bucket(TokenBucket::builder().capacity(5000).build())
904 /// .build(),
905 /// )
906 /// .build();
907 /// ```
908 ///
909 /// Configuring a client rate limiter with adaptive retry mode:
910 /// ```no_run
911 /// use aws_sdk_s3::config::Config;
912 /// use aws_sdk_s3::config::retry::{ClientRateLimiter, RetryConfig, RetryPartition};
913 ///
914 /// let client_rate_limiter = ClientRateLimiter::new(10.0);
915 /// let config = Config::builder()
916 /// .retry_partition(RetryPartition::custom("custom")
917 /// .client_rate_limiter(client_rate_limiter)
918 /// .build()
919 /// )
920 /// .retry_config(RetryConfig::adaptive())
921 /// .build();
922 /// ```
923 pub fn retry_partition(mut self, retry_partition: ::aws_smithy_runtime::client::retries::RetryPartition) -> Self {
924 self.set_retry_partition(Some(retry_partition));
925 self
926 }
927 /// Like [`Self::retry_partition`], but takes a mutable reference to the builder and an optional `RetryPartition`
928 pub fn set_retry_partition(
929 &mut self,
930 retry_partition: ::std::option::Option<::aws_smithy_runtime::client::retries::RetryPartition>,
931 ) -> &mut Self {
932 retry_partition.map(|r| self.config.store_put(r));
933 self
934 }
935 /// Set the identity cache for auth.
936 ///
937 /// The identity cache defaults to a lazy caching implementation that will resolve
938 /// an identity when it is requested, and place it in the cache thereafter. Subsequent
939 /// requests will take the value from the cache while it is still valid. Once it expires,
940 /// the next request will result in refreshing the identity.
941 ///
942 /// This configuration allows you to disable or change the default caching mechanism.
943 /// To use a custom caching mechanism, implement the [`ResolveCachedIdentity`](crate::config::ResolveCachedIdentity)
944 /// trait and pass that implementation into this function.
945 ///
946 /// # Examples
947 ///
948 /// Disabling identity caching:
949 /// ```no_run
950 /// use aws_sdk_s3::config::IdentityCache;
951 ///
952 /// let config = aws_sdk_s3::Config::builder()
953 /// .identity_cache(IdentityCache::no_cache())
954 /// // ...
955 /// .build();
956 /// let client = aws_sdk_s3::Client::from_conf(config);
957 /// ```
958 ///
959 /// Customizing lazy caching:
960 /// ```no_run
961 /// use aws_sdk_s3::config::IdentityCache;
962 /// use std::time::Duration;
963 ///
964 /// let config = aws_sdk_s3::Config::builder()
965 /// .identity_cache(
966 /// IdentityCache::lazy()
967 /// // change the load timeout to 10 seconds
968 /// .load_timeout(Duration::from_secs(10))
969 /// .build()
970 /// )
971 /// // ...
972 /// .build();
973 /// let client = aws_sdk_s3::Client::from_conf(config);
974 /// ```
975 ///
976 pub fn identity_cache(mut self, identity_cache: impl crate::config::ResolveCachedIdentity + 'static) -> Self {
977 self.set_identity_cache(identity_cache);
978 self
979 }
980
981 /// Set the identity cache for auth.
982 ///
983 /// The identity cache defaults to a lazy caching implementation that will resolve
984 /// an identity when it is requested, and place it in the cache thereafter. Subsequent
985 /// requests will take the value from the cache while it is still valid. Once it expires,
986 /// the next request will result in refreshing the identity.
987 ///
988 /// This configuration allows you to disable or change the default caching mechanism.
989 /// To use a custom caching mechanism, implement the [`ResolveCachedIdentity`](crate::config::ResolveCachedIdentity)
990 /// trait and pass that implementation into this function.
991 ///
992 /// # Examples
993 ///
994 /// Disabling identity caching:
995 /// ```no_run
996 /// use aws_sdk_s3::config::IdentityCache;
997 ///
998 /// let config = aws_sdk_s3::Config::builder()
999 /// .identity_cache(IdentityCache::no_cache())
1000 /// // ...
1001 /// .build();
1002 /// let client = aws_sdk_s3::Client::from_conf(config);
1003 /// ```
1004 ///
1005 /// Customizing lazy caching:
1006 /// ```no_run
1007 /// use aws_sdk_s3::config::IdentityCache;
1008 /// use std::time::Duration;
1009 ///
1010 /// let config = aws_sdk_s3::Config::builder()
1011 /// .identity_cache(
1012 /// IdentityCache::lazy()
1013 /// // change the load timeout to 10 seconds
1014 /// .load_timeout(Duration::from_secs(10))
1015 /// .build()
1016 /// )
1017 /// // ...
1018 /// .build();
1019 /// let client = aws_sdk_s3::Client::from_conf(config);
1020 /// ```
1021 ///
1022 pub fn set_identity_cache(&mut self, identity_cache: impl crate::config::ResolveCachedIdentity + 'static) -> &mut Self {
1023 self.runtime_components.set_identity_cache(::std::option::Option::Some(identity_cache));
1024 self
1025 }
1026 /// Add an [interceptor](crate::config::Intercept) that runs at specific stages of the request execution pipeline.
1027 ///
1028 /// Interceptors targeted at a certain stage are executed according to the pre-defined priority.
1029 /// The SDK provides a default set of interceptors. An interceptor configured by this method
1030 /// will run after those default interceptors.
1031 ///
1032 /// # Examples
1033 /// ```no_run
1034 /// # fn example() {
1035 /// use aws_smithy_runtime_api::box_error::BoxError;
1036 /// use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
1037 /// use aws_smithy_runtime_api::client::interceptors::Intercept;
1038 /// use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
1039 /// use aws_smithy_types::config_bag::ConfigBag;
1040 /// use aws_sdk_s3::config::Config;
1041 /// use ::http::uri::Uri;
1042 ///
1043 /// fn base_url() -> String {
1044 /// // ...
1045 /// # String::new()
1046 /// }
1047 ///
1048 /// #[derive(Debug)]
1049 /// pub struct UriModifierInterceptor;
1050 /// impl Intercept for UriModifierInterceptor {
1051 /// fn name(&self) -> &'static str {
1052 /// "UriModifierInterceptor"
1053 /// }
1054 /// fn modify_before_signing(
1055 /// &self,
1056 /// context: &mut BeforeTransmitInterceptorContextMut<'_>,
1057 /// _runtime_components: &RuntimeComponents,
1058 /// _cfg: &mut ConfigBag,
1059 /// ) -> Result<(), BoxError> {
1060 /// let request = context.request_mut();
1061 /// let uri = format!("{}{}", base_url(), request.uri());
1062 /// *request.uri_mut() = uri.parse::<Uri>()?.into();
1063 ///
1064 /// Ok(())
1065 /// }
1066 /// }
1067 ///
1068 /// let config = Config::builder()
1069 /// .interceptor(UriModifierInterceptor)
1070 /// .build();
1071 /// # }
1072 /// ```
1073 pub fn interceptor(mut self, interceptor: impl crate::config::Intercept + 'static) -> Self {
1074 self.push_interceptor(crate::config::SharedInterceptor::new(interceptor));
1075 self
1076 }
1077
1078 /// Like [`Self::interceptor`], but takes a [`SharedInterceptor`](crate::config::SharedInterceptor).
1079 pub fn push_interceptor(&mut self, interceptor: crate::config::SharedInterceptor) -> &mut Self {
1080 self.runtime_components.push_interceptor(interceptor);
1081 self
1082 }
1083
1084 /// Set [`SharedInterceptor`](crate::config::SharedInterceptor)s for the builder.
1085 pub fn set_interceptors(&mut self, interceptors: impl IntoIterator<Item = crate::config::SharedInterceptor>) -> &mut Self {
1086 self.runtime_components.set_interceptors(interceptors.into_iter());
1087 self
1088 }
1089 /// Sets the time source used for this service
1090 pub fn time_source(mut self, time_source: impl ::aws_smithy_async::time::TimeSource + 'static) -> Self {
1091 self.set_time_source(::std::option::Option::Some(::aws_smithy_runtime_api::shared::IntoShared::into_shared(
1092 time_source,
1093 )));
1094 self
1095 }
1096 /// Sets the time source used for this service
1097 pub fn set_time_source(&mut self, time_source: ::std::option::Option<::aws_smithy_async::time::SharedTimeSource>) -> &mut Self {
1098 self.runtime_components.set_time_source(time_source);
1099 self
1100 }
1101 /// Add type implementing [`ClassifyRetry`](::aws_smithy_runtime_api::client::retries::classifiers::ClassifyRetry) that will be used by the
1102 /// [`RetryStrategy`](::aws_smithy_runtime_api::client::retries::RetryStrategy) to determine what responses should be retried.
1103 ///
1104 /// A retry classifier configured by this method will run according to its [priority](::aws_smithy_runtime_api::client::retries::classifiers::RetryClassifierPriority).
1105 ///
1106 /// # Examples
1107 /// ```no_run
1108 /// # fn example() {
1109 /// use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
1110 /// use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
1111 /// use aws_smithy_runtime_api::client::retries::classifiers::{
1112 /// ClassifyRetry, RetryAction, RetryClassifierPriority,
1113 /// };
1114 /// use aws_smithy_types::error::metadata::ProvideErrorMetadata;
1115 /// use aws_smithy_types::retry::ErrorKind;
1116 /// use std::error::Error as StdError;
1117 /// use std::marker::PhantomData;
1118 /// use std::fmt;
1119 /// use aws_sdk_s3::config::Config;
1120 /// # #[derive(Debug)]
1121 /// # struct SomeOperationError {}
1122 /// # impl StdError for SomeOperationError {}
1123 /// # impl fmt::Display for SomeOperationError {
1124 /// # fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { todo!() }
1125 /// # }
1126 /// # impl ProvideErrorMetadata for SomeOperationError {
1127 /// # fn meta(&self) -> &aws_sdk_s3::error::ErrorMetadata { todo!() }
1128 /// # }
1129 ///
1130 /// const RETRYABLE_ERROR_CODES: &[&str] = &[
1131 /// // List error codes to be retried here...
1132 /// ];
1133 ///
1134 /// // When classifying at an operation's error type, classifiers require a generic parameter.
1135 /// // When classifying the HTTP response alone, no generic is needed.
1136 /// #[derive(Debug, Default)]
1137 /// pub struct ExampleErrorCodeClassifier<E> {
1138 /// _inner: PhantomData<E>,
1139 /// }
1140 ///
1141 /// impl<E> ExampleErrorCodeClassifier<E> {
1142 /// pub fn new() -> Self {
1143 /// Self {
1144 /// _inner: PhantomData,
1145 /// }
1146 /// }
1147 /// }
1148 ///
1149 /// impl<E> ClassifyRetry for ExampleErrorCodeClassifier<E>
1150 /// where
1151 /// // Adding a trait bound for ProvideErrorMetadata allows us to inspect the error code.
1152 /// E: StdError + ProvideErrorMetadata + Send + Sync + 'static,
1153 /// {
1154 /// fn classify_retry(&self, ctx: &InterceptorContext) -> RetryAction {
1155 /// // Check for a result
1156 /// let output_or_error = ctx.output_or_error();
1157 /// // Check for an error
1158 /// let error = match output_or_error {
1159 /// Some(Ok(_)) | None => return RetryAction::NoActionIndicated,
1160 /// Some(Err(err)) => err,
1161 /// };
1162 ///
1163 /// // Downcast the generic error and extract the code
1164 /// let error_code = OrchestratorError::as_operation_error(error)
1165 /// .and_then(|err| err.downcast_ref::<E>())
1166 /// .and_then(|err| err.code());
1167 ///
1168 /// // If this error's code is in our list, return an action that tells the RetryStrategy to retry this request.
1169 /// if let Some(error_code) = error_code {
1170 /// if RETRYABLE_ERROR_CODES.contains(&error_code) {
1171 /// return RetryAction::transient_error();
1172 /// }
1173 /// }
1174 ///
1175 /// // Otherwise, return that no action is indicated i.e. that this classifier doesn't require a retry.
1176 /// // Another classifier may still classify this response as retryable.
1177 /// RetryAction::NoActionIndicated
1178 /// }
1179 ///
1180 /// fn name(&self) -> &'static str { "Example Error Code Classifier" }
1181 /// }
1182 ///
1183 /// let config = Config::builder()
1184 /// .retry_classifier(ExampleErrorCodeClassifier::<SomeOperationError>::new())
1185 /// .build();
1186 /// # }
1187 /// ```
1188 pub fn retry_classifier(
1189 mut self,
1190 retry_classifier: impl ::aws_smithy_runtime_api::client::retries::classifiers::ClassifyRetry + 'static,
1191 ) -> Self {
1192 self.push_retry_classifier(::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier::new(
1193 retry_classifier,
1194 ));
1195 self
1196 }
1197
1198 /// Like [`Self::retry_classifier`], but takes a [`SharedRetryClassifier`](::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier).
1199 pub fn push_retry_classifier(
1200 &mut self,
1201 retry_classifier: ::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier,
1202 ) -> &mut Self {
1203 self.runtime_components.push_retry_classifier(retry_classifier);
1204 self
1205 }
1206
1207 /// Set [`SharedRetryClassifier`](::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier)s for the builder, replacing any that
1208 /// were previously set.
1209 pub fn set_retry_classifiers(
1210 &mut self,
1211 retry_classifiers: impl IntoIterator<Item = ::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier>,
1212 ) -> &mut Self {
1213 self.runtime_components.set_retry_classifiers(retry_classifiers.into_iter());
1214 self
1215 }
1216 /// Sets the name of the app that is using the client.
1217 ///
1218 /// This _optional_ name is used to identify the application in the user agent that
1219 /// gets sent along with requests.
1220 pub fn app_name(mut self, app_name: ::aws_types::app_name::AppName) -> Self {
1221 self.set_app_name(Some(app_name));
1222 self
1223 }
1224 /// Sets the name of the app that is using the client.
1225 ///
1226 /// This _optional_ name is used to identify the application in the user agent that
1227 /// gets sent along with requests.
1228 pub fn set_app_name(&mut self, app_name: ::std::option::Option<::aws_types::app_name::AppName>) -> &mut Self {
1229 self.config.store_or_unset(app_name);
1230 self
1231 }
1232 /// Appends framework metadata to the user agent.
1233 ///
1234 /// This _optional_ metadata identifies a software framework or third-party library
1235 /// that is being used with the client. It is rendered into the user agent string
1236 /// (as `lib/{name}/{version}`) so that libraries built on top of the AWS SDK can
1237 /// self-identify in the requests they make. Multiple entries may be added; each call
1238 /// appends another entry rather than replacing previous ones.
1239 ///
1240 /// Entries are de-duplicated on `(name, version)`, rendered in first-seen order, and
1241 /// the total number of unique entries included in the user agent is capped (currently
1242 /// at 10); additional entries beyond the cap are dropped with a warning.
1243 pub fn framework_metadata(mut self, framework_metadata: ::aws_types::sdk_ua_metadata::FrameworkMetadata) -> Self {
1244 self.push_framework_metadata(framework_metadata);
1245 self
1246 }
1247 /// Appends framework metadata to the user agent.
1248 ///
1249 /// This _optional_ metadata identifies a software framework or third-party library
1250 /// that is being used with the client. It is rendered into the user agent string
1251 /// (as `lib/{name}/{version}`) so that libraries built on top of the AWS SDK can
1252 /// self-identify in the requests they make. Multiple entries may be added; each call
1253 /// appends another entry rather than replacing previous ones.
1254 pub fn push_framework_metadata(&mut self, framework_metadata: ::aws_types::sdk_ua_metadata::FrameworkMetadata) -> &mut Self {
1255 self.config.store_append(framework_metadata);
1256 self
1257 }
1258 /// Sets the credentials provider for S3 Express One Zone
1259 pub fn express_credentials_provider(mut self, credentials_provider: impl crate::config::ProvideCredentials + 'static) -> Self {
1260 self.set_express_credentials_provider(::std::option::Option::Some(crate::config::SharedCredentialsProvider::new(
1261 credentials_provider,
1262 )));
1263 self
1264 }
1265 /// Sets the credentials provider for S3 Express One Zone
1266 pub fn set_express_credentials_provider(
1267 &mut self,
1268 credentials_provider: ::std::option::Option<crate::config::SharedCredentialsProvider>,
1269 ) -> &mut Self {
1270 if let ::std::option::Option::Some(credentials_provider) = credentials_provider {
1271 self.runtime_components
1272 .set_identity_resolver(crate::s3_express::auth::SCHEME_ID, credentials_provider);
1273 }
1274 self
1275 }
1276 /// Overrides the default invocation ID generator.
1277 ///
1278 /// The invocation ID generator generates ID values for the `amz-sdk-invocation-id` header. By default, this will be a random UUID. Overriding it may be useful in tests that examine the HTTP request and need to be deterministic.
1279 pub fn invocation_id_generator(mut self, gen: impl ::aws_runtime::invocation_id::InvocationIdGenerator + 'static) -> Self {
1280 self.set_invocation_id_generator(::std::option::Option::Some(
1281 ::aws_runtime::invocation_id::SharedInvocationIdGenerator::new(gen),
1282 ));
1283 self
1284 }
1285 /// Overrides the default invocation ID generator.
1286 ///
1287 /// The invocation ID generator generates ID values for the `amz-sdk-invocation-id` header. By default, this will be a random UUID. Overriding it may be useful in tests that examine the HTTP request and need to be deterministic.
1288 pub fn set_invocation_id_generator(
1289 &mut self,
1290 gen: ::std::option::Option<::aws_runtime::invocation_id::SharedInvocationIdGenerator>,
1291 ) -> &mut Self {
1292 self.config.store_or_unset(gen);
1293 self
1294 }
1295 /// Sets the endpoint URL used to communicate with this service.
1296 ///
1297 /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
1298 /// will be prefixed onto this URL. To fully override the endpoint resolver, use
1299 /// [`Builder::endpoint_resolver`].
1300 pub fn endpoint_url(mut self, endpoint_url: impl Into<::std::string::String>) -> Self {
1301 self.set_endpoint_url(Some(endpoint_url.into()));
1302 self
1303 }
1304 /// Sets the endpoint URL used to communicate with this service.
1305 ///
1306 /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
1307 /// will be prefixed onto this URL. To fully override the endpoint resolver, use
1308 /// [`Builder::endpoint_resolver`].
1309 pub fn set_endpoint_url(&mut self, endpoint_url: Option<::std::string::String>) -> &mut Self {
1310 self.config.store_or_unset(endpoint_url.map(::aws_types::endpoint_config::EndpointUrl));
1311 self
1312 }
1313 /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
1314 pub fn use_dual_stack(mut self, use_dual_stack: impl Into<bool>) -> Self {
1315 self.set_use_dual_stack(Some(use_dual_stack.into()));
1316 self
1317 }
1318 /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
1319 pub fn set_use_dual_stack(&mut self, use_dual_stack: Option<bool>) -> &mut Self {
1320 self.config.store_or_unset(use_dual_stack.map(::aws_types::endpoint_config::UseDualStack));
1321 self
1322 }
1323 /// When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.
1324 pub fn use_fips(mut self, use_fips: impl Into<bool>) -> Self {
1325 self.set_use_fips(Some(use_fips.into()));
1326 self
1327 }
1328 /// When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.
1329 pub fn set_use_fips(&mut self, use_fips: Option<bool>) -> &mut Self {
1330 self.config.store_or_unset(use_fips.map(::aws_types::endpoint_config::UseFips));
1331 self
1332 }
1333 /// Set the [`ResponseChecksumValidation`](crate::config::ResponseChecksumValidation)
1334 /// to determine when checksum validation will be performed on response payloads.
1335 pub fn response_checksum_validation(mut self, response_checksum_validation: crate::config::ResponseChecksumValidation) -> Self {
1336 self.set_response_checksum_validation(::std::option::Option::Some(response_checksum_validation));
1337 self
1338 }
1339 /// Set the [`ResponseChecksumValidation`](crate::config::ResponseChecksumValidation)
1340 /// to determine when checksum validation will be performed on response payloads.
1341 pub fn set_response_checksum_validation(
1342 &mut self,
1343 response_checksum_validation: ::std::option::Option<crate::config::ResponseChecksumValidation>,
1344 ) -> &mut Self {
1345 self.config.store_or_unset(response_checksum_validation);
1346 self
1347 }
1348 /// Set the [`RequestChecksumCalculation`](crate::config::RequestChecksumCalculation)
1349 /// to determine when a checksum will be calculated for request payloads.
1350 pub fn request_checksum_calculation(mut self, request_checksum_calculation: crate::config::RequestChecksumCalculation) -> Self {
1351 self.set_request_checksum_calculation(::std::option::Option::Some(request_checksum_calculation));
1352 self
1353 }
1354 /// Set the [`RequestChecksumCalculation`](crate::config::RequestChecksumCalculation)
1355 /// to determine when a checksum will be calculated for request payloads.
1356 pub fn set_request_checksum_calculation(
1357 &mut self,
1358 request_checksum_calculation: ::std::option::Option<crate::config::RequestChecksumCalculation>,
1359 ) -> &mut Self {
1360 self.config.store_or_unset(request_checksum_calculation);
1361 self
1362 }
1363 /// Sets the SigV4a signing region set.
1364 pub fn sigv4a_signing_region_set(mut self, v: impl Into<::aws_types::region::SigningRegionSet>) -> Self {
1365 self.set_sigv4a_signing_region_set(Some(v.into()));
1366 self
1367 }
1368
1369 /// Sets the SigV4a signing region set.
1370 pub fn set_sigv4a_signing_region_set(&mut self, v: Option<::aws_types::region::SigningRegionSet>) -> &mut Self {
1371 self.config.store_or_unset(v);
1372 self
1373 }
1374 /// Sets the AWS region to use when making requests.
1375 ///
1376 /// # Examples
1377 /// ```no_run
1378 /// use aws_types::region::Region;
1379 /// use aws_sdk_s3::config::{Builder, Config};
1380 ///
1381 /// let config = aws_sdk_s3::Config::builder()
1382 /// .region(Region::new("us-east-1"))
1383 /// .build();
1384 /// ```
1385 pub fn region(mut self, region: impl ::std::convert::Into<::std::option::Option<crate::config::Region>>) -> Self {
1386 self.set_region(region.into());
1387 self
1388 }
1389 /// Sets the AWS region to use when making requests.
1390 pub fn set_region(&mut self, region: ::std::option::Option<crate::config::Region>) -> &mut Self {
1391 self.config.store_or_unset(region);
1392 self
1393 }
1394 /// Sets the credentials provider for this service
1395 pub fn credentials_provider(mut self, credentials_provider: impl crate::config::ProvideCredentials + 'static) -> Self {
1396 self.set_credentials_provider(::std::option::Option::Some(crate::config::SharedCredentialsProvider::new(
1397 credentials_provider,
1398 )));
1399 self
1400 }
1401 /// Sets the credentials provider for this service
1402 pub fn set_credentials_provider(&mut self, credentials_provider: ::std::option::Option<crate::config::SharedCredentialsProvider>) -> &mut Self {
1403 if let Some(credentials_provider) = credentials_provider {
1404 #[cfg(feature = "sigv4a")]
1405 {
1406 self.runtime_components
1407 .set_identity_resolver(::aws_runtime::auth::sigv4a::SCHEME_ID, credentials_provider.clone());
1408 }
1409 self.runtime_components
1410 .set_identity_resolver(::aws_runtime::auth::sigv4::SCHEME_ID, credentials_provider);
1411 }
1412 self
1413 }
1414 /// Sets the chunk size for [`aws-chunked encoding`].
1415 ///
1416 /// Pass `Some(size)` to use a specific chunk size (minimum 8 KiB).
1417 /// Pass `None` to use the content-length as chunk size (no chunking).
1418 ///
1419 /// The minimum chunk size of 8 KiB is validated when the request is sent.
1420 ///
1421 /// **Note:** This setting only applies to operations that support aws-chunked encoding
1422 /// and has no effect on other operations. If this method is not invoked, a default
1423 /// chunk size of 64 KiB is used.
1424 ///
1425 /// [`aws-chunked encoding`]: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html
1426 ///
1427 /// # Example - Custom chunk size
1428 /// ```no_run
1429 /// # use aws_sdk_s3::{Client, Config};
1430 /// # async fn example(client: Client) -> Result<(), Box<dyn std::error::Error>> {
1431 /// let config = Config::builder()
1432 /// .aws_chunked_encoding_chunk_size(Some(10240)) // 10 KiB chunks
1433 /// .build();
1434 /// let client = Client::from_conf(config);
1435 /// # Ok(())
1436 /// # }
1437 /// ```
1438 ///
1439 /// # Example - No chunking (buffers entire body in memory)
1440 /// ```no_run
1441 /// # use aws_sdk_s3::{Client, Config};
1442 /// # async fn example(client: Client) -> Result<(), Box<dyn std::error::Error>> {
1443 /// let config = Config::builder()
1444 /// .aws_chunked_encoding_chunk_size(None) // Use entire content as one chunk
1445 /// .build();
1446 /// let client = Client::from_conf(config);
1447 /// # Ok(())
1448 /// # }
1449 /// ```
1450 pub fn aws_chunked_encoding_chunk_size(mut self, chunk_size: ::std::option::Option<usize>) -> Self {
1451 self.set_aws_chunked_encoding_chunk_size(::std::option::Option::Some(chunk_size));
1452 self
1453 }
1454
1455 /// Sets the chunk size for aws-chunked encoding.
1456 pub fn set_aws_chunked_encoding_chunk_size(&mut self, chunk_size: ::std::option::Option<::std::option::Option<usize>>) -> &mut Self {
1457 if let ::std::option::Option::Some(chunk_size) = chunk_size {
1458 let chunk_size = match chunk_size {
1459 ::std::option::Option::Some(size) => crate::aws_chunked::ChunkSize::Configured(size),
1460 ::std::option::Option::None => crate::aws_chunked::ChunkSize::DisableChunking,
1461 };
1462 self.push_runtime_plugin(crate::aws_chunked::ChunkSizeRuntimePlugin::new(chunk_size).into_shared());
1463 }
1464 self
1465 }
1466 /// Sets the [`behavior major version`](crate::config::BehaviorVersion).
1467 ///
1468 /// Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards
1469 /// compatible. For example, a change which introduces new default timeouts or a new retry-mode for
1470 /// all operations might be the ideal behavior but could break existing applications.
1471 ///
1472 /// # Examples
1473 ///
1474 /// Set the behavior major version to `latest`. This is equivalent to enabling the `behavior-version-latest` cargo feature.
1475 /// ```no_run
1476 /// use aws_sdk_s3::config::BehaviorVersion;
1477 ///
1478 /// let config = aws_sdk_s3::Config::builder()
1479 /// .behavior_version(BehaviorVersion::latest())
1480 /// // ...
1481 /// .build();
1482 /// let client = aws_sdk_s3::Client::from_conf(config);
1483 /// ```
1484 ///
1485 /// Customizing behavior major version:
1486 /// ```no_run
1487 /// use aws_sdk_s3::config::BehaviorVersion;
1488 ///
1489 /// let config = aws_sdk_s3::Config::builder()
1490 /// .behavior_version(BehaviorVersion::v2023_11_09())
1491 /// // ...
1492 /// .build();
1493 /// let client = aws_sdk_s3::Client::from_conf(config);
1494 /// ```
1495 ///
1496 pub fn behavior_version(mut self, behavior_version: crate::config::BehaviorVersion) -> Self {
1497 self.set_behavior_version(Some(behavior_version));
1498 self
1499 }
1500
1501 /// Sets the [`behavior major version`](crate::config::BehaviorVersion).
1502 ///
1503 /// Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards
1504 /// compatible. For example, a change which introduces new default timeouts or a new retry-mode for
1505 /// all operations might be the ideal behavior but could break existing applications.
1506 ///
1507 /// # Examples
1508 ///
1509 /// Set the behavior major version to `latest`. This is equivalent to enabling the `behavior-version-latest` cargo feature.
1510 /// ```no_run
1511 /// use aws_sdk_s3::config::BehaviorVersion;
1512 ///
1513 /// let config = aws_sdk_s3::Config::builder()
1514 /// .behavior_version(BehaviorVersion::latest())
1515 /// // ...
1516 /// .build();
1517 /// let client = aws_sdk_s3::Client::from_conf(config);
1518 /// ```
1519 ///
1520 /// Customizing behavior major version:
1521 /// ```no_run
1522 /// use aws_sdk_s3::config::BehaviorVersion;
1523 ///
1524 /// let config = aws_sdk_s3::Config::builder()
1525 /// .behavior_version(BehaviorVersion::v2023_11_09())
1526 /// // ...
1527 /// .build();
1528 /// let client = aws_sdk_s3::Client::from_conf(config);
1529 /// ```
1530 ///
1531 pub fn set_behavior_version(&mut self, behavior_version: Option<crate::config::BehaviorVersion>) -> &mut Self {
1532 self.behavior_version = behavior_version;
1533 self
1534 }
1535
1536 /// Convenience method to set the latest behavior major version
1537 ///
1538 /// This is equivalent to enabling the `behavior-version-latest` Cargo feature
1539 pub fn behavior_version_latest(mut self) -> Self {
1540 self.set_behavior_version(Some(crate::config::BehaviorVersion::latest()));
1541 self
1542 }
1543 /// Adds a runtime plugin to the config.
1544 #[allow(unused)]
1545 pub(crate) fn runtime_plugin(mut self, plugin: impl crate::config::RuntimePlugin + 'static) -> Self {
1546 self.push_runtime_plugin(crate::config::SharedRuntimePlugin::new(plugin));
1547 self
1548 }
1549 /// Adds a runtime plugin to the config.
1550 #[allow(unused)]
1551 pub(crate) fn push_runtime_plugin(&mut self, plugin: crate::config::SharedRuntimePlugin) -> &mut Self {
1552 self.runtime_plugins.push(plugin);
1553 self
1554 }
1555 #[cfg(any(feature = "test-util", test))]
1556 #[allow(unused_mut)]
1557 /// Apply test defaults to the builder. NOTE: Consider migrating to use `apply_test_defaults_v2` instead.
1558 pub fn apply_test_defaults(&mut self) -> &mut Self {
1559 self.set_idempotency_token_provider(Some("00000000-0000-4000-8000-000000000000".into()));
1560
1561 self.set_time_source(::std::option::Option::Some(::aws_smithy_async::time::SharedTimeSource::new(
1562 ::aws_smithy_async::time::StaticTimeSource::new(::std::time::UNIX_EPOCH + ::std::time::Duration::from_secs(1234567890)),
1563 )));
1564 self.config.store_put(::aws_runtime::user_agent::AwsUserAgent::for_tests());
1565 self.set_credentials_provider(Some(crate::config::SharedCredentialsProvider::new(
1566 ::aws_credential_types::Credentials::for_tests(),
1567 )));
1568 self.behavior_version = ::std::option::Option::Some(crate::config::BehaviorVersion::latest());
1569 self
1570 }
1571 #[cfg(any(feature = "test-util", test))]
1572 #[allow(unused_mut)]
1573 /// Apply test defaults to the builder. NOTE: Consider migrating to use `with_test_defaults_v2` instead.
1574 pub fn with_test_defaults(mut self) -> Self {
1575 self.apply_test_defaults();
1576 self
1577 }
1578 #[cfg(any(feature = "test-util", test))]
1579 #[allow(unused_mut)]
1580 /// Apply test defaults to the builder. V2 of this function sets additional test defaults such as region configuration (if applicable).
1581 pub fn apply_test_defaults_v2(&mut self) -> &mut Self {
1582 self.apply_test_defaults();
1583
1584 if self.config.load::<crate::config::Region>().is_none() {
1585 self.set_region(::std::option::Option::Some(crate::config::Region::new("us-east-1")));
1586 }
1587 self
1588 }
1589 #[cfg(any(feature = "test-util", test))]
1590 #[allow(unused_mut)]
1591 /// Apply test defaults to the builder. V2 of this function sets additional test defaults such as region configuration (if applicable).
1592 pub fn with_test_defaults_v2(mut self) -> Self {
1593 self.apply_test_defaults_v2();
1594 self
1595 }
1596 /// Builds a [`Config`].
1597 #[allow(unused_mut)]
1598 pub fn build(mut self) -> Config {
1599 let mut layer = self.config;
1600
1601 if self.runtime_components.time_source().is_none() {
1602 self.runtime_components
1603 .set_time_source(::std::option::Option::Some(::std::default::Default::default()));
1604 }
1605 layer.store_put(crate::meta::API_METADATA.clone());
1606 layer.store_put(::aws_types::SigningName::from_static("s3"));
1607 layer
1608 .load::<::aws_types::region::Region>()
1609 .cloned()
1610 .map(|r| layer.store_put(::aws_types::region::SigningRegion::from(r)));
1611 Config {
1612 config: crate::config::Layer::from(layer.clone()).with_name("aws_sdk_s3::config::Config").freeze(),
1613 cloneable: layer,
1614 runtime_components: self.runtime_components,
1615 runtime_plugins: self.runtime_plugins,
1616 behavior_version: self.behavior_version,
1617 }
1618 }
1619}
1620#[derive(::std::fmt::Debug)]
1621pub(crate) struct ServiceRuntimePlugin {
1622 config: ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer>,
1623 runtime_components: ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1624}
1625
1626impl ServiceRuntimePlugin {
1627 pub fn new(_service_config: crate::config::Config) -> Self {
1628 let config = {
1629 let mut cfg = ::aws_smithy_types::config_bag::Layer::new("AmazonS3");
1630 cfg.store_put(crate::idempotency_token::default_provider());
1631 cfg.store_put(::aws_smithy_runtime::client::orchestrator::AuthSchemeAndEndpointOrchestrationV2);
1632 ::std::option::Option::Some(cfg.freeze())
1633 };
1634 let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin");
1635 runtime_components.set_auth_scheme_option_resolver(::std::option::Option::Some({
1636 use crate::config::auth::ResolveAuthScheme;
1637 crate::config::auth::DefaultAuthSchemeResolver::default().into_shared_resolver()
1638 }));
1639 runtime_components.set_endpoint_resolver(::std::option::Option::Some({
1640 use crate::config::endpoint::ResolveEndpoint;
1641 crate::config::endpoint::DefaultResolver::new().into_shared_resolver()
1642 }));
1643 runtime_components.push_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
1644 ::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new(),
1645 ));
1646 runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default());
1647 runtime_components.push_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
1648 crate::sdk_feature_tracker::retry_mode::RetryModeFeatureTrackerInterceptor::new(),
1649 ));
1650 runtime_components.push_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
1651 ::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new(),
1652 ));
1653 runtime_components.push_interceptor(::aws_runtime::request_info::RequestInfoInterceptor::new());
1654 runtime_components.push_interceptor(::aws_runtime::user_agent::UserAgentInterceptor::new());
1655 runtime_components.push_auth_scheme(::aws_smithy_runtime_api::client::auth::SharedAuthScheme::new(
1656 crate::s3_express::auth::S3ExpressAuthScheme::new(),
1657 ));
1658 runtime_components.push_interceptor(::aws_runtime::invocation_id::InvocationIdInterceptor::new());
1659 runtime_components.push_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
1660 ::aws_runtime::recursion_detection::RecursionDetectionInterceptor::new(),
1661 ));
1662 runtime_components.push_auth_scheme(::aws_smithy_runtime_api::client::auth::SharedAuthScheme::new(
1663 ::aws_runtime::auth::sigv4::SigV4AuthScheme::new(),
1664 ));
1665 #[cfg(feature = "sigv4a")]
1666 {
1667 runtime_components.push_auth_scheme(::aws_smithy_runtime_api::client::auth::SharedAuthScheme::new(
1668 ::aws_runtime::auth::sigv4a::SigV4aAuthScheme::new(),
1669 ));
1670 }
1671 runtime_components.push_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
1672 crate::config::endpoint::EndpointOverrideFeatureTrackerInterceptor,
1673 ));
1674 runtime_components.push_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
1675 crate::observability_feature::ObservabilityFeatureTrackerInterceptor,
1676 ));
1677 Self { config, runtime_components }
1678 }
1679}
1680
1681impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for ServiceRuntimePlugin {
1682 fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
1683 self.config.clone()
1684 }
1685
1686 fn order(&self) -> ::aws_smithy_runtime_api::client::runtime_plugin::Order {
1687 ::aws_smithy_runtime_api::client::runtime_plugin::Order::Defaults
1688 }
1689
1690 fn runtime_components(
1691 &self,
1692 _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1693 ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
1694 ::std::borrow::Cow::Borrowed(&self.runtime_components)
1695 }
1696}
1697
1698// Cross-operation shared-state singletons
1699
1700/// A plugin that enables configuration for a single operation invocation
1701///
1702/// The `config` method will return a `FrozenLayer` by storing values from `config_override`.
1703/// In the case of default values requested, they will be obtained from `client_config`.
1704#[derive(Debug)]
1705pub(crate) struct ConfigOverrideRuntimePlugin {
1706 pub(crate) config: ::aws_smithy_types::config_bag::FrozenLayer,
1707 pub(crate) components: ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1708}
1709
1710impl ConfigOverrideRuntimePlugin {
1711 #[allow(dead_code)] // unused when a service does not provide any operations
1712 pub(crate) fn new(
1713 config_override: Builder,
1714 initial_config: ::aws_smithy_types::config_bag::FrozenLayer,
1715 initial_components: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1716 ) -> Self {
1717 let mut layer = config_override.config;
1718 let mut components = config_override.runtime_components;
1719 #[allow(unused_mut)]
1720 let mut resolver =
1721 ::aws_smithy_runtime::client::config_override::Resolver::overrid(initial_config, initial_components, &mut layer, &mut components);
1722
1723 resolver
1724 .config_mut()
1725 .load::<::aws_types::region::Region>()
1726 .cloned()
1727 .map(|r| resolver.config_mut().store_put(::aws_types::region::SigningRegion::from(r)));
1728
1729 let _ = resolver;
1730
1731 // When the config override supplies an identity resolver for any auth scheme
1732 // known to the client or the override itself, we give this operation its own
1733 // short-lived identity cache so that new partitions don't accumulate in the
1734 // shared client cache. A lazy cache (not `no_cache`) is used so that resolved
1735 // identities are served from the short-lived identity cache on retries.
1736 //
1737 // This is skipped if the override already sets its own identity cache.
1738 if components.has_identity_resolvers() && components.identity_cache().is_none() {
1739 components.set_identity_cache(::std::option::Option::Some(
1740 ::aws_smithy_runtime::client::identity::IdentityCache::lazy().max_partitions(1).build(),
1741 ));
1742 }
1743
1744 Self {
1745 config: ::aws_smithy_types::config_bag::Layer::from(layer)
1746 .with_name("aws_sdk_s3::config::ConfigOverrideRuntimePlugin")
1747 .freeze(),
1748 components,
1749 }
1750 }
1751}
1752
1753impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for ConfigOverrideRuntimePlugin {
1754 fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
1755 Some(self.config.clone())
1756 }
1757
1758 fn runtime_components(
1759 &self,
1760 _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1761 ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
1762 ::std::borrow::Cow::Borrowed(&self.components)
1763 }
1764}
1765
1766pub use ::aws_smithy_runtime::client::identity::IdentityCache;
1767pub use ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
1768pub use ::aws_smithy_types::config_bag::ConfigBag;
1769
1770pub use ::aws_credential_types::Credentials;
1771
1772impl From<&::aws_types::sdk_config::SdkConfig> for Builder {
1773 fn from(input: &::aws_types::sdk_config::SdkConfig) -> Self {
1774 let mut builder = Builder::default();
1775 builder.set_credentials_provider(input.credentials_provider());
1776 builder = builder.region(input.region().cloned());
1777 builder.set_sigv4a_signing_region_set(input.sigv4a_signing_region_set().cloned());
1778 builder.set_request_checksum_calculation(input.request_checksum_calculation());
1779 builder.set_response_checksum_validation(input.response_checksum_validation());
1780 builder.set_use_fips(input.use_fips());
1781 builder.set_use_dual_stack(input.use_dual_stack());
1782 if input.get_origin("endpoint_url").is_client_config() {
1783 builder.set_endpoint_url(input.endpoint_url().map(|s| s.to_string()));
1784 } else {
1785 builder.set_endpoint_url(
1786 input
1787 .service_config()
1788 .and_then(|conf| {
1789 conf.load_config(service_config_key("S3", "AWS_ENDPOINT_URL", "endpoint_url"))
1790 .map(|it| it.parse().unwrap())
1791 })
1792 .or_else(|| input.endpoint_url().map(|s| s.to_string())),
1793 );
1794 }
1795 // resiliency
1796 builder.set_retry_config(input.retry_config().cloned());
1797 builder.set_timeout_config(input.timeout_config().cloned());
1798 builder.set_sleep_impl(input.sleep_impl());
1799
1800 builder.set_http_client(input.http_client());
1801 builder.set_time_source(input.time_source());
1802 builder.set_behavior_version(input.behavior_version());
1803 builder.set_auth_scheme_preference(input.auth_scheme_preference().cloned());
1804 // setting `None` here removes the default
1805 if let Some(config) = input.stalled_stream_protection() {
1806 builder.set_stalled_stream_protection(Some(config));
1807 }
1808
1809 if let Some(cache) = input.identity_cache() {
1810 builder.set_identity_cache(cache);
1811 }
1812 builder.set_disable_s3_express_session_auth(input.service_config().and_then(|conf| {
1813 let str_config = conf.load_config(service_config_key(
1814 "S3",
1815 "AWS_S3_DISABLE_EXPRESS_SESSION_AUTH",
1816 "s3_disable_express_session_auth",
1817 ));
1818 str_config.and_then(|it| it.parse::<bool>().ok())
1819 }));
1820 builder.set_app_name(input.app_name().cloned());
1821 for framework_metadata in input.framework_metadata() {
1822 builder.push_framework_metadata(framework_metadata.clone());
1823 }
1824
1825 builder
1826 }
1827}
1828
1829impl From<&::aws_types::sdk_config::SdkConfig> for Config {
1830 fn from(sdk_config: &::aws_types::sdk_config::SdkConfig) -> Self {
1831 Builder::from(sdk_config).build()
1832 }
1833}
1834
1835pub use ::aws_types::app_name::AppName;
1836pub use ::aws_types::sdk_ua_metadata::FrameworkMetadata;
1837
1838#[allow(dead_code)]
1839fn service_config_key<'a>(service_id: &'a str, env: &'a str, profile: &'a str) -> aws_types::service_config::ServiceConfigKey<'a> {
1840 ::aws_types::service_config::ServiceConfigKey::builder()
1841 .service_id(service_id)
1842 .env(env)
1843 .profile(profile)
1844 .build()
1845 .expect("all field sets explicitly, can't fail")
1846}
1847
1848pub use ::aws_smithy_async::rt::sleep::Sleep;
1849
1850pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
1851 let mut configured_plugins = ::std::vec::Vec::new();
1852 ::std::mem::swap(&mut config.runtime_plugins, &mut configured_plugins);
1853 #[cfg(feature = "behavior-version-latest")]
1854 {
1855 if config.behavior_version.is_none() {
1856 config.behavior_version = Some(::aws_smithy_runtime_api::client::behavior_version::BehaviorVersion::latest());
1857 }
1858 }
1859
1860 let default_retry_partition = "s3";
1861 let default_retry_partition = match config.region() {
1862 Some(region) => ::std::borrow::Cow::from(format!("{default_retry_partition}-{region}")),
1863 None => ::std::borrow::Cow::from(default_retry_partition),
1864 };
1865
1866 let scope = "aws-sdk-s3";
1867
1868 #[allow(deprecated)]
1869 let mut plugins = ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins::new()
1870 // defaults
1871 .with_client_plugins(::aws_smithy_runtime::client::defaults::default_plugins(
1872 ::aws_smithy_runtime::client::defaults::DefaultPluginParams::new()
1873 .with_retry_partition_name(default_retry_partition)
1874 .with_behavior_version(config.behavior_version.expect("Invalid client configuration: A behavior major version must be set when sending a request or constructing a client. You must set it during client construction or by enabling the `behavior-version-latest` cargo feature."))
1875 .with_is_aws_sdk(true)
1876 ))
1877 // user config
1878 .with_client_plugin(
1879 ::aws_smithy_runtime_api::client::runtime_plugin::StaticRuntimePlugin::new()
1880 .with_config(config.config.clone())
1881 .with_runtime_components(config.runtime_components.clone())
1882 )
1883 // codegen config
1884 .with_client_plugin(crate::config::ServiceRuntimePlugin::new(config.clone()))
1885 .with_client_plugin(::aws_smithy_runtime::client::auth::no_auth::NoAuthRuntimePlugin::new())
1886 .with_client_plugin(
1887 ::aws_smithy_runtime::client::metrics::MetricsRuntimePlugin::builder()
1888 .with_scope(scope)
1889 .with_time_source(config.runtime_components.time_source().unwrap_or_default())
1890 .build()
1891 .expect("All required fields have been set")
1892 );
1893
1894 plugins = plugins.with_client_plugin(crate::s3_express::runtime_plugin::S3ExpressRuntimePlugin::new(config.clone()));
1895
1896 for plugin in configured_plugins {
1897 plugins = plugins.with_client_plugin(plugin);
1898 }
1899 plugins
1900}
1901
1902pub use ::aws_smithy_types::config_bag::FrozenLayer;
1903
1904pub use ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
1905
1906pub use ::aws_smithy_runtime_api::client::runtime_plugin::SharedRuntimePlugin;
1907
1908pub use ::aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
1909
1910pub use ::aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
1911
1912pub use ::aws_smithy_runtime_api::client::http::SharedHttpClient;
1913
1914pub use ::aws_smithy_async::rt::sleep::SharedAsyncSleep;
1915
1916pub use ::aws_smithy_runtime_api::client::identity::SharedIdentityCache;
1917
1918pub use ::aws_smithy_runtime_api::client::interceptors::SharedInterceptor;
1919
1920pub use ::aws_smithy_types::checksum_config::ResponseChecksumValidation;
1921
1922pub use ::aws_smithy_types::checksum_config::RequestChecksumCalculation;
1923
1924pub use ::aws_types::region::Region;
1925
1926pub use ::aws_credential_types::provider::SharedCredentialsProvider;
1927
1928#[derive(Debug, Clone)]
1929pub(crate) struct ForcePathStyle(pub(crate) bool);
1930impl ::aws_smithy_types::config_bag::Storable for ForcePathStyle {
1931 type Storer = ::aws_smithy_types::config_bag::StoreReplace<Self>;
1932}
1933
1934#[derive(Debug, Clone)]
1935pub(crate) struct UseArnRegion(pub(crate) bool);
1936impl ::aws_smithy_types::config_bag::Storable for UseArnRegion {
1937 type Storer = ::aws_smithy_types::config_bag::StoreReplace<Self>;
1938}
1939
1940#[derive(Debug, Clone)]
1941pub(crate) struct DisableMultiRegionAccessPoints(pub(crate) bool);
1942impl ::aws_smithy_types::config_bag::Storable for DisableMultiRegionAccessPoints {
1943 type Storer = ::aws_smithy_types::config_bag::StoreReplace<Self>;
1944}
1945
1946#[derive(Debug, Clone)]
1947pub(crate) struct Accelerate(pub(crate) bool);
1948impl ::aws_smithy_types::config_bag::Storable for Accelerate {
1949 type Storer = ::aws_smithy_types::config_bag::StoreReplace<Self>;
1950}
1951
1952#[derive(Debug, Clone)]
1953pub(crate) struct DisableS3ExpressSessionAuth(pub(crate) bool);
1954impl ::aws_smithy_types::config_bag::Storable for DisableS3ExpressSessionAuth {
1955 type Storer = ::aws_smithy_types::config_bag::StoreReplace<Self>;
1956}
1957
1958pub use ::aws_smithy_runtime_api::client::http::HttpClient;
1959
1960pub use ::aws_smithy_runtime_api::shared::IntoShared;
1961
1962pub use ::aws_smithy_async::rt::sleep::AsyncSleep;
1963
1964pub use ::aws_smithy_runtime_api::client::identity::ResolveCachedIdentity;
1965
1966pub use ::aws_smithy_runtime_api::client::interceptors::Intercept;
1967
1968pub use ::aws_credential_types::provider::ProvideCredentials;
1969
1970pub use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
1971
1972pub use ::aws_smithy_types::config_bag::Layer;
1973
1974/// Types needed to configure endpoint resolution.
1975pub mod endpoint;
1976
1977/// HTTP request and response types.
1978pub mod http;
1979
1980/// Types needed to implement [`Intercept`](crate::config::Intercept).
1981pub mod interceptors;
1982
1983/// Retry configuration.
1984///
1985/// [`RetryConfig`](crate::config::retry::RetryConfig) sets the number of retry attempts and the backoff between them. Retries are additionally bounded by a retry token bucket (a shared retry quota): [`TokenBucket`](crate::config::retry::TokenBucket) holds the tokens and [`RetryPartition`](crate::config::retry::RetryPartition) determines which clients and operations share one. To size the token bucket or give a workload its own, use [`Builder::retry_partition`](crate::config::Builder::retry_partition).
1986pub mod retry;
1987
1988/// Timeout configuration.
1989pub mod timeout;
1990
1991/// Types needed to configure auth scheme resolution.
1992pub mod auth;