aws_types/sdk_config.rs
1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#![deny(missing_docs)]
7
8//! AWS Shared Config
9//!
10//! This module contains a shared configuration representation that is agnostic from a specific service.
11
12use crate::app_name::AppName;
13use crate::docs_for;
14use crate::origin::Origin;
15use crate::region::Region;
16use crate::service_config::LoadServiceConfig;
17use aws_credential_types::provider::token::SharedTokenProvider;
18pub use aws_credential_types::provider::SharedCredentialsProvider;
19use aws_smithy_async::rt::sleep::AsyncSleep;
20pub use aws_smithy_async::rt::sleep::SharedAsyncSleep;
21pub use aws_smithy_async::time::{SharedTimeSource, TimeSource};
22use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
23use aws_smithy_runtime_api::client::http::HttpClient;
24pub use aws_smithy_runtime_api::client::http::SharedHttpClient;
25use aws_smithy_runtime_api::client::identity::{ResolveCachedIdentity, SharedIdentityCache};
26pub use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
27use aws_smithy_runtime_api::shared::IntoShared;
28pub use aws_smithy_types::checksum_config::{
29 RequestChecksumCalculation, ResponseChecksumValidation,
30};
31pub use aws_smithy_types::retry::RetryConfig;
32pub use aws_smithy_types::timeout::TimeoutConfig;
33use std::collections::HashMap;
34use std::sync::Arc;
35
36/// Unified docstrings to keep crates in sync. Not intended for public use
37pub mod unified_docs {
38 /// A macro that generates docs for selected fields of `SdkConfig`.
39 #[macro_export]
40 macro_rules! docs_for {
41 (use_fips) => {
42"When true, send this request to the FIPS-compliant regional endpoint.
43
44If no FIPS-compliant endpoint can be determined, dispatching the request will return an error."
45 };
46 (use_dual_stack) => {
47"When true, send this request to the dual-stack endpoint.
48
49If no dual-stack endpoint is available the request MAY return an error.
50
51**Note**: Some services do not offer dual-stack as a configurable parameter (e.g. Code Catalyst). For
52these services, this setting has no effect"
53 };
54 (time_source) => {
55"The time source use to use for this client.
56
57This only needs to be required for creating deterministic tests or platforms where `SystemTime::now()` is not supported."};
58 (disable_request_compression) => {
59"When `true`, disable request compression. Defaults to `false`.
60
61**Only some services support request compression.** For services
62that don't support request compression, this setting does nothing.
63" };
64 (request_min_compression_size_bytes) => {
65"The minimum size of request that should be compressed. Defaults to `10240` bytes.
66
67When a request body's size is lower than this, request compression will be skipped.
68This is useful for request bodies because, for small request bodies, compression may actually increase their size.
69
70**Only some services support request compression.** For services
71that don't support request compression, this setting does nothing.
72" };
73 }
74}
75
76/// AWS Shared Configuration
77#[derive(Debug, Clone)]
78pub struct SdkConfig {
79 app_name: Option<AppName>,
80 identity_cache: Option<SharedIdentityCache>,
81 credentials_provider: Option<SharedCredentialsProvider>,
82 token_provider: Option<SharedTokenProvider>,
83 region: Option<Region>,
84 endpoint_url: Option<String>,
85 retry_config: Option<RetryConfig>,
86 sleep_impl: Option<SharedAsyncSleep>,
87 time_source: Option<SharedTimeSource>,
88 timeout_config: Option<TimeoutConfig>,
89 stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
90 http_client: Option<SharedHttpClient>,
91 use_fips: Option<bool>,
92 use_dual_stack: Option<bool>,
93 behavior_version: Option<BehaviorVersion>,
94 service_config: Option<Arc<dyn LoadServiceConfig>>,
95 config_origins: HashMap<&'static str, Origin>,
96 disable_request_compression: Option<bool>,
97 request_min_compression_size_bytes: Option<u32>,
98 request_checksum_calculation: Option<RequestChecksumCalculation>,
99 response_checksum_validation: Option<ResponseChecksumValidation>,
100}
101
102/// Builder for AWS Shared Configuration
103///
104/// _Important:_ Using the `aws-config` crate to configure the SDK is preferred to invoking this
105/// builder directly. Using this builder directly won't pull in any AWS recommended default
106/// configuration values.
107#[derive(Debug, Default)]
108pub struct Builder {
109 app_name: Option<AppName>,
110 identity_cache: Option<SharedIdentityCache>,
111 credentials_provider: Option<SharedCredentialsProvider>,
112 token_provider: Option<SharedTokenProvider>,
113 region: Option<Region>,
114 endpoint_url: Option<String>,
115 retry_config: Option<RetryConfig>,
116 sleep_impl: Option<SharedAsyncSleep>,
117 time_source: Option<SharedTimeSource>,
118 timeout_config: Option<TimeoutConfig>,
119 stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
120 http_client: Option<SharedHttpClient>,
121 use_fips: Option<bool>,
122 use_dual_stack: Option<bool>,
123 behavior_version: Option<BehaviorVersion>,
124 service_config: Option<Arc<dyn LoadServiceConfig>>,
125 config_origins: HashMap<&'static str, Origin>,
126 disable_request_compression: Option<bool>,
127 request_min_compression_size_bytes: Option<u32>,
128 request_checksum_calculation: Option<RequestChecksumCalculation>,
129 response_checksum_validation: Option<ResponseChecksumValidation>,
130}
131
132impl Builder {
133 /// Set the region for the builder
134 ///
135 /// # Examples
136 /// ```rust
137 /// use aws_types::SdkConfig;
138 /// use aws_types::region::Region;
139 /// let config = SdkConfig::builder().region(Region::new("us-east-1")).build();
140 /// ```
141 pub fn region(mut self, region: impl Into<Option<Region>>) -> Self {
142 self.set_region(region);
143 self
144 }
145
146 /// Set the region for the builder
147 ///
148 /// # Examples
149 /// ```rust
150 /// fn region_override() -> Option<Region> {
151 /// // ...
152 /// # None
153 /// }
154 /// use aws_types::SdkConfig;
155 /// use aws_types::region::Region;
156 /// let mut builder = SdkConfig::builder();
157 /// if let Some(region) = region_override() {
158 /// builder.set_region(region);
159 /// }
160 /// let config = builder.build();
161 /// ```
162 pub fn set_region(&mut self, region: impl Into<Option<Region>>) -> &mut Self {
163 self.region = region.into();
164 self
165 }
166
167 /// Set the endpoint URL to use when making requests.
168 /// # Examples
169 /// ```
170 /// use aws_types::SdkConfig;
171 /// let config = SdkConfig::builder().endpoint_url("http://localhost:8080").build();
172 /// ```
173 pub fn endpoint_url(mut self, endpoint_url: impl Into<String>) -> Self {
174 self.set_endpoint_url(Some(endpoint_url.into()));
175 self
176 }
177
178 /// Set the endpoint URL to use when making requests.
179 pub fn set_endpoint_url(&mut self, endpoint_url: Option<String>) -> &mut Self {
180 self.endpoint_url = endpoint_url;
181 self
182 }
183
184 /// Set the checksum calculation strategy to use when making requests.
185 /// # Examples
186 /// ```
187 /// use aws_types::SdkConfig;
188 /// use aws_smithy_types::checksum_config::RequestChecksumCalculation;
189 /// let config = SdkConfig::builder().request_checksum_calculation(RequestChecksumCalculation::WhenSupported).build();
190 /// ```
191 pub fn request_checksum_calculation(
192 mut self,
193 request_checksum_calculation: RequestChecksumCalculation,
194 ) -> Self {
195 self.set_request_checksum_calculation(Some(request_checksum_calculation));
196 self
197 }
198
199 /// Set the checksum calculation strategy to use when making requests.
200 pub fn set_request_checksum_calculation(
201 &mut self,
202 request_checksum_calculation: Option<RequestChecksumCalculation>,
203 ) -> &mut Self {
204 self.request_checksum_calculation = request_checksum_calculation;
205 self
206 }
207
208 /// Set the checksum calculation strategy to use for responses.
209 /// # Examples
210 /// ```
211 /// use aws_types::SdkConfig;
212 /// use aws_smithy_types::checksum_config::ResponseChecksumValidation;
213 /// let config = SdkConfig::builder().response_checksum_validation(ResponseChecksumValidation::WhenSupported).build();
214 /// ```
215 pub fn response_checksum_validation(
216 mut self,
217 response_checksum_validation: ResponseChecksumValidation,
218 ) -> Self {
219 self.set_response_checksum_validation(Some(response_checksum_validation));
220 self
221 }
222
223 /// Set the checksum calculation strategy to use for responses.
224 pub fn set_response_checksum_validation(
225 &mut self,
226 response_checksum_validation: Option<ResponseChecksumValidation>,
227 ) -> &mut Self {
228 self.response_checksum_validation = response_checksum_validation;
229 self
230 }
231
232 /// Set the retry_config for the builder
233 ///
234 /// _Note:_ Retries require a sleep implementation in order to work. When enabling retry, make
235 /// sure to set one with [Self::sleep_impl] or [Self::set_sleep_impl].
236 ///
237 /// # Examples
238 /// ```rust
239 /// use aws_types::SdkConfig;
240 /// use aws_smithy_types::retry::RetryConfig;
241 ///
242 /// let retry_config = RetryConfig::standard().with_max_attempts(5);
243 /// let config = SdkConfig::builder().retry_config(retry_config).build();
244 /// ```
245 pub fn retry_config(mut self, retry_config: RetryConfig) -> Self {
246 self.set_retry_config(Some(retry_config));
247 self
248 }
249
250 /// Set the retry_config for the builder
251 ///
252 /// _Note:_ Retries require a sleep implementation in order to work. When enabling retry, make
253 /// sure to set one with [Self::sleep_impl] or [Self::set_sleep_impl].
254 ///
255 /// # Examples
256 /// ```rust
257 /// use aws_types::sdk_config::{SdkConfig, Builder};
258 /// use aws_smithy_types::retry::RetryConfig;
259 ///
260 /// fn disable_retries(builder: &mut Builder) {
261 /// let retry_config = RetryConfig::standard().with_max_attempts(1);
262 /// builder.set_retry_config(Some(retry_config));
263 /// }
264 ///
265 /// let mut builder = SdkConfig::builder();
266 /// disable_retries(&mut builder);
267 /// ```
268 pub fn set_retry_config(&mut self, retry_config: Option<RetryConfig>) -> &mut Self {
269 self.retry_config = retry_config;
270 self
271 }
272
273 /// Set the [`TimeoutConfig`] for the builder
274 ///
275 /// _Note:_ Timeouts require a sleep implementation in order to work.
276 /// When enabling timeouts, be sure to set one with [Self::sleep_impl] or
277 /// [Self::set_sleep_impl].
278 ///
279 /// # Examples
280 ///
281 /// ```rust
282 /// # use std::time::Duration;
283 /// use aws_types::SdkConfig;
284 /// use aws_smithy_types::timeout::TimeoutConfig;
285 ///
286 /// let timeout_config = TimeoutConfig::builder()
287 /// .operation_attempt_timeout(Duration::from_secs(2))
288 /// .operation_timeout(Duration::from_secs(5))
289 /// .build();
290 /// let config = SdkConfig::builder()
291 /// .timeout_config(timeout_config)
292 /// .build();
293 /// ```
294 pub fn timeout_config(mut self, timeout_config: TimeoutConfig) -> Self {
295 self.set_timeout_config(Some(timeout_config));
296 self
297 }
298
299 /// Set the [`TimeoutConfig`] for the builder
300 ///
301 /// _Note:_ Timeouts require a sleep implementation in order to work.
302 /// When enabling timeouts, be sure to set one with [Self::sleep_impl] or
303 /// [Self::set_sleep_impl].
304 ///
305 /// # Examples
306 /// ```rust
307 /// # use std::time::Duration;
308 /// use aws_types::sdk_config::{SdkConfig, Builder};
309 /// use aws_smithy_types::timeout::TimeoutConfig;
310 ///
311 /// fn set_preferred_timeouts(builder: &mut Builder) {
312 /// let timeout_config = TimeoutConfig::builder()
313 /// .operation_attempt_timeout(Duration::from_secs(2))
314 /// .operation_timeout(Duration::from_secs(5))
315 /// .build();
316 /// builder.set_timeout_config(Some(timeout_config));
317 /// }
318 ///
319 /// let mut builder = SdkConfig::builder();
320 /// set_preferred_timeouts(&mut builder);
321 /// let config = builder.build();
322 /// ```
323 pub fn set_timeout_config(&mut self, timeout_config: Option<TimeoutConfig>) -> &mut Self {
324 self.timeout_config = timeout_config;
325 self
326 }
327
328 /// Set the sleep implementation for the builder.
329 ///
330 /// The sleep implementation is used to create timeout futures.
331 ///
332 /// _Note:_ If you're using the Tokio runtime, a `TokioSleep` implementation is available in
333 /// the `aws-smithy-async` crate.
334 ///
335 /// # Examples
336 ///
337 /// ```rust
338 /// use aws_smithy_async::rt::sleep::{AsyncSleep, SharedAsyncSleep, Sleep};
339 /// use aws_types::SdkConfig;
340 ///
341 /// ##[derive(Debug)]
342 /// pub struct ForeverSleep;
343 ///
344 /// impl AsyncSleep for ForeverSleep {
345 /// fn sleep(&self, duration: std::time::Duration) -> Sleep {
346 /// Sleep::new(std::future::pending())
347 /// }
348 /// }
349 ///
350 /// let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
351 /// let config = SdkConfig::builder().sleep_impl(sleep_impl).build();
352 /// ```
353 pub fn sleep_impl(mut self, sleep_impl: impl AsyncSleep + 'static) -> Self {
354 self.set_sleep_impl(Some(sleep_impl.into_shared()));
355 self
356 }
357
358 /// Set the sleep implementation for the builder. The sleep implementation is used to create
359 /// timeout futures.
360 ///
361 /// _Note:_ If you're using the Tokio runtime, a `TokioSleep` implementation is available in
362 /// the `aws-smithy-async` crate.
363 ///
364 /// # Examples
365 /// ```rust
366 /// # use aws_smithy_async::rt::sleep::{AsyncSleep, SharedAsyncSleep, Sleep};
367 /// # use aws_types::sdk_config::{Builder, SdkConfig};
368 /// #[derive(Debug)]
369 /// pub struct ForeverSleep;
370 ///
371 /// impl AsyncSleep for ForeverSleep {
372 /// fn sleep(&self, duration: std::time::Duration) -> Sleep {
373 /// Sleep::new(std::future::pending())
374 /// }
375 /// }
376 ///
377 /// fn set_never_ending_sleep_impl(builder: &mut Builder) {
378 /// let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
379 /// builder.set_sleep_impl(Some(sleep_impl));
380 /// }
381 ///
382 /// let mut builder = SdkConfig::builder();
383 /// set_never_ending_sleep_impl(&mut builder);
384 /// let config = builder.build();
385 /// ```
386 pub fn set_sleep_impl(&mut self, sleep_impl: Option<SharedAsyncSleep>) -> &mut Self {
387 self.sleep_impl = sleep_impl;
388 self
389 }
390
391 /// Set the identity cache for caching credentials and SSO tokens.
392 ///
393 /// The default identity cache will wait until the first request that requires authentication
394 /// to load an identity. Once the identity is loaded, it is cached until shortly before it
395 /// expires.
396 ///
397 /// # Examples
398 /// Disabling identity caching:
399 /// ```rust
400 /// # use aws_types::SdkConfig;
401 /// use aws_smithy_runtime::client::identity::IdentityCache;
402 /// let config = SdkConfig::builder()
403 /// .identity_cache(IdentityCache::no_cache())
404 /// .build();
405 /// ```
406 /// Changing settings on the default cache implementation:
407 /// ```rust
408 /// # use aws_types::SdkConfig;
409 /// use aws_smithy_runtime::client::identity::IdentityCache;
410 /// use std::time::Duration;
411 ///
412 /// let config = SdkConfig::builder()
413 /// .identity_cache(
414 /// IdentityCache::lazy()
415 /// .load_timeout(Duration::from_secs(10))
416 /// .build()
417 /// )
418 /// .build();
419 /// ```
420 pub fn identity_cache(mut self, cache: impl ResolveCachedIdentity + 'static) -> Self {
421 self.set_identity_cache(Some(cache.into_shared()));
422 self
423 }
424
425 /// Set the identity cache for caching credentials and SSO tokens.
426 ///
427 /// The default identity cache will wait until the first request that requires authentication
428 /// to load an identity. Once the identity is loaded, it is cached until shortly before it
429 /// expires.
430 ///
431 /// # Examples
432 /// ```rust
433 /// # use aws_types::SdkConfig;
434 /// use aws_smithy_runtime::client::identity::IdentityCache;
435 ///
436 /// fn override_identity_cache() -> bool {
437 /// // ...
438 /// # true
439 /// }
440 ///
441 /// let mut builder = SdkConfig::builder();
442 /// if override_identity_cache() {
443 /// builder.set_identity_cache(Some(IdentityCache::lazy().build()));
444 /// }
445 /// let config = builder.build();
446 /// ```
447 pub fn set_identity_cache(&mut self, cache: Option<SharedIdentityCache>) -> &mut Self {
448 self.identity_cache = cache;
449 self
450 }
451
452 /// Set the credentials provider for the builder
453 ///
454 /// # Examples
455 /// ```rust
456 /// use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
457 /// use aws_types::SdkConfig;
458 /// fn make_provider() -> impl ProvideCredentials {
459 /// // ...
460 /// # use aws_credential_types::Credentials;
461 /// # Credentials::new("test", "test", None, None, "example")
462 /// }
463 ///
464 /// let config = SdkConfig::builder()
465 /// .credentials_provider(SharedCredentialsProvider::new(make_provider()))
466 /// .build();
467 /// ```
468 pub fn credentials_provider(mut self, provider: SharedCredentialsProvider) -> Self {
469 self.set_credentials_provider(Some(provider));
470 self
471 }
472
473 /// Set the credentials provider for the builder
474 ///
475 /// # Examples
476 /// ```rust
477 /// use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
478 /// use aws_types::SdkConfig;
479 /// fn make_provider() -> impl ProvideCredentials {
480 /// // ...
481 /// # use aws_credential_types::Credentials;
482 /// # Credentials::new("test", "test", None, None, "example")
483 /// }
484 ///
485 /// fn override_provider() -> bool {
486 /// // ...
487 /// # true
488 /// }
489 ///
490 /// let mut builder = SdkConfig::builder();
491 /// if override_provider() {
492 /// builder.set_credentials_provider(Some(SharedCredentialsProvider::new(make_provider())));
493 /// }
494 /// let config = builder.build();
495 /// ```
496 pub fn set_credentials_provider(
497 &mut self,
498 provider: Option<SharedCredentialsProvider>,
499 ) -> &mut Self {
500 self.credentials_provider = provider;
501 self
502 }
503
504 /// Set the bearer auth token provider for the builder
505 ///
506 /// # Examples
507 /// ```rust
508 /// use aws_credential_types::provider::token::{ProvideToken, SharedTokenProvider};
509 /// use aws_types::SdkConfig;
510 ///
511 /// fn make_provider() -> impl ProvideToken {
512 /// // ...
513 /// # aws_credential_types::Token::new("example", None)
514 /// }
515 ///
516 /// let config = SdkConfig::builder()
517 /// .token_provider(SharedTokenProvider::new(make_provider()))
518 /// .build();
519 /// ```
520 pub fn token_provider(mut self, provider: SharedTokenProvider) -> Self {
521 self.set_token_provider(Some(provider));
522 self
523 }
524
525 /// Set the bearer auth token provider for the builder
526 ///
527 /// # Examples
528 /// ```rust
529 /// use aws_credential_types::provider::token::{ProvideToken, SharedTokenProvider};
530 /// use aws_types::SdkConfig;
531 ///
532 /// fn make_provider() -> impl ProvideToken {
533 /// // ...
534 /// # aws_credential_types::Token::new("example", None)
535 /// }
536 ///
537 /// fn override_provider() -> bool {
538 /// // ...
539 /// # true
540 /// }
541 ///
542 /// let mut builder = SdkConfig::builder();
543 /// if override_provider() {
544 /// builder.set_token_provider(Some(SharedTokenProvider::new(make_provider())));
545 /// }
546 /// let config = builder.build();
547 /// ```
548 pub fn set_token_provider(&mut self, provider: Option<SharedTokenProvider>) -> &mut Self {
549 self.token_provider = provider;
550 self
551 }
552
553 /// Sets the name of the app that is using the client.
554 ///
555 /// This _optional_ name is used to identify the application in the user agent that
556 /// gets sent along with requests.
557 pub fn app_name(mut self, app_name: AppName) -> Self {
558 self.set_app_name(Some(app_name));
559 self
560 }
561
562 /// Sets the name of the app that is using the client.
563 ///
564 /// This _optional_ name is used to identify the application in the user agent that
565 /// gets sent along with requests.
566 pub fn set_app_name(&mut self, app_name: Option<AppName>) -> &mut Self {
567 self.app_name = app_name;
568 self
569 }
570
571 /// Sets the HTTP client to use when making requests.
572 ///
573 /// ## Examples
574 /// ```no_run
575 /// # #[cfg(feature = "examples")]
576 /// # fn example() {
577 /// use aws_types::sdk_config::{SdkConfig, TimeoutConfig};
578 /// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
579 /// use std::time::Duration;
580 ///
581 /// // Create a connector that will be used to establish TLS connections
582 /// let tls_connector = hyper_rustls::HttpsConnectorBuilder::new()
583 /// .with_webpki_roots()
584 /// .https_only()
585 /// .enable_http1()
586 /// .enable_http2()
587 /// .build();
588 /// // Create a HTTP client that uses the TLS connector. This client is
589 /// // responsible for creating and caching a HttpConnector when given HttpConnectorSettings.
590 /// // This hyper client will create HttpConnectors backed by hyper and the tls_connector.
591 /// let http_client = HyperClientBuilder::new().build(tls_connector);
592 /// let sdk_config = SdkConfig::builder()
593 /// .http_client(http_client)
594 /// // Connect/read timeouts are passed to the HTTP client when servicing a request
595 /// .timeout_config(
596 /// TimeoutConfig::builder()
597 /// .connect_timeout(Duration::from_secs(5))
598 /// .build()
599 /// )
600 /// .build();
601 /// # }
602 /// ```
603 pub fn http_client(mut self, http_client: impl HttpClient + 'static) -> Self {
604 self.set_http_client(Some(http_client.into_shared()));
605 self
606 }
607
608 /// Sets the HTTP client to use when making requests.
609 ///
610 /// ## Examples
611 /// ```no_run
612 /// # #[cfg(feature = "examples")]
613 /// # fn example() {
614 /// use aws_types::sdk_config::{Builder, SdkConfig, TimeoutConfig};
615 /// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
616 /// use std::time::Duration;
617 ///
618 /// fn override_http_client(builder: &mut Builder) {
619 /// // Create a connector that will be used to establish TLS connections
620 /// let tls_connector = hyper_rustls::HttpsConnectorBuilder::new()
621 /// .with_webpki_roots()
622 /// .https_only()
623 /// .enable_http1()
624 /// .enable_http2()
625 /// .build();
626 /// // Create a HTTP client that uses the TLS connector. This client is
627 /// // responsible for creating and caching a HttpConnector when given HttpConnectorSettings.
628 /// // This hyper client will create HttpConnectors backed by hyper and the tls_connector.
629 /// let http_client = HyperClientBuilder::new().build(tls_connector);
630 ///
631 /// builder.set_http_client(Some(http_client));
632 /// }
633 ///
634 /// let mut builder = SdkConfig::builder();
635 /// override_http_client(&mut builder);
636 /// let config = builder.build();
637 /// # }
638 /// ```
639 pub fn set_http_client(&mut self, http_client: Option<SharedHttpClient>) -> &mut Self {
640 self.http_client = http_client;
641 self
642 }
643
644 #[doc = docs_for!(use_fips)]
645 pub fn use_fips(mut self, use_fips: bool) -> Self {
646 self.set_use_fips(Some(use_fips));
647 self
648 }
649
650 #[doc = docs_for!(use_fips)]
651 pub fn set_use_fips(&mut self, use_fips: Option<bool>) -> &mut Self {
652 self.use_fips = use_fips;
653 self
654 }
655
656 #[doc = docs_for!(use_dual_stack)]
657 pub fn use_dual_stack(mut self, use_dual_stack: bool) -> Self {
658 self.set_use_dual_stack(Some(use_dual_stack));
659 self
660 }
661
662 #[doc = docs_for!(use_dual_stack)]
663 pub fn set_use_dual_stack(&mut self, use_dual_stack: Option<bool>) -> &mut Self {
664 self.use_dual_stack = use_dual_stack;
665 self
666 }
667
668 #[doc = docs_for!(time_source)]
669 pub fn time_source(mut self, time_source: impl TimeSource + 'static) -> Self {
670 self.set_time_source(Some(SharedTimeSource::new(time_source)));
671 self
672 }
673
674 #[doc = docs_for!(time_source)]
675 pub fn set_time_source(&mut self, time_source: Option<SharedTimeSource>) -> &mut Self {
676 self.time_source = time_source;
677 self
678 }
679
680 #[doc = docs_for!(disable_request_compression)]
681 pub fn disable_request_compression(mut self, disable_request_compression: bool) -> Self {
682 self.set_disable_request_compression(Some(disable_request_compression));
683 self
684 }
685
686 #[doc = docs_for!(disable_request_compression)]
687 pub fn set_disable_request_compression(
688 &mut self,
689 disable_request_compression: Option<bool>,
690 ) -> &mut Self {
691 self.disable_request_compression = disable_request_compression;
692 self
693 }
694
695 #[doc = docs_for!(request_min_compression_size_bytes)]
696 pub fn request_min_compression_size_bytes(
697 mut self,
698 request_min_compression_size_bytes: u32,
699 ) -> Self {
700 self.set_request_min_compression_size_bytes(Some(request_min_compression_size_bytes));
701 self
702 }
703
704 #[doc = docs_for!(request_min_compression_size_bytes)]
705 pub fn set_request_min_compression_size_bytes(
706 &mut self,
707 request_min_compression_size_bytes: Option<u32>,
708 ) -> &mut Self {
709 self.request_min_compression_size_bytes = request_min_compression_size_bytes;
710 self
711 }
712
713 /// Sets the [`BehaviorVersion`] for the [`SdkConfig`]
714 pub fn behavior_version(mut self, behavior_version: BehaviorVersion) -> Self {
715 self.set_behavior_version(Some(behavior_version));
716 self
717 }
718
719 /// Sets the [`BehaviorVersion`] for the [`SdkConfig`]
720 pub fn set_behavior_version(&mut self, behavior_version: Option<BehaviorVersion>) -> &mut Self {
721 self.behavior_version = behavior_version;
722 self
723 }
724
725 /// Sets the service config provider for the [`SdkConfig`].
726 ///
727 /// This provider is used when creating a service-specific config from an
728 /// `SdkConfig` and provides access to config defined in the environment
729 /// which would otherwise be inaccessible.
730 pub fn service_config(mut self, service_config: impl LoadServiceConfig + 'static) -> Self {
731 self.set_service_config(Some(service_config));
732 self
733 }
734
735 /// Sets the service config provider for the [`SdkConfig`].
736 ///
737 /// This provider is used when creating a service-specific config from an
738 /// `SdkConfig` and provides access to config defined in the environment
739 /// which would otherwise be inaccessible.
740 pub fn set_service_config(
741 &mut self,
742 service_config: Option<impl LoadServiceConfig + 'static>,
743 ) -> &mut Self {
744 self.service_config = service_config.map(|it| Arc::new(it) as Arc<dyn LoadServiceConfig>);
745 self
746 }
747
748 /// Set the origin of a setting.
749 ///
750 /// This is used internally to understand how to merge config structs while
751 /// respecting precedence of origins.
752 pub fn insert_origin(&mut self, setting: &'static str, origin: Origin) {
753 self.config_origins.insert(setting, origin);
754 }
755
756 /// Build a [`SdkConfig`] from this builder.
757 pub fn build(self) -> SdkConfig {
758 SdkConfig {
759 app_name: self.app_name,
760 identity_cache: self.identity_cache,
761 credentials_provider: self.credentials_provider,
762 token_provider: self.token_provider,
763 region: self.region,
764 endpoint_url: self.endpoint_url,
765 retry_config: self.retry_config,
766 sleep_impl: self.sleep_impl,
767 timeout_config: self.timeout_config,
768 http_client: self.http_client,
769 use_fips: self.use_fips,
770 use_dual_stack: self.use_dual_stack,
771 time_source: self.time_source,
772 behavior_version: self.behavior_version,
773 stalled_stream_protection_config: self.stalled_stream_protection_config,
774 service_config: self.service_config,
775 config_origins: self.config_origins,
776 disable_request_compression: self.disable_request_compression,
777 request_min_compression_size_bytes: self.request_min_compression_size_bytes,
778 request_checksum_calculation: self.request_checksum_calculation,
779 response_checksum_validation: self.response_checksum_validation,
780 }
781 }
782}
783
784impl Builder {
785 /// Set the [`StalledStreamProtectionConfig`] to configure protection for stalled streams.
786 ///
787 /// This configures stalled stream protection. When enabled, download streams
788 /// that stall (stream no data) for longer than a configured grace period will return an error.
789 ///
790 /// _Note:_ Stalled stream protection requires both a sleep implementation and a time source
791 /// in order to work. When enabling stalled stream protection, make sure to set
792 /// - A sleep impl with [Self::sleep_impl] or [Self::set_sleep_impl].
793 /// - A time source with [Self::time_source] or [Self::set_time_source].
794 ///
795 /// # Examples
796 /// ```rust
797 /// use std::time::Duration;
798 /// use aws_types::SdkConfig;
799 /// pub use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
800 ///
801 /// let stalled_stream_protection_config = StalledStreamProtectionConfig::enabled()
802 /// .grace_period(Duration::from_secs(1))
803 /// .build();
804 /// let config = SdkConfig::builder()
805 /// .stalled_stream_protection(stalled_stream_protection_config)
806 /// .build();
807 /// ```
808 pub fn stalled_stream_protection(
809 mut self,
810 stalled_stream_protection_config: StalledStreamProtectionConfig,
811 ) -> Self {
812 self.set_stalled_stream_protection(Some(stalled_stream_protection_config));
813 self
814 }
815
816 /// Set the [`StalledStreamProtectionConfig`] to configure protection for stalled streams.
817 ///
818 /// This configures stalled stream protection. When enabled, download streams
819 /// that stall (stream no data) for longer than a configured grace period will return an error.
820 ///
821 /// By default, streams that transmit less than one byte per-second for five seconds will
822 /// be cancelled.
823 ///
824 /// _Note:_ Stalled stream protection requires both a sleep implementation and a time source
825 /// in order to work. When enabling stalled stream protection, make sure to set
826 /// - A sleep impl with [Self::sleep_impl] or [Self::set_sleep_impl].
827 /// - A time source with [Self::time_source] or [Self::set_time_source].
828 ///
829 /// # Examples
830 /// ```rust
831 /// use std::time::Duration;
832 /// use aws_types::sdk_config::{SdkConfig, Builder};
833 /// pub use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
834 ///
835 /// fn set_stalled_stream_protection(builder: &mut Builder) {
836 /// let stalled_stream_protection_config = StalledStreamProtectionConfig::enabled()
837 /// .grace_period(Duration::from_secs(1))
838 /// .build();
839 /// builder.set_stalled_stream_protection(Some(stalled_stream_protection_config));
840 /// }
841 ///
842 /// let mut builder = SdkConfig::builder();
843 /// set_stalled_stream_protection(&mut builder);
844 /// let config = builder.build();
845 /// ```
846 pub fn set_stalled_stream_protection(
847 &mut self,
848 stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
849 ) -> &mut Self {
850 self.stalled_stream_protection_config = stalled_stream_protection_config;
851 self
852 }
853}
854
855impl SdkConfig {
856 /// Configured region
857 pub fn region(&self) -> Option<&Region> {
858 self.region.as_ref()
859 }
860
861 /// Configured endpoint URL
862 pub fn endpoint_url(&self) -> Option<&str> {
863 self.endpoint_url.as_deref()
864 }
865
866 /// Configured retry config
867 pub fn retry_config(&self) -> Option<&RetryConfig> {
868 self.retry_config.as_ref()
869 }
870
871 /// Configured timeout config
872 pub fn timeout_config(&self) -> Option<&TimeoutConfig> {
873 self.timeout_config.as_ref()
874 }
875
876 /// Configured sleep implementation
877 pub fn sleep_impl(&self) -> Option<SharedAsyncSleep> {
878 self.sleep_impl.clone()
879 }
880
881 /// Configured identity cache
882 pub fn identity_cache(&self) -> Option<SharedIdentityCache> {
883 self.identity_cache.clone()
884 }
885
886 /// Configured credentials provider
887 pub fn credentials_provider(&self) -> Option<SharedCredentialsProvider> {
888 self.credentials_provider.clone()
889 }
890
891 /// Configured bearer auth token provider
892 pub fn token_provider(&self) -> Option<SharedTokenProvider> {
893 self.token_provider.clone()
894 }
895
896 /// Configured time source
897 pub fn time_source(&self) -> Option<SharedTimeSource> {
898 self.time_source.clone()
899 }
900
901 /// Configured app name
902 pub fn app_name(&self) -> Option<&AppName> {
903 self.app_name.as_ref()
904 }
905
906 /// Configured HTTP client
907 pub fn http_client(&self) -> Option<SharedHttpClient> {
908 self.http_client.clone()
909 }
910
911 /// Use FIPS endpoints
912 pub fn use_fips(&self) -> Option<bool> {
913 self.use_fips
914 }
915
916 /// Use dual-stack endpoint
917 pub fn use_dual_stack(&self) -> Option<bool> {
918 self.use_dual_stack
919 }
920
921 /// When true, request compression is disabled.
922 pub fn disable_request_compression(&self) -> Option<bool> {
923 self.disable_request_compression
924 }
925
926 /// Configured checksum request behavior.
927 pub fn request_checksum_calculation(&self) -> Option<RequestChecksumCalculation> {
928 self.request_checksum_calculation
929 }
930
931 /// Configured checksum response behavior.
932 pub fn response_checksum_validation(&self) -> Option<ResponseChecksumValidation> {
933 self.response_checksum_validation
934 }
935
936 /// Configured minimum request compression size.
937 pub fn request_min_compression_size_bytes(&self) -> Option<u32> {
938 self.request_min_compression_size_bytes
939 }
940
941 /// Configured stalled stream protection
942 pub fn stalled_stream_protection(&self) -> Option<StalledStreamProtectionConfig> {
943 self.stalled_stream_protection_config.clone()
944 }
945
946 /// Behavior version configured for this client
947 pub fn behavior_version(&self) -> Option<BehaviorVersion> {
948 self.behavior_version
949 }
950
951 /// Return an immutable reference to the service config provider configured for this client.
952 pub fn service_config(&self) -> Option<&dyn LoadServiceConfig> {
953 self.service_config.as_deref()
954 }
955
956 /// Config builder
957 ///
958 /// _Important:_ Using the `aws-config` crate to configure the SDK is preferred to invoking this
959 /// builder directly. Using this builder directly won't pull in any AWS recommended default
960 /// configuration values.
961 pub fn builder() -> Builder {
962 Builder::default()
963 }
964
965 /// Convert this [`SdkConfig`] into a [`Builder`] by cloning it first
966 pub fn to_builder(&self) -> Builder {
967 self.clone().into_builder()
968 }
969
970 /// Get the origin of a setting.
971 ///
972 /// This is used internally to understand how to merge config structs while
973 /// respecting precedence of origins.
974 pub fn get_origin(&self, setting: &'static str) -> Origin {
975 self.config_origins
976 .get(setting)
977 .cloned()
978 .unwrap_or_default()
979 }
980
981 /// Convert this [`SdkConfig`] back to a builder to enable modification
982 pub fn into_builder(self) -> Builder {
983 Builder {
984 app_name: self.app_name,
985 identity_cache: self.identity_cache,
986 credentials_provider: self.credentials_provider,
987 token_provider: self.token_provider,
988 region: self.region,
989 endpoint_url: self.endpoint_url,
990 retry_config: self.retry_config,
991 sleep_impl: self.sleep_impl,
992 time_source: self.time_source,
993 timeout_config: self.timeout_config,
994 http_client: self.http_client,
995 use_fips: self.use_fips,
996 use_dual_stack: self.use_dual_stack,
997 behavior_version: self.behavior_version,
998 stalled_stream_protection_config: self.stalled_stream_protection_config,
999 service_config: self.service_config,
1000 config_origins: self.config_origins,
1001 disable_request_compression: self.disable_request_compression,
1002 request_min_compression_size_bytes: self.request_min_compression_size_bytes,
1003 request_checksum_calculation: self.request_checksum_calculation,
1004 response_checksum_validation: self.response_checksum_validation,
1005 }
1006 }
1007}