aws_sdk_kms/
config.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// Configuration for a aws_sdk_kms 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    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    /// Returns the endpoint resolver.
59    pub fn endpoint_resolver(&self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver {
60        self.runtime_components.endpoint_resolver().expect("resolver defaulted if not set")
61    }
62    /// Return a reference to the retry configuration contained in this config, if any.
63    pub fn retry_config(&self) -> ::std::option::Option<&::aws_smithy_types::retry::RetryConfig> {
64        self.config.load::<::aws_smithy_types::retry::RetryConfig>()
65    }
66
67    /// Return a cloned shared async sleep implementation from this config, if any.
68    pub fn sleep_impl(&self) -> ::std::option::Option<crate::config::SharedAsyncSleep> {
69        self.runtime_components.sleep_impl()
70    }
71
72    /// Return a reference to the timeout configuration contained in this config, if any.
73    pub fn timeout_config(&self) -> ::std::option::Option<&::aws_smithy_types::timeout::TimeoutConfig> {
74        self.config.load::<::aws_smithy_types::timeout::TimeoutConfig>()
75    }
76
77    /// Returns a reference to the retry partition contained in this config, if any.
78    ///
79    /// WARNING: This method is unstable and may be removed at any time. Do not rely on this
80    /// method for anything!
81    pub fn retry_partition(&self) -> ::std::option::Option<&::aws_smithy_runtime::client::retries::RetryPartition> {
82        self.config.load::<::aws_smithy_runtime::client::retries::RetryPartition>()
83    }
84    /// Returns the configured identity cache for auth.
85    pub fn identity_cache(&self) -> ::std::option::Option<crate::config::SharedIdentityCache> {
86        self.runtime_components.identity_cache()
87    }
88    /// Returns interceptors currently registered by the user.
89    pub fn interceptors(&self) -> impl Iterator<Item = crate::config::SharedInterceptor> + '_ {
90        self.runtime_components.interceptors()
91    }
92    /// Return time source used for this service.
93    pub fn time_source(&self) -> ::std::option::Option<::aws_smithy_async::time::SharedTimeSource> {
94        self.runtime_components.time_source()
95    }
96    /// Returns retry classifiers currently registered by the user.
97    pub fn retry_classifiers(&self) -> impl Iterator<Item = ::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier> + '_ {
98        self.runtime_components.retry_classifiers()
99    }
100    /// Returns the name of the app that is using the client, if it was provided.
101    ///
102    /// This _optional_ name is used to identify the application in the user agent that
103    /// gets sent along with requests.
104    pub fn app_name(&self) -> ::std::option::Option<&::aws_types::app_name::AppName> {
105        self.config.load::<::aws_types::app_name::AppName>()
106    }
107    /// Returns the invocation ID generator if one was given in config.
108    ///
109    /// 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.
110    pub fn invocation_id_generator(&self) -> ::std::option::Option<::aws_runtime::invocation_id::SharedInvocationIdGenerator> {
111        self.config.load::<::aws_runtime::invocation_id::SharedInvocationIdGenerator>().cloned()
112    }
113    /// Creates a new [service config](crate::Config) from a [shared `config`](::aws_types::sdk_config::SdkConfig).
114    pub fn new(config: &::aws_types::sdk_config::SdkConfig) -> Self {
115        Builder::from(config).build()
116    }
117    /// The signature version 4 service signing name to use in the credential scope when signing requests.
118    ///
119    /// The signing service may be overridden by the `Endpoint`, or by specifying a custom
120    /// [`SigningName`](aws_types::SigningName) during operation construction
121    pub fn signing_name(&self) -> &'static str {
122        "kms"
123    }
124    /// Returns the AWS region, if it was provided.
125    pub fn region(&self) -> ::std::option::Option<&crate::config::Region> {
126        self.config.load::<crate::config::Region>()
127    }
128    /// 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.
129    #[deprecated(
130        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."
131    )]
132    pub fn credentials_provider(&self) -> Option<crate::config::SharedCredentialsProvider> {
133        ::std::option::Option::None
134    }
135}
136/// Builder for creating a `Config`.
137#[derive(::std::clone::Clone, ::std::fmt::Debug)]
138pub struct Builder {
139    pub(crate) config: ::aws_smithy_types::config_bag::CloneableLayer,
140    pub(crate) runtime_components: crate::config::RuntimeComponentsBuilder,
141    pub(crate) runtime_plugins: ::std::vec::Vec<crate::config::SharedRuntimePlugin>,
142    pub(crate) behavior_version: ::std::option::Option<crate::config::BehaviorVersion>,
143}
144impl ::std::default::Default for Builder {
145    fn default() -> Self {
146        Self {
147            config: ::std::default::Default::default(),
148            runtime_components: crate::config::RuntimeComponentsBuilder::new("service config"),
149            runtime_plugins: ::std::default::Default::default(),
150            behavior_version: ::std::default::Default::default(),
151        }
152    }
153}
154impl Builder {
155    ///
156    /// Constructs a config builder.
157    /// <div class="warning">
158    /// Note that a config created from this builder will not have the same safe defaults as one created by
159    /// the <a href="https://crates.io/crates/aws-config" target="_blank">aws-config</a> crate.
160    /// </div>
161    ///
162    pub fn new() -> Self {
163        Self::default()
164    }
165    /// Constructs a config builder from the given `config_bag`, setting only fields stored in the config bag,
166    /// but not those in runtime components.
167    #[allow(unused)]
168    pub(crate) fn from_config_bag(config_bag: &::aws_smithy_types::config_bag::ConfigBag) -> Self {
169        let mut builder = Self::new();
170        builder.set_stalled_stream_protection(config_bag.load::<crate::config::StalledStreamProtectionConfig>().cloned());
171        builder.set_retry_config(config_bag.load::<::aws_smithy_types::retry::RetryConfig>().cloned());
172        builder.set_timeout_config(config_bag.load::<::aws_smithy_types::timeout::TimeoutConfig>().cloned());
173        builder.set_retry_partition(config_bag.load::<::aws_smithy_runtime::client::retries::RetryPartition>().cloned());
174        builder.set_app_name(config_bag.load::<::aws_types::app_name::AppName>().cloned());
175        builder.set_endpoint_url(config_bag.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()));
176        builder.set_use_dual_stack(config_bag.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0));
177        builder.set_use_fips(config_bag.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0));
178        builder.set_region(config_bag.load::<crate::config::Region>().cloned());
179        builder
180    }
181    /// Set the [`StalledStreamProtectionConfig`](crate::config::StalledStreamProtectionConfig)
182    /// to configure protection for stalled streams.
183    pub fn stalled_stream_protection(mut self, stalled_stream_protection_config: crate::config::StalledStreamProtectionConfig) -> Self {
184        self.set_stalled_stream_protection(::std::option::Option::Some(stalled_stream_protection_config));
185        self
186    }
187    /// Set the [`StalledStreamProtectionConfig`](crate::config::StalledStreamProtectionConfig)
188    /// to configure protection for stalled streams.
189    pub fn set_stalled_stream_protection(
190        &mut self,
191        stalled_stream_protection_config: ::std::option::Option<crate::config::StalledStreamProtectionConfig>,
192    ) -> &mut Self {
193        self.config.store_or_unset(stalled_stream_protection_config);
194        self
195    }
196    /// Sets the HTTP client to use when making requests.
197    ///
198    /// # Examples
199    /// ```no_run
200    /// # #[cfg(test)]
201    /// # mod tests {
202    /// # #[test]
203    /// # fn example() {
204    /// use std::time::Duration;
205    /// use aws_sdk_kms::config::Config;
206    /// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
207    ///
208    /// let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
209    ///     .with_webpki_roots()
210    ///     .https_only()
211    ///     .enable_http1()
212    ///     .enable_http2()
213    ///     .build();
214    /// let hyper_client = HyperClientBuilder::new().build(https_connector);
215    ///
216    /// // This connector can then be given to a generated service Config
217    /// let config = my_service_client::Config::builder()
218    ///     .endpoint_url("https://example.com")
219    ///     .http_client(hyper_client)
220    ///     .build();
221    /// let client = my_service_client::Client::from_conf(config);
222    /// # }
223    /// # }
224    /// ```
225    pub fn http_client(mut self, http_client: impl crate::config::HttpClient + 'static) -> Self {
226        self.set_http_client(::std::option::Option::Some(crate::config::IntoShared::into_shared(http_client)));
227        self
228    }
229
230    /// Sets the HTTP client to use when making requests.
231    ///
232    /// # Examples
233    /// ```no_run
234    /// # #[cfg(test)]
235    /// # mod tests {
236    /// # #[test]
237    /// # fn example() {
238    /// use std::time::Duration;
239    /// use aws_sdk_kms::config::{Builder, Config};
240    /// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
241    ///
242    /// fn override_http_client(builder: &mut Builder) {
243    ///     let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
244    ///         .with_webpki_roots()
245    ///         .https_only()
246    ///         .enable_http1()
247    ///         .enable_http2()
248    ///         .build();
249    ///     let hyper_client = HyperClientBuilder::new().build(https_connector);
250    ///     builder.set_http_client(Some(hyper_client));
251    /// }
252    ///
253    /// let mut builder = aws_sdk_kms::Config::builder();
254    /// override_http_client(&mut builder);
255    /// let config = builder.build();
256    /// # }
257    /// # }
258    /// ```
259    pub fn set_http_client(&mut self, http_client: Option<crate::config::SharedHttpClient>) -> &mut Self {
260        self.runtime_components.set_http_client(http_client);
261        self
262    }
263    /// Sets the endpoint resolver to use when making requests.
264    ///
265
266    /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
267    /// rules for `aws_sdk_kms`.
268
269    ///
270    /// Note: setting an endpoint resolver will replace any endpoint URL that has been set.
271    /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to
272    /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`].
273    ///
274    /// # Examples
275    /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production.
276    /// ```no_run
277    /// use aws_sdk_kms::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint};
278    /// #[derive(Debug)]
279    /// struct StageResolver { stage: String }
280    /// impl ResolveEndpoint for StageResolver {
281    ///     fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> {
282    ///         let stage = &self.stage;
283    ///         EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build()))
284    ///     }
285    /// }
286    /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() };
287    /// let config = aws_sdk_kms::Config::builder().endpoint_resolver(resolver).build();
288    /// let client = aws_sdk_kms::Client::from_conf(config);
289    /// ```
290    pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self {
291        self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver()));
292        self
293    }
294
295    /// Sets the endpoint resolver to use when making requests.
296    ///
297
298    /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
299    /// rules for `aws_sdk_kms`.
300    pub fn set_endpoint_resolver(
301        &mut self,
302        endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>,
303    ) -> &mut Self {
304        self.runtime_components.set_endpoint_resolver(endpoint_resolver);
305        self
306    }
307    /// Set the retry_config for the builder
308    ///
309    /// # Examples
310    /// ```no_run
311    /// use aws_sdk_kms::config::Config;
312    /// use aws_sdk_kms::config::retry::RetryConfig;
313    ///
314    /// let retry_config = RetryConfig::standard().with_max_attempts(5);
315    /// let config = Config::builder().retry_config(retry_config).build();
316    /// ```
317    pub fn retry_config(mut self, retry_config: ::aws_smithy_types::retry::RetryConfig) -> Self {
318        self.set_retry_config(Some(retry_config));
319        self
320    }
321
322    /// Set the retry_config for the builder
323    ///
324    /// # Examples
325    /// ```no_run
326    /// use aws_sdk_kms::config::{Builder, Config};
327    /// use aws_sdk_kms::config::retry::RetryConfig;
328    ///
329    /// fn disable_retries(builder: &mut Builder) {
330    ///     let retry_config = RetryConfig::standard().with_max_attempts(1);
331    ///     builder.set_retry_config(Some(retry_config));
332    /// }
333    ///
334    /// let mut builder = Config::builder();
335    /// disable_retries(&mut builder);
336    /// let config = builder.build();
337    /// ```
338    pub fn set_retry_config(&mut self, retry_config: ::std::option::Option<::aws_smithy_types::retry::RetryConfig>) -> &mut Self {
339        retry_config.map(|r| self.config.store_put(r));
340        self
341    }
342    /// Set the sleep_impl for the builder
343    ///
344    /// # Examples
345    ///
346    /// ```no_run
347    /// use aws_sdk_kms::config::{AsyncSleep, Config, SharedAsyncSleep, Sleep};
348    ///
349    /// #[derive(Debug)]
350    /// pub struct ForeverSleep;
351    ///
352    /// impl AsyncSleep for ForeverSleep {
353    ///     fn sleep(&self, duration: std::time::Duration) -> Sleep {
354    ///         Sleep::new(std::future::pending())
355    ///     }
356    /// }
357    ///
358    /// let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
359    /// let config = Config::builder().sleep_impl(sleep_impl).build();
360    /// ```
361    pub fn sleep_impl(mut self, sleep_impl: impl crate::config::AsyncSleep + 'static) -> Self {
362        self.set_sleep_impl(Some(::aws_smithy_runtime_api::shared::IntoShared::into_shared(sleep_impl)));
363        self
364    }
365
366    /// Set the sleep_impl for the builder
367    ///
368    /// # Examples
369    ///
370    /// ```no_run
371    /// use aws_sdk_kms::config::{AsyncSleep, Builder, Config, SharedAsyncSleep, Sleep};
372    ///
373    /// #[derive(Debug)]
374    /// pub struct ForeverSleep;
375    ///
376    /// impl AsyncSleep for ForeverSleep {
377    ///     fn sleep(&self, duration: std::time::Duration) -> Sleep {
378    ///         Sleep::new(std::future::pending())
379    ///     }
380    /// }
381    ///
382    /// fn set_never_ending_sleep_impl(builder: &mut Builder) {
383    ///     let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
384    ///     builder.set_sleep_impl(Some(sleep_impl));
385    /// }
386    ///
387    /// let mut builder = Config::builder();
388    /// set_never_ending_sleep_impl(&mut builder);
389    /// let config = builder.build();
390    /// ```
391    pub fn set_sleep_impl(&mut self, sleep_impl: ::std::option::Option<crate::config::SharedAsyncSleep>) -> &mut Self {
392        self.runtime_components.set_sleep_impl(sleep_impl);
393        self
394    }
395    /// Set the timeout_config for the builder
396    ///
397    /// # Examples
398    ///
399    /// ```no_run
400    /// # use std::time::Duration;
401    /// use aws_sdk_kms::config::Config;
402    /// use aws_sdk_kms::config::timeout::TimeoutConfig;
403    ///
404    /// let timeout_config = TimeoutConfig::builder()
405    ///     .operation_attempt_timeout(Duration::from_secs(1))
406    ///     .build();
407    /// let config = Config::builder().timeout_config(timeout_config).build();
408    /// ```
409    pub fn timeout_config(mut self, timeout_config: ::aws_smithy_types::timeout::TimeoutConfig) -> Self {
410        self.set_timeout_config(Some(timeout_config));
411        self
412    }
413
414    /// Set the timeout_config for the builder.
415    ///
416    /// Setting this to `None` has no effect if another source of configuration has set timeouts. If you
417    /// are attempting to disable timeouts, use [`TimeoutConfig::disabled`](::aws_smithy_types::timeout::TimeoutConfig::disabled)
418    ///
419    ///
420    /// # Examples
421    ///
422    /// ```no_run
423    /// # use std::time::Duration;
424    /// use aws_sdk_kms::config::{Builder, Config};
425    /// use aws_sdk_kms::config::timeout::TimeoutConfig;
426    ///
427    /// fn set_request_timeout(builder: &mut Builder) {
428    ///     let timeout_config = TimeoutConfig::builder()
429    ///         .operation_attempt_timeout(Duration::from_secs(1))
430    ///         .build();
431    ///     builder.set_timeout_config(Some(timeout_config));
432    /// }
433    ///
434    /// let mut builder = Config::builder();
435    /// set_request_timeout(&mut builder);
436    /// let config = builder.build();
437    /// ```
438    pub fn set_timeout_config(&mut self, timeout_config: ::std::option::Option<::aws_smithy_types::timeout::TimeoutConfig>) -> &mut Self {
439        // passing None has no impact.
440        let Some(mut timeout_config) = timeout_config else { return self };
441
442        if let Some(base) = self.config.load::<::aws_smithy_types::timeout::TimeoutConfig>() {
443            timeout_config.take_defaults_from(base);
444        }
445        self.config.store_put(timeout_config);
446        self
447    }
448    /// Set the partition for retry-related state. When clients share a retry partition, they will
449    /// also share things like token buckets and client rate limiters. By default, all clients
450    /// for the same service will share a partition.
451    pub fn retry_partition(mut self, retry_partition: ::aws_smithy_runtime::client::retries::RetryPartition) -> Self {
452        self.set_retry_partition(Some(retry_partition));
453        self
454    }
455    /// Set the partition for retry-related state. When clients share a retry partition, they will
456    /// also share things like token buckets and client rate limiters. By default, all clients
457    /// for the same service will share a partition.
458    pub fn set_retry_partition(
459        &mut self,
460        retry_partition: ::std::option::Option<::aws_smithy_runtime::client::retries::RetryPartition>,
461    ) -> &mut Self {
462        retry_partition.map(|r| self.config.store_put(r));
463        self
464    }
465    /// Set the identity cache for auth.
466    ///
467    /// The identity cache defaults to a lazy caching implementation that will resolve
468    /// an identity when it is requested, and place it in the cache thereafter. Subsequent
469    /// requests will take the value from the cache while it is still valid. Once it expires,
470    /// the next request will result in refreshing the identity.
471    ///
472    /// This configuration allows you to disable or change the default caching mechanism.
473    /// To use a custom caching mechanism, implement the [`ResolveCachedIdentity`](crate::config::ResolveCachedIdentity)
474    /// trait and pass that implementation into this function.
475    ///
476    /// # Examples
477    ///
478    /// Disabling identity caching:
479    /// ```no_run
480    /// use aws_sdk_kms::config::IdentityCache;
481    ///
482    /// let config = aws_sdk_kms::Config::builder()
483    ///     .identity_cache(IdentityCache::no_cache())
484    ///     // ...
485    ///     .build();
486    /// let client = aws_sdk_kms::Client::from_conf(config);
487    /// ```
488    ///
489    /// Customizing lazy caching:
490    /// ```no_run
491    /// use aws_sdk_kms::config::IdentityCache;
492    /// use std::time::Duration;
493    ///
494    /// let config = aws_sdk_kms::Config::builder()
495    ///     .identity_cache(
496    ///         IdentityCache::lazy()
497    ///             // change the load timeout to 10 seconds
498    ///             .load_timeout(Duration::from_secs(10))
499    ///             .build()
500    ///     )
501    ///     // ...
502    ///     .build();
503    /// let client = aws_sdk_kms::Client::from_conf(config);
504    /// ```
505
506    pub fn identity_cache(mut self, identity_cache: impl crate::config::ResolveCachedIdentity + 'static) -> Self {
507        self.set_identity_cache(identity_cache);
508        self
509    }
510
511    /// Set the identity cache for auth.
512    ///
513    /// The identity cache defaults to a lazy caching implementation that will resolve
514    /// an identity when it is requested, and place it in the cache thereafter. Subsequent
515    /// requests will take the value from the cache while it is still valid. Once it expires,
516    /// the next request will result in refreshing the identity.
517    ///
518    /// This configuration allows you to disable or change the default caching mechanism.
519    /// To use a custom caching mechanism, implement the [`ResolveCachedIdentity`](crate::config::ResolveCachedIdentity)
520    /// trait and pass that implementation into this function.
521    ///
522    /// # Examples
523    ///
524    /// Disabling identity caching:
525    /// ```no_run
526    /// use aws_sdk_kms::config::IdentityCache;
527    ///
528    /// let config = aws_sdk_kms::Config::builder()
529    ///     .identity_cache(IdentityCache::no_cache())
530    ///     // ...
531    ///     .build();
532    /// let client = aws_sdk_kms::Client::from_conf(config);
533    /// ```
534    ///
535    /// Customizing lazy caching:
536    /// ```no_run
537    /// use aws_sdk_kms::config::IdentityCache;
538    /// use std::time::Duration;
539    ///
540    /// let config = aws_sdk_kms::Config::builder()
541    ///     .identity_cache(
542    ///         IdentityCache::lazy()
543    ///             // change the load timeout to 10 seconds
544    ///             .load_timeout(Duration::from_secs(10))
545    ///             .build()
546    ///     )
547    ///     // ...
548    ///     .build();
549    /// let client = aws_sdk_kms::Client::from_conf(config);
550    /// ```
551
552    pub fn set_identity_cache(&mut self, identity_cache: impl crate::config::ResolveCachedIdentity + 'static) -> &mut Self {
553        self.runtime_components.set_identity_cache(::std::option::Option::Some(identity_cache));
554        self
555    }
556    /// Add an [interceptor](crate::config::Intercept) that runs at specific stages of the request execution pipeline.
557    ///
558    /// Interceptors targeted at a certain stage are executed according to the pre-defined priority.
559    /// The SDK provides a default set of interceptors. An interceptor configured by this method
560    /// will run after those default interceptors.
561    ///
562    /// # Examples
563    /// ```no_run
564    /// # #[cfg(test)]
565    /// # mod tests {
566    /// # #[test]
567    /// # fn example() {
568    /// use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
569    /// use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
570    /// use aws_smithy_types::config_bag::ConfigBag;
571    /// use aws_sdk_kms::config::Config;
572    ///
573    /// fn base_url() -> String {
574    ///     // ...
575    ///     # String::new()
576    /// }
577    ///
578    /// #[derive(Debug)]
579    /// pub struct UriModifierInterceptor;
580    /// impl Intercept for UriModifierInterceptor {
581    ///     fn modify_before_signing(
582    ///         &self,
583    ///         context: &mut InterceptorContext<BeforeTransmit>,
584    ///         _cfg: &mut ConfigBag,
585    ///     ) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
586    ///         let request = context.request_mut();
587    ///         let uri = format!("{}{}", base_url(), request.uri().path());
588    ///         *request.uri_mut() = uri.parse()?;
589    ///
590    ///         Ok(())
591    ///     }
592    /// }
593    ///
594    /// let config = Config::builder()
595    ///     .interceptor(UriModifierInterceptor)
596    ///     .build();
597    /// # }
598    /// # }
599    /// ```
600    pub fn interceptor(mut self, interceptor: impl crate::config::Intercept + 'static) -> Self {
601        self.push_interceptor(crate::config::SharedInterceptor::new(interceptor));
602        self
603    }
604
605    /// Add a [`SharedInterceptor`](crate::config::SharedInterceptor) that runs at specific stages of the request execution pipeline.
606    ///
607    /// Interceptors targeted at a certain stage are executed according to the pre-defined priority.
608    /// The SDK provides a default set of interceptors. An interceptor configured by this method
609    /// will run after those default interceptors.
610    ///
611    /// # Examples
612    /// ```no_run
613    /// # #[cfg(test)]
614    /// # mod tests {
615    /// # #[test]
616    /// # fn example() {
617    /// use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
618    /// use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext, SharedInterceptor};
619    /// use aws_smithy_types::config_bag::ConfigBag;
620    /// use aws_sdk_kms::config::{Builder, Config};
621    ///
622    /// fn base_url() -> String {
623    ///     // ...
624    ///     # String::new()
625    /// }
626    ///
627    /// fn modify_request_uri(builder: &mut Builder) {
628    ///     #[derive(Debug)]
629    ///     pub struct UriModifierInterceptor;
630    ///     impl Intercept for UriModifierInterceptor {
631    ///         fn modify_before_signing(
632    ///             &self,
633    ///             context: &mut InterceptorContext<BeforeTransmit>,
634    ///             _cfg: &mut ConfigBag,
635    ///         ) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
636    ///             let request = context.request_mut();
637    ///             let uri = format!("{}{}", base_url(), request.uri().path());
638    ///             *request.uri_mut() = uri.parse()?;
639    ///
640    ///             Ok(())
641    ///         }
642    ///     }
643    ///     builder.push_interceptor(SharedInterceptor::new(UriModifierInterceptor));
644    /// }
645    ///
646    /// let mut builder = Config::builder();
647    /// modify_request_uri(&mut builder);
648    /// let config = builder.build();
649    /// # }
650    /// # }
651    /// ```
652    pub fn push_interceptor(&mut self, interceptor: crate::config::SharedInterceptor) -> &mut Self {
653        self.runtime_components.push_interceptor(interceptor);
654        self
655    }
656
657    /// Set [`SharedInterceptor`](crate::config::SharedInterceptor)s for the builder.
658    pub fn set_interceptors(&mut self, interceptors: impl IntoIterator<Item = crate::config::SharedInterceptor>) -> &mut Self {
659        self.runtime_components.set_interceptors(interceptors.into_iter());
660        self
661    }
662    /// Sets the time source used for this service
663    pub fn time_source(mut self, time_source: impl ::aws_smithy_async::time::TimeSource + 'static) -> Self {
664        self.set_time_source(::std::option::Option::Some(::aws_smithy_runtime_api::shared::IntoShared::into_shared(
665            time_source,
666        )));
667        self
668    }
669    /// Sets the time source used for this service
670    pub fn set_time_source(&mut self, time_source: ::std::option::Option<::aws_smithy_async::time::SharedTimeSource>) -> &mut Self {
671        self.runtime_components.set_time_source(time_source);
672        self
673    }
674    /// Add type implementing [`ClassifyRetry`](::aws_smithy_runtime_api::client::retries::classifiers::ClassifyRetry) that will be used by the
675    /// [`RetryStrategy`](::aws_smithy_runtime_api::client::retries::RetryStrategy) to determine what responses should be retried.
676    ///
677    /// A retry classifier configured by this method will run according to its [priority](::aws_smithy_runtime_api::client::retries::classifiers::RetryClassifierPriority).
678    ///
679    /// # Examples
680    /// ```no_run
681    /// # #[cfg(test)]
682    /// # mod tests {
683    /// # #[test]
684    /// # fn example() {
685    /// use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
686    /// use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
687    /// use aws_smithy_runtime_api::client::retries::classifiers::{
688    ///     ClassifyRetry, RetryAction, RetryClassifierPriority,
689    /// };
690    /// use aws_smithy_types::error::metadata::ProvideErrorMetadata;
691    /// use aws_smithy_types::retry::ErrorKind;
692    /// use std::error::Error as StdError;
693    /// use std::marker::PhantomData;
694    /// use aws_sdk_kms::config::Config;
695    /// # struct SomeOperationError {}
696    ///
697    /// const RETRYABLE_ERROR_CODES: &[&str] = [
698    ///     // List error codes to be retried here...
699    /// ];
700    ///
701    /// // When classifying at an operation's error type, classifiers require a generic parameter.
702    /// // When classifying the HTTP response alone, no generic is needed.
703    /// #[derive(Debug, Default)]
704    /// pub struct ErrorCodeClassifier<E> {
705    ///     _inner: PhantomData<E>,
706    /// }
707    ///
708    /// impl<E> ExampleErrorCodeClassifier<E> {
709    ///     pub fn new() -> Self {
710    ///         Self {
711    ///             _inner: PhantomData,
712    ///         }
713    ///     }
714    /// }
715    ///
716    /// impl<E> ClassifyRetry for ExampleErrorCodeClassifier<E>
717    /// where
718    ///     // Adding a trait bound for ProvideErrorMetadata allows us to inspect the error code.
719    ///     E: StdError + ProvideErrorMetadata + Send + Sync + 'static,
720    /// {
721    ///     fn classify_retry(&self, ctx: &InterceptorContext) -> RetryAction {
722    ///         // Check for a result
723    ///         let output_or_error = ctx.output_or_error();
724    ///         // Check for an error
725    ///         let error = match output_or_error {
726    ///             Some(Ok(_)) | None => return RetryAction::NoActionIndicated,
727    ///               Some(Err(err)) => err,
728    ///         };
729    ///
730    ///         // Downcast the generic error and extract the code
731    ///         let error_code = OrchestratorError::as_operation_error(error)
732    ///             .and_then(|err| err.downcast_ref::<E>())
733    ///             .and_then(|err| err.code());
734    ///
735    ///         // If this error's code is in our list, return an action that tells the RetryStrategy to retry this request.
736    ///         if let Some(error_code) = error_code {
737    ///             if RETRYABLE_ERROR_CODES.contains(&error_code) {
738    ///                 return RetryAction::transient_error();
739    ///             }
740    ///         }
741    ///
742    ///         // Otherwise, return that no action is indicated i.e. that this classifier doesn't require a retry.
743    ///         // Another classifier may still classify this response as retryable.
744    ///         RetryAction::NoActionIndicated
745    ///     }
746    ///
747    ///     fn name(&self) -> &'static str { "Example Error Code Classifier" }
748    /// }
749    ///
750    /// let config = Config::builder()
751    ///     .retry_classifier(ExampleErrorCodeClassifier::<SomeOperationError>::new())
752    ///     .build();
753    /// # }
754    /// # }
755    /// ```
756    pub fn retry_classifier(
757        mut self,
758        retry_classifier: impl ::aws_smithy_runtime_api::client::retries::classifiers::ClassifyRetry + 'static,
759    ) -> Self {
760        self.push_retry_classifier(::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier::new(
761            retry_classifier,
762        ));
763        self
764    }
765
766    /// Add a [`SharedRetryClassifier`](::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier) that will be used by the
767    /// [`RetryStrategy`](::aws_smithy_runtime_api::client::retries::RetryStrategy) to determine what responses should be retried.
768    ///
769    /// A retry classifier configured by this method will run according to its priority.
770    ///
771    /// # Examples
772    /// ```no_run
773    /// # #[cfg(test)]
774    /// # mod tests {
775    /// # #[test]
776    /// # fn example() {
777    /// use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
778    /// use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
779    /// use aws_smithy_runtime_api::client::retries::classifiers::{
780    ///     ClassifyRetry, RetryAction, RetryClassifierPriority,
781    /// };
782    /// use aws_smithy_types::error::metadata::ProvideErrorMetadata;
783    /// use aws_smithy_types::retry::ErrorKind;
784    /// use std::error::Error as StdError;
785    /// use std::marker::PhantomData;
786    /// use aws_sdk_kms::config::{Builder, Config};
787    /// # struct SomeOperationError {}
788    ///
789    /// const RETRYABLE_ERROR_CODES: &[&str] = [
790    ///     // List error codes to be retried here...
791    /// ];
792    /// fn set_example_error_code_classifier(builder: &mut Builder) {
793    ///     // When classifying at an operation's error type, classifiers require a generic parameter.
794    ///     // When classifying the HTTP response alone, no generic is needed.
795    ///     #[derive(Debug, Default)]
796    ///     pub struct ExampleErrorCodeClassifier<E> {
797    ///         _inner: PhantomData<E>,
798    ///     }
799    ///
800    ///     impl<E> ExampleErrorCodeClassifier<E> {
801    ///         pub fn new() -> Self {
802    ///             Self {
803    ///                 _inner: PhantomData,
804    ///             }
805    ///         }
806    ///     }
807    ///
808    ///     impl<E> ClassifyRetry for ExampleErrorCodeClassifier<E>
809    ///     where
810    ///         // Adding a trait bound for ProvideErrorMetadata allows us to inspect the error code.
811    ///         E: StdError + ProvideErrorMetadata + Send + Sync + 'static,
812    ///     {
813    ///         fn classify_retry(&self, ctx: &InterceptorContext) -> RetryAction {
814    ///             // Check for a result
815    ///             let output_or_error = ctx.output_or_error();
816    ///             // Check for an error
817    ///             let error = match output_or_error {
818    ///                 Some(Ok(_)) | None => return RetryAction::NoActionIndicated,
819    ///                   Some(Err(err)) => err,
820    ///             };
821    ///
822    ///             // Downcast the generic error and extract the code
823    ///             let error_code = OrchestratorError::as_operation_error(error)
824    ///                 .and_then(|err| err.downcast_ref::<E>())
825    ///                 .and_then(|err| err.code());
826    ///
827    ///             // If this error's code is in our list, return an action that tells the RetryStrategy to retry this request.
828    ///             if let Some(error_code) = error_code {
829    ///                 if RETRYABLE_ERROR_CODES.contains(&error_code) {
830    ///                     return RetryAction::transient_error();
831    ///                 }
832    ///             }
833    ///
834    ///             // Otherwise, return that no action is indicated i.e. that this classifier doesn't require a retry.
835    ///             // Another classifier may still classify this response as retryable.
836    ///             RetryAction::NoActionIndicated
837    ///         }
838    ///
839    ///         fn name(&self) -> &'static str { "Example Error Code Classifier" }
840    ///     }
841    ///
842    ///     builder.push_retry_classifier(ExampleErrorCodeClassifier::<SomeOperationError>::new())
843    /// }
844    ///
845    /// let mut builder = Config::builder();
846    /// set_example_error_code_classifier(&mut builder);
847    /// let config = builder.build();
848    /// # }
849    /// # }
850    /// ```
851    pub fn push_retry_classifier(
852        &mut self,
853        retry_classifier: ::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier,
854    ) -> &mut Self {
855        self.runtime_components.push_retry_classifier(retry_classifier);
856        self
857    }
858
859    /// Set [`SharedRetryClassifier`](::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier)s for the builder, replacing any that
860    /// were previously set.
861    pub fn set_retry_classifiers(
862        &mut self,
863        retry_classifiers: impl IntoIterator<Item = ::aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier>,
864    ) -> &mut Self {
865        self.runtime_components.set_retry_classifiers(retry_classifiers.into_iter());
866        self
867    }
868    /// Sets the name of the app that is using the client.
869    ///
870    /// This _optional_ name is used to identify the application in the user agent that
871    /// gets sent along with requests.
872    pub fn app_name(mut self, app_name: ::aws_types::app_name::AppName) -> Self {
873        self.set_app_name(Some(app_name));
874        self
875    }
876    /// Sets the name of the app that is using the client.
877    ///
878    /// This _optional_ name is used to identify the application in the user agent that
879    /// gets sent along with requests.
880    pub fn set_app_name(&mut self, app_name: ::std::option::Option<::aws_types::app_name::AppName>) -> &mut Self {
881        self.config.store_or_unset(app_name);
882        self
883    }
884    /// Overrides the default invocation ID generator.
885    ///
886    /// 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.
887    pub fn invocation_id_generator(mut self, gen: impl ::aws_runtime::invocation_id::InvocationIdGenerator + 'static) -> Self {
888        self.set_invocation_id_generator(::std::option::Option::Some(
889            ::aws_runtime::invocation_id::SharedInvocationIdGenerator::new(gen),
890        ));
891        self
892    }
893    /// Overrides the default invocation ID generator.
894    ///
895    /// 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.
896    pub fn set_invocation_id_generator(
897        &mut self,
898        gen: ::std::option::Option<::aws_runtime::invocation_id::SharedInvocationIdGenerator>,
899    ) -> &mut Self {
900        self.config.store_or_unset(gen);
901        self
902    }
903    /// Sets the endpoint URL used to communicate with this service
904
905    /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
906    /// will be prefixed onto this URL. To fully override the endpoint resolver, use
907    /// [`Builder::endpoint_resolver`].
908    pub fn endpoint_url(mut self, endpoint_url: impl Into<::std::string::String>) -> Self {
909        self.set_endpoint_url(Some(endpoint_url.into()));
910        self
911    }
912    /// Sets the endpoint URL used to communicate with this service
913
914    /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
915    /// will be prefixed onto this URL. To fully override the endpoint resolver, use
916    /// [`Builder::endpoint_resolver`].
917    pub fn set_endpoint_url(&mut self, endpoint_url: Option<::std::string::String>) -> &mut Self {
918        self.config.store_or_unset(endpoint_url.map(::aws_types::endpoint_config::EndpointUrl));
919        self
920    }
921    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
922    pub fn use_dual_stack(mut self, use_dual_stack: impl Into<bool>) -> Self {
923        self.set_use_dual_stack(Some(use_dual_stack.into()));
924        self
925    }
926    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
927    pub fn set_use_dual_stack(&mut self, use_dual_stack: Option<bool>) -> &mut Self {
928        self.config.store_or_unset(use_dual_stack.map(::aws_types::endpoint_config::UseDualStack));
929        self
930    }
931    /// 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.
932    pub fn use_fips(mut self, use_fips: impl Into<bool>) -> Self {
933        self.set_use_fips(Some(use_fips.into()));
934        self
935    }
936    /// 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.
937    pub fn set_use_fips(&mut self, use_fips: Option<bool>) -> &mut Self {
938        self.config.store_or_unset(use_fips.map(::aws_types::endpoint_config::UseFips));
939        self
940    }
941    /// Sets the AWS region to use when making requests.
942    ///
943    /// # Examples
944    /// ```no_run
945    /// use aws_types::region::Region;
946    /// use aws_sdk_kms::config::{Builder, Config};
947    ///
948    /// let config = aws_sdk_kms::Config::builder()
949    ///     .region(Region::new("us-east-1"))
950    ///     .build();
951    /// ```
952    pub fn region(mut self, region: impl ::std::convert::Into<::std::option::Option<crate::config::Region>>) -> Self {
953        self.set_region(region.into());
954        self
955    }
956    /// Sets the AWS region to use when making requests.
957    pub fn set_region(&mut self, region: ::std::option::Option<crate::config::Region>) -> &mut Self {
958        self.config.store_or_unset(region);
959        self
960    }
961    /// Sets the credentials provider for this service
962    pub fn credentials_provider(mut self, credentials_provider: impl crate::config::ProvideCredentials + 'static) -> Self {
963        self.set_credentials_provider(::std::option::Option::Some(crate::config::SharedCredentialsProvider::new(
964            credentials_provider,
965        )));
966        self
967    }
968    /// Sets the credentials provider for this service
969    pub fn set_credentials_provider(&mut self, credentials_provider: ::std::option::Option<crate::config::SharedCredentialsProvider>) -> &mut Self {
970        if let Some(credentials_provider) = credentials_provider {
971            self.runtime_components
972                .set_identity_resolver(::aws_runtime::auth::sigv4::SCHEME_ID, credentials_provider);
973        }
974        self
975    }
976    /// Sets the [`behavior major version`](crate::config::BehaviorVersion).
977    ///
978    /// Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards
979    /// compatible. For example, a change which introduces new default timeouts or a new retry-mode for
980    /// all operations might be the ideal behavior but could break existing applications.
981    ///
982    /// # Examples
983    ///
984    /// Set the behavior major version to `latest`. This is equivalent to enabling the `behavior-version-latest` cargo feature.
985    /// ```no_run
986    /// use aws_sdk_kms::config::BehaviorVersion;
987    ///
988    /// let config = aws_sdk_kms::Config::builder()
989    ///     .behavior_version(BehaviorVersion::latest())
990    ///     // ...
991    ///     .build();
992    /// let client = aws_sdk_kms::Client::from_conf(config);
993    /// ```
994    ///
995    /// Customizing behavior major version:
996    /// ```no_run
997    /// use aws_sdk_kms::config::BehaviorVersion;
998    ///
999    /// let config = aws_sdk_kms::Config::builder()
1000    ///     .behavior_version(BehaviorVersion::v2023_11_09())
1001    ///     // ...
1002    ///     .build();
1003    /// let client = aws_sdk_kms::Client::from_conf(config);
1004    /// ```
1005
1006    pub fn behavior_version(mut self, behavior_version: crate::config::BehaviorVersion) -> Self {
1007        self.set_behavior_version(Some(behavior_version));
1008        self
1009    }
1010
1011    /// Sets the [`behavior major version`](crate::config::BehaviorVersion).
1012    ///
1013    /// Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards
1014    /// compatible. For example, a change which introduces new default timeouts or a new retry-mode for
1015    /// all operations might be the ideal behavior but could break existing applications.
1016    ///
1017    /// # Examples
1018    ///
1019    /// Set the behavior major version to `latest`. This is equivalent to enabling the `behavior-version-latest` cargo feature.
1020    /// ```no_run
1021    /// use aws_sdk_kms::config::BehaviorVersion;
1022    ///
1023    /// let config = aws_sdk_kms::Config::builder()
1024    ///     .behavior_version(BehaviorVersion::latest())
1025    ///     // ...
1026    ///     .build();
1027    /// let client = aws_sdk_kms::Client::from_conf(config);
1028    /// ```
1029    ///
1030    /// Customizing behavior major version:
1031    /// ```no_run
1032    /// use aws_sdk_kms::config::BehaviorVersion;
1033    ///
1034    /// let config = aws_sdk_kms::Config::builder()
1035    ///     .behavior_version(BehaviorVersion::v2023_11_09())
1036    ///     // ...
1037    ///     .build();
1038    /// let client = aws_sdk_kms::Client::from_conf(config);
1039    /// ```
1040
1041    pub fn set_behavior_version(&mut self, behavior_version: Option<crate::config::BehaviorVersion>) -> &mut Self {
1042        self.behavior_version = behavior_version;
1043        self
1044    }
1045
1046    /// Convenience method to set the latest behavior major version
1047    ///
1048    /// This is equivalent to enabling the `behavior-version-latest` Cargo feature
1049    pub fn behavior_version_latest(mut self) -> Self {
1050        self.set_behavior_version(Some(crate::config::BehaviorVersion::latest()));
1051        self
1052    }
1053    /// Adds a runtime plugin to the config.
1054    #[allow(unused)]
1055    pub(crate) fn runtime_plugin(mut self, plugin: impl crate::config::RuntimePlugin + 'static) -> Self {
1056        self.push_runtime_plugin(crate::config::SharedRuntimePlugin::new(plugin));
1057        self
1058    }
1059    /// Adds a runtime plugin to the config.
1060    #[allow(unused)]
1061    pub(crate) fn push_runtime_plugin(&mut self, plugin: crate::config::SharedRuntimePlugin) -> &mut Self {
1062        self.runtime_plugins.push(plugin);
1063        self
1064    }
1065    #[cfg(any(feature = "test-util", test))]
1066    #[allow(unused_mut)]
1067    /// Apply test defaults to the builder
1068    pub fn apply_test_defaults(&mut self) -> &mut Self {
1069        self.set_time_source(::std::option::Option::Some(::aws_smithy_async::time::SharedTimeSource::new(
1070            ::aws_smithy_async::time::StaticTimeSource::new(::std::time::UNIX_EPOCH + ::std::time::Duration::from_secs(1234567890)),
1071        )));
1072        self.config.store_put(::aws_runtime::user_agent::AwsUserAgent::for_tests());
1073        self.set_credentials_provider(Some(crate::config::SharedCredentialsProvider::new(
1074            ::aws_credential_types::Credentials::for_tests(),
1075        )));
1076        self.behavior_version = ::std::option::Option::Some(crate::config::BehaviorVersion::latest());
1077        self
1078    }
1079    #[cfg(any(feature = "test-util", test))]
1080    #[allow(unused_mut)]
1081    /// Apply test defaults to the builder
1082    pub fn with_test_defaults(mut self) -> Self {
1083        self.apply_test_defaults();
1084        self
1085    }
1086    /// Builds a [`Config`].
1087    #[allow(unused_mut)]
1088    pub fn build(mut self) -> Config {
1089        let mut layer = self.config;
1090        if self.runtime_components.time_source().is_none() {
1091            self.runtime_components
1092                .set_time_source(::std::option::Option::Some(::std::default::Default::default()));
1093        }
1094        layer.store_put(crate::meta::API_METADATA.clone());
1095        layer.store_put(::aws_types::SigningName::from_static("kms"));
1096        layer
1097            .load::<::aws_types::region::Region>()
1098            .cloned()
1099            .map(|r| layer.store_put(::aws_types::region::SigningRegion::from(r)));
1100        Config {
1101            config: crate::config::Layer::from(layer.clone())
1102                .with_name("aws_sdk_kms::config::Config")
1103                .freeze(),
1104            cloneable: layer,
1105            runtime_components: self.runtime_components,
1106            runtime_plugins: self.runtime_plugins,
1107            behavior_version: self.behavior_version,
1108        }
1109    }
1110}
1111#[derive(::std::fmt::Debug)]
1112pub(crate) struct ServiceRuntimePlugin {
1113    config: ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer>,
1114    runtime_components: ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1115}
1116
1117impl ServiceRuntimePlugin {
1118    pub fn new(_service_config: crate::config::Config) -> Self {
1119        let config = { None };
1120        let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin");
1121        runtime_components.set_endpoint_resolver(Some({
1122            use crate::config::endpoint::ResolveEndpoint;
1123            crate::config::endpoint::DefaultResolver::new().into_shared_resolver()
1124        }));
1125        runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new());
1126        runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default());
1127        runtime_components.push_interceptor(crate::sdk_feature_tracker::retry_mode::RetryModeFeatureTrackerInterceptor::new());
1128        runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new());
1129        runtime_components.push_interceptor(::aws_runtime::request_info::RequestInfoInterceptor::new());
1130        runtime_components.push_interceptor(::aws_runtime::user_agent::UserAgentInterceptor::new());
1131        runtime_components.push_interceptor(::aws_runtime::invocation_id::InvocationIdInterceptor::new());
1132        runtime_components.push_interceptor(::aws_runtime::recursion_detection::RecursionDetectionInterceptor::new());
1133        runtime_components.push_auth_scheme(::aws_smithy_runtime_api::client::auth::SharedAuthScheme::new(
1134            ::aws_runtime::auth::sigv4::SigV4AuthScheme::new(),
1135        ));
1136        Self { config, runtime_components }
1137    }
1138}
1139
1140impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for ServiceRuntimePlugin {
1141    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
1142        self.config.clone()
1143    }
1144
1145    fn order(&self) -> ::aws_smithy_runtime_api::client::runtime_plugin::Order {
1146        ::aws_smithy_runtime_api::client::runtime_plugin::Order::Defaults
1147    }
1148
1149    fn runtime_components(
1150        &self,
1151        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1152    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
1153        ::std::borrow::Cow::Borrowed(&self.runtime_components)
1154    }
1155}
1156
1157/// Cross-operation shared-state singletons
1158
1159/// A plugin that enables configuration for a single operation invocation
1160///
1161/// The `config` method will return a `FrozenLayer` by storing values from `config_override`.
1162/// In the case of default values requested, they will be obtained from `client_config`.
1163#[derive(Debug)]
1164pub(crate) struct ConfigOverrideRuntimePlugin {
1165    pub(crate) config: ::aws_smithy_types::config_bag::FrozenLayer,
1166    pub(crate) components: ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1167}
1168
1169impl ConfigOverrideRuntimePlugin {
1170    #[allow(dead_code)] // unused when a service does not provide any operations
1171    pub(crate) fn new(
1172        config_override: Builder,
1173        initial_config: ::aws_smithy_types::config_bag::FrozenLayer,
1174        initial_components: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1175    ) -> Self {
1176        let mut layer = config_override.config;
1177        let mut components = config_override.runtime_components;
1178        #[allow(unused_mut)]
1179        let mut resolver =
1180            ::aws_smithy_runtime::client::config_override::Resolver::overrid(initial_config, initial_components, &mut layer, &mut components);
1181
1182        resolver
1183            .config_mut()
1184            .load::<::aws_types::region::Region>()
1185            .cloned()
1186            .map(|r| resolver.config_mut().store_put(::aws_types::region::SigningRegion::from(r)));
1187
1188        let _ = resolver;
1189        Self {
1190            config: ::aws_smithy_types::config_bag::Layer::from(layer)
1191                .with_name("aws_sdk_kms::config::ConfigOverrideRuntimePlugin")
1192                .freeze(),
1193            components,
1194        }
1195    }
1196}
1197
1198impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for ConfigOverrideRuntimePlugin {
1199    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
1200        Some(self.config.clone())
1201    }
1202
1203    fn runtime_components(
1204        &self,
1205        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
1206    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
1207        ::std::borrow::Cow::Borrowed(&self.components)
1208    }
1209}
1210
1211pub use ::aws_smithy_runtime::client::identity::IdentityCache;
1212pub use ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
1213pub use ::aws_smithy_types::config_bag::ConfigBag;
1214
1215pub use ::aws_credential_types::Credentials;
1216
1217impl From<&::aws_types::sdk_config::SdkConfig> for Builder {
1218    fn from(input: &::aws_types::sdk_config::SdkConfig) -> Self {
1219        let mut builder = Builder::default();
1220        builder.set_credentials_provider(input.credentials_provider());
1221        builder = builder.region(input.region().cloned());
1222        builder.set_use_fips(input.use_fips());
1223        builder.set_use_dual_stack(input.use_dual_stack());
1224        if input.get_origin("endpoint_url").is_client_config() {
1225            builder.set_endpoint_url(input.endpoint_url().map(|s| s.to_string()));
1226        } else {
1227            builder.set_endpoint_url(
1228                input
1229                    .service_config()
1230                    .and_then(|conf| {
1231                        conf.load_config(service_config_key("AWS_ENDPOINT_URL", "endpoint_url"))
1232                            .map(|it| it.parse().unwrap())
1233                    })
1234                    .or_else(|| input.endpoint_url().map(|s| s.to_string())),
1235            );
1236        }
1237        // resiliency
1238        builder.set_retry_config(input.retry_config().cloned());
1239        builder.set_timeout_config(input.timeout_config().cloned());
1240        builder.set_sleep_impl(input.sleep_impl());
1241
1242        builder.set_http_client(input.http_client());
1243        builder.set_time_source(input.time_source());
1244        builder.set_behavior_version(input.behavior_version());
1245        // setting `None` here removes the default
1246        if let Some(config) = input.stalled_stream_protection() {
1247            builder.set_stalled_stream_protection(Some(config));
1248        }
1249
1250        if let Some(cache) = input.identity_cache() {
1251            builder.set_identity_cache(cache);
1252        }
1253        builder.set_app_name(input.app_name().cloned());
1254
1255        builder
1256    }
1257}
1258
1259impl From<&::aws_types::sdk_config::SdkConfig> for Config {
1260    fn from(sdk_config: &::aws_types::sdk_config::SdkConfig) -> Self {
1261        Builder::from(sdk_config).build()
1262    }
1263}
1264
1265pub use ::aws_types::app_name::AppName;
1266
1267#[allow(dead_code)]
1268fn service_config_key<'a>(env: &'a str, profile: &'a str) -> aws_types::service_config::ServiceConfigKey<'a> {
1269    ::aws_types::service_config::ServiceConfigKey::builder()
1270        .service_id("kms")
1271        .env(env)
1272        .profile(profile)
1273        .build()
1274        .expect("all field sets explicitly, can't fail")
1275}
1276
1277pub use ::aws_smithy_async::rt::sleep::Sleep;
1278
1279pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
1280    let mut configured_plugins = ::std::vec::Vec::new();
1281    ::std::mem::swap(&mut config.runtime_plugins, &mut configured_plugins);
1282    #[cfg(feature = "behavior-version-latest")]
1283    {
1284        if config.behavior_version.is_none() {
1285            config.behavior_version = Some(::aws_smithy_runtime_api::client::behavior_version::BehaviorVersion::latest());
1286        }
1287    }
1288
1289    let default_retry_partition = "kms";
1290    let default_retry_partition = match config.region() {
1291        Some(region) => ::std::borrow::Cow::from(format!("{default_retry_partition}-{}", region)),
1292        None => ::std::borrow::Cow::from(default_retry_partition),
1293    };
1294
1295    let mut plugins = ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins::new()
1296                        // defaults
1297                        .with_client_plugins(::aws_smithy_runtime::client::defaults::default_plugins(
1298                            ::aws_smithy_runtime::client::defaults::DefaultPluginParams::new()
1299                                .with_retry_partition_name(default_retry_partition)
1300                                .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."))
1301                        ))
1302                        // user config
1303                        .with_client_plugin(
1304                            ::aws_smithy_runtime_api::client::runtime_plugin::StaticRuntimePlugin::new()
1305                                .with_config(config.config.clone())
1306                                .with_runtime_components(config.runtime_components.clone())
1307                        )
1308                        // codegen config
1309                        .with_client_plugin(crate::config::ServiceRuntimePlugin::new(config.clone()))
1310                        .with_client_plugin(::aws_smithy_runtime::client::auth::no_auth::NoAuthRuntimePlugin::new());
1311
1312    for plugin in configured_plugins {
1313        plugins = plugins.with_client_plugin(plugin);
1314    }
1315    plugins
1316}
1317
1318pub use ::aws_smithy_types::config_bag::FrozenLayer;
1319
1320pub use ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
1321
1322pub use ::aws_smithy_runtime_api::client::runtime_plugin::SharedRuntimePlugin;
1323
1324pub use ::aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
1325
1326pub use ::aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
1327
1328pub use ::aws_smithy_runtime_api::client::http::SharedHttpClient;
1329
1330pub use ::aws_smithy_async::rt::sleep::SharedAsyncSleep;
1331
1332pub use ::aws_smithy_runtime_api::client::identity::SharedIdentityCache;
1333
1334pub use ::aws_smithy_runtime_api::client::interceptors::SharedInterceptor;
1335
1336pub use ::aws_types::region::Region;
1337
1338pub use ::aws_credential_types::provider::SharedCredentialsProvider;
1339
1340pub use ::aws_smithy_runtime_api::client::http::HttpClient;
1341
1342pub use ::aws_smithy_runtime_api::shared::IntoShared;
1343
1344pub use ::aws_smithy_async::rt::sleep::AsyncSleep;
1345
1346pub use ::aws_smithy_runtime_api::client::identity::ResolveCachedIdentity;
1347
1348pub use ::aws_smithy_runtime_api::client::interceptors::Intercept;
1349
1350pub use ::aws_credential_types::provider::ProvideCredentials;
1351
1352pub use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
1353
1354pub use ::aws_smithy_types::config_bag::Layer;
1355
1356/// Types needed to configure endpoint resolution.
1357pub mod endpoint;
1358
1359/// HTTP request and response types.
1360pub mod http;
1361
1362/// Types needed to implement [`Intercept`](crate::config::Intercept).
1363pub mod interceptors;
1364
1365/// Retry configuration.
1366pub mod retry;
1367
1368/// Timeout configuration.
1369pub mod timeout;