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