stedi_sdk_client_guides/
config.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// Service config.
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///
19pub struct Config {
20    api_key: Option<aws_smithy_http_auth::api_key::AuthApiKey>,
21    #[allow(missing_docs)] // documentation missing in model
22    pub(crate) stage: std::option::Option<std::string::String>,
23    pub(crate) endpoint_resolver:
24        std::sync::Arc<dyn aws_smithy_http::endpoint::ResolveEndpoint<crate::endpoint::Params>>,
25    retry_config: Option<aws_smithy_types::retry::RetryConfig>,
26    sleep_impl: Option<std::sync::Arc<dyn aws_smithy_async::rt::sleep::AsyncSleep>>,
27    timeout_config: Option<aws_smithy_types::timeout::TimeoutConfig>,
28    app_name: Option<aws_types::app_name::AppName>,
29    #[allow(missing_docs)] // documentation missing in model
30    pub(crate) endpoint_url: std::option::Option<std::string::String>,
31    http_connector: Option<aws_smithy_client::http_connector::HttpConnector>,
32    pub(crate) region: Option<aws_types::region::Region>,
33}
34impl std::fmt::Debug for Config {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        let mut config = f.debug_struct("Config");
37        config.finish()
38    }
39}
40impl Config {
41    /// Constructs a config builder.
42    pub fn builder() -> Builder {
43        Builder::default()
44    }
45    /// Returns API key used by the client, if it was provided.
46    pub fn api_key(&self) -> Option<&aws_smithy_http_auth::api_key::AuthApiKey> {
47        self.api_key.as_ref()
48    }
49    /// Returns the endpoint resolver.
50    pub fn endpoint_resolver(
51        &self,
52    ) -> std::sync::Arc<dyn aws_smithy_http::endpoint::ResolveEndpoint<crate::endpoint::Params>>
53    {
54        self.endpoint_resolver.clone()
55    }
56    /// Return a reference to the retry configuration contained in this config, if any.
57    pub fn retry_config(&self) -> Option<&aws_smithy_types::retry::RetryConfig> {
58        self.retry_config.as_ref()
59    }
60
61    /// Return a cloned Arc containing the async sleep implementation from this config, if any.
62    pub fn sleep_impl(
63        &self,
64    ) -> Option<std::sync::Arc<dyn aws_smithy_async::rt::sleep::AsyncSleep>> {
65        self.sleep_impl.clone()
66    }
67
68    /// Return a reference to the timeout configuration contained in this config, if any.
69    pub fn timeout_config(&self) -> Option<&aws_smithy_types::timeout::TimeoutConfig> {
70        self.timeout_config.as_ref()
71    }
72    /// Returns the name of the app that is using the client, if it was provided.
73    ///
74    /// This _optional_ name is used to identify the application in the user agent that
75    /// gets sent along with requests.
76    pub fn app_name(&self) -> Option<&aws_types::app_name::AppName> {
77        self.app_name.as_ref()
78    }
79    /// Return an [`HttpConnector`](aws_smithy_client::http_connector::HttpConnector) to use when making requests, if any.
80    pub fn http_connector(&self) -> Option<&aws_smithy_client::http_connector::HttpConnector> {
81        self.http_connector.as_ref()
82    }
83    /// Creates a new [service config](crate::Config) from a [shared `config`](stedi_sdk_config::sdk_config::SdkConfig).
84    pub fn new(config: &stedi_sdk_config::sdk_config::SdkConfig) -> Self {
85        Builder::from(config).build()
86    }
87    /// Returns the AWS region, if it was provided.
88    pub fn region(&self) -> Option<&aws_types::region::Region> {
89        self.region.as_ref()
90    }
91}
92/// Builder for creating a `Config`.
93#[derive(Default)]
94pub struct Builder {
95    api_key: Option<aws_smithy_http_auth::api_key::AuthApiKey>,
96    stage: std::option::Option<std::string::String>,
97    endpoint_resolver: Option<
98        std::sync::Arc<dyn aws_smithy_http::endpoint::ResolveEndpoint<crate::endpoint::Params>>,
99    >,
100    retry_config: Option<aws_smithy_types::retry::RetryConfig>,
101    sleep_impl: Option<std::sync::Arc<dyn aws_smithy_async::rt::sleep::AsyncSleep>>,
102    timeout_config: Option<aws_smithy_types::timeout::TimeoutConfig>,
103    app_name: Option<aws_types::app_name::AppName>,
104    endpoint_url: std::option::Option<std::string::String>,
105    http_connector: Option<aws_smithy_client::http_connector::HttpConnector>,
106    region: Option<aws_types::region::Region>,
107}
108impl Builder {
109    /// Constructs a config builder.
110    pub fn new() -> Self {
111        Self::default()
112    }
113    /// Sets the API key that will be used by the client.
114    pub fn api_key(mut self, api_key: aws_smithy_http_auth::api_key::AuthApiKey) -> Self {
115        self.set_api_key(Some(api_key));
116        self
117    }
118
119    /// Sets the API key that will be used by the client.
120    pub fn set_api_key(
121        &mut self,
122        api_key: Option<aws_smithy_http_auth::api_key::AuthApiKey>,
123    ) -> &mut Self {
124        self.api_key = api_key;
125        self
126    }
127    /// The endpoint stage used to contruct the hostname.
128    pub fn stage(mut self, stage: impl Into<std::string::String>) -> Self {
129        self.stage = Some(stage.into());
130        self
131    }
132    /// The endpoint stage used to contruct the hostname.
133    pub fn set_stage(&mut self, stage: Option<std::string::String>) -> &mut Self {
134        self.stage = stage;
135        self
136    }
137    /// Sets the endpoint resolver to use when making requests.
138
139    ///
140    /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
141    /// rules for `stedi_sdk_client_guides`.
142    ///
143    /// # Examples
144    /// ```no_run
145    /// use aws_smithy_http::endpoint;
146    /// use stedi_sdk_client_guides::endpoint::{Params as EndpointParams, DefaultResolver};
147    /// /// Endpoint resolver which adds a prefix to the generated endpoint
148    /// struct PrefixResolver {
149    ///     base_resolver: DefaultResolver,
150    ///     prefix: String
151    /// }
152    /// impl endpoint::ResolveEndpoint<EndpointParams> for PrefixResolver {
153    ///   fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result {
154    ///        self.base_resolver
155    ///              .resolve_endpoint(params)
156    ///              .map(|ep|{
157    ///                   let url = ep.url().to_string();
158    ///                   ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build()
159    ///               })
160    ///   }
161    /// }
162    /// let prefix_resolver = PrefixResolver {
163    ///     base_resolver: DefaultResolver::new(),
164    ///     prefix: "subdomain".to_string()
165    /// };
166    /// let config = stedi_sdk_client_guides::Config::builder().endpoint_resolver(prefix_resolver);
167    /// ```
168
169    pub fn endpoint_resolver(
170        mut self,
171        endpoint_resolver: impl aws_smithy_http::endpoint::ResolveEndpoint<crate::endpoint::Params>
172            + 'static,
173    ) -> Self {
174        self.endpoint_resolver = Some(std::sync::Arc::new(endpoint_resolver) as _);
175        self
176    }
177
178    /// Sets the endpoint resolver to use when making requests.
179    ///
180    /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
181    /// rules for `stedi_sdk_client_guides`.
182    pub fn set_endpoint_resolver(
183        &mut self,
184        endpoint_resolver: Option<
185            std::sync::Arc<dyn aws_smithy_http::endpoint::ResolveEndpoint<crate::endpoint::Params>>,
186        >,
187    ) -> &mut Self {
188        self.endpoint_resolver = endpoint_resolver;
189        self
190    }
191    /// Set the retry_config for the builder
192    ///
193    /// # Examples
194    /// ```no_run
195    /// use stedi_sdk_client_guides::config::Config;
196    /// use stedi_sdk_client_guides::config::retry::RetryConfig;
197    ///
198    /// let retry_config = RetryConfig::standard().with_max_attempts(5);
199    /// let config = Config::builder().retry_config(retry_config).build();
200    /// ```
201    pub fn retry_config(mut self, retry_config: aws_smithy_types::retry::RetryConfig) -> Self {
202        self.set_retry_config(Some(retry_config));
203        self
204    }
205
206    /// Set the retry_config for the builder
207    ///
208    /// # Examples
209    /// ```no_run
210    /// use stedi_sdk_client_guides::config::{Builder, Config};
211    /// use stedi_sdk_client_guides::config::retry::RetryConfig;
212    ///
213    /// fn disable_retries(builder: &mut Builder) {
214    ///     let retry_config = RetryConfig::standard().with_max_attempts(1);
215    ///     builder.set_retry_config(Some(retry_config));
216    /// }
217    ///
218    /// let mut builder = Config::builder();
219    /// disable_retries(&mut builder);
220    /// let config = builder.build();
221    /// ```
222    pub fn set_retry_config(
223        &mut self,
224        retry_config: Option<aws_smithy_types::retry::RetryConfig>,
225    ) -> &mut Self {
226        self.retry_config = retry_config;
227        self
228    }
229
230    /// Set the sleep_impl for the builder
231    ///
232    /// # Examples
233    ///
234    /// ```no_run
235    /// use stedi_sdk_client_guides::config::{AsyncSleep, Sleep, Config};
236    ///
237    /// #[derive(Debug)]
238    /// pub struct ForeverSleep;
239    ///
240    /// impl AsyncSleep for ForeverSleep {
241    ///     fn sleep(&self, duration: std::time::Duration) -> Sleep {
242    ///         Sleep::new(std::future::pending())
243    ///     }
244    /// }
245    ///
246    /// let sleep_impl = std::sync::Arc::new(ForeverSleep);
247    /// let config = Config::builder().sleep_impl(sleep_impl).build();
248    /// ```
249    pub fn sleep_impl(
250        mut self,
251        sleep_impl: std::sync::Arc<dyn aws_smithy_async::rt::sleep::AsyncSleep>,
252    ) -> Self {
253        self.set_sleep_impl(Some(sleep_impl));
254        self
255    }
256
257    /// Set the sleep_impl for the builder
258    ///
259    /// # Examples
260    ///
261    /// ```no_run
262    /// use stedi_sdk_client_guides::config::{AsyncSleep, Sleep, Builder, Config};
263    ///
264    /// #[derive(Debug)]
265    /// pub struct ForeverSleep;
266    ///
267    /// impl AsyncSleep for ForeverSleep {
268    ///     fn sleep(&self, duration: std::time::Duration) -> Sleep {
269    ///         Sleep::new(std::future::pending())
270    ///     }
271    /// }
272    ///
273    /// fn set_never_ending_sleep_impl(builder: &mut Builder) {
274    ///     let sleep_impl = std::sync::Arc::new(ForeverSleep);
275    ///     builder.set_sleep_impl(Some(sleep_impl));
276    /// }
277    ///
278    /// let mut builder = Config::builder();
279    /// set_never_ending_sleep_impl(&mut builder);
280    /// let config = builder.build();
281    /// ```
282    pub fn set_sleep_impl(
283        &mut self,
284        sleep_impl: Option<std::sync::Arc<dyn aws_smithy_async::rt::sleep::AsyncSleep>>,
285    ) -> &mut Self {
286        self.sleep_impl = sleep_impl;
287        self
288    }
289
290    /// Set the timeout_config for the builder
291    ///
292    /// # Examples
293    ///
294    /// ```no_run
295    /// # use std::time::Duration;
296    /// use stedi_sdk_client_guides::config::Config;
297    /// use stedi_sdk_client_guides::config::timeout::TimeoutConfig;
298    ///
299    /// let timeout_config = TimeoutConfig::builder()
300    ///     .operation_attempt_timeout(Duration::from_secs(1))
301    ///     .build();
302    /// let config = Config::builder().timeout_config(timeout_config).build();
303    /// ```
304    pub fn timeout_config(
305        mut self,
306        timeout_config: aws_smithy_types::timeout::TimeoutConfig,
307    ) -> Self {
308        self.set_timeout_config(Some(timeout_config));
309        self
310    }
311
312    /// Set the timeout_config for the builder
313    ///
314    /// # Examples
315    ///
316    /// ```no_run
317    /// # use std::time::Duration;
318    /// use stedi_sdk_client_guides::config::{Builder, Config};
319    /// use stedi_sdk_client_guides::config::timeout::TimeoutConfig;
320    ///
321    /// fn set_request_timeout(builder: &mut Builder) {
322    ///     let timeout_config = TimeoutConfig::builder()
323    ///         .operation_attempt_timeout(Duration::from_secs(1))
324    ///         .build();
325    ///     builder.set_timeout_config(Some(timeout_config));
326    /// }
327    ///
328    /// let mut builder = Config::builder();
329    /// set_request_timeout(&mut builder);
330    /// let config = builder.build();
331    /// ```
332    pub fn set_timeout_config(
333        &mut self,
334        timeout_config: Option<aws_smithy_types::timeout::TimeoutConfig>,
335    ) -> &mut Self {
336        self.timeout_config = timeout_config;
337        self
338    }
339    /// Sets the name of the app that is using the client.
340    ///
341    /// This _optional_ name is used to identify the application in the user agent that
342    /// gets sent along with requests.
343    pub fn app_name(mut self, app_name: aws_types::app_name::AppName) -> Self {
344        self.set_app_name(Some(app_name));
345        self
346    }
347
348    /// Sets the name of the app that is using the client.
349    ///
350    /// This _optional_ name is used to identify the application in the user agent that
351    /// gets sent along with requests.
352    pub fn set_app_name(&mut self, app_name: Option<aws_types::app_name::AppName>) -> &mut Self {
353        self.app_name = app_name;
354        self
355    }
356    /// Sets the endpoint url used to communicate with this service
357
358    /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
359    /// will be prefixed onto this URL. To fully override the endpoint resolver, use
360    /// [`Builder::endpoint_resolver`].
361    pub fn endpoint_url(mut self, endpoint_url: impl Into<std::string::String>) -> Self {
362        self.endpoint_url = Some(endpoint_url.into());
363        self
364    }
365    /// Sets the endpoint url used to communicate with this service
366
367    /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
368    /// will be prefixed onto this URL. To fully override the endpoint resolver, use
369    /// [`Builder::endpoint_resolver`].
370    pub fn set_endpoint_url(&mut self, endpoint_url: Option<std::string::String>) -> &mut Self {
371        self.endpoint_url = endpoint_url;
372        self
373    }
374    /// Sets the HTTP connector to use when making requests.
375    ///
376    /// # Examples
377    /// ```no_run
378    /// # #[cfg(test)]
379    /// # mod tests {
380    /// # #[test]
381    /// # fn example() {
382    /// use std::time::Duration;
383    /// use aws_smithy_client::{Client, hyper_ext};
384    /// use aws_smithy_client::erase::DynConnector;
385    /// use aws_smithy_client::http_connector::ConnectorSettings;
386    /// use stedi_sdk_client_guides::config::Config;
387    ///
388    /// let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
389    ///     .with_webpki_roots()
390    ///     .https_only()
391    ///     .enable_http1()
392    ///     .enable_http2()
393    ///     .build();
394    /// let smithy_connector = hyper_ext::Adapter::builder()
395    ///     // Optionally set things like timeouts as well
396    ///     .connector_settings(
397    ///         ConnectorSettings::builder()
398    ///             .connect_timeout(Duration::from_secs(5))
399    ///             .build()
400    ///     )
401    ///     .build(https_connector);
402    /// # }
403    /// # }
404    /// ```
405    pub fn http_connector(
406        mut self,
407        http_connector: impl Into<aws_smithy_client::http_connector::HttpConnector>,
408    ) -> Self {
409        self.http_connector = Some(http_connector.into());
410        self
411    }
412
413    /// Sets the HTTP connector to use when making requests.
414    ///
415    /// # Examples
416    /// ```no_run
417    /// # #[cfg(test)]
418    /// # mod tests {
419    /// # #[test]
420    /// # fn example() {
421    /// use std::time::Duration;
422    /// use aws_smithy_client::hyper_ext;
423    /// use aws_smithy_client::http_connector::ConnectorSettings;
424    /// use crate::sdk_config::{SdkConfig, Builder};
425    /// use stedi_sdk_client_guides::config::{Builder, Config};
426    ///
427    /// fn override_http_connector(builder: &mut Builder) {
428    ///     let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
429    ///         .with_webpki_roots()
430    ///         .https_only()
431    ///         .enable_http1()
432    ///         .enable_http2()
433    ///         .build();
434    ///     let smithy_connector = hyper_ext::Adapter::builder()
435    ///         // Optionally set things like timeouts as well
436    ///         .connector_settings(
437    ///             ConnectorSettings::builder()
438    ///                 .connect_timeout(Duration::from_secs(5))
439    ///                 .build()
440    ///         )
441    ///         .build(https_connector);
442    ///     builder.set_http_connector(Some(smithy_connector));
443    /// }
444    ///
445    /// let mut builder = stedi_sdk_client_guides::Config::builder();
446    /// override_http_connector(&mut builder);
447    /// let config = builder.build();
448    /// # }
449    /// # }
450    /// ```
451    pub fn set_http_connector(
452        &mut self,
453        http_connector: Option<impl Into<aws_smithy_client::http_connector::HttpConnector>>,
454    ) -> &mut Self {
455        self.http_connector = http_connector.map(|inner| inner.into());
456        self
457    }
458    /// Sets the AWS region to use when making requests.
459    ///
460    /// # Examples
461    /// ```no_run
462    /// use aws_types::region::Region;
463    /// use stedi_sdk_client_guides::config::{Builder, Config};
464    ///
465    /// let config = stedi_sdk_client_guides::Config::builder()
466    ///     .region(Region::new("us-east-1"))
467    ///     .build();
468    /// ```
469    pub fn region(mut self, region: impl Into<Option<aws_types::region::Region>>) -> Self {
470        self.region = region.into();
471        self
472    }
473    #[cfg(any(feature = "test-util", test))]
474    #[allow(unused_mut)]
475    /// Apply test defaults to the builder
476    pub fn set_test_defaults(&mut self) -> &mut Self {
477        self
478    }
479    #[cfg(any(feature = "test-util", test))]
480    #[allow(unused_mut)]
481    /// Apply test defaults to the builder
482    pub fn with_test_defaults(mut self) -> Self {
483        self.set_test_defaults();
484        self
485    }
486    /// Builds a [`Config`].
487    pub fn build(self) -> Config {
488        Config {
489            api_key: self.api_key,
490            stage: self.stage,
491            endpoint_resolver: self
492                .endpoint_resolver
493                .unwrap_or_else(|| std::sync::Arc::new(crate::endpoint::DefaultResolver::new())),
494            retry_config: self.retry_config,
495            sleep_impl: self.sleep_impl.clone(),
496            timeout_config: self.timeout_config,
497            app_name: self.app_name,
498            endpoint_url: self.endpoint_url,
499            http_connector: self.http_connector,
500            region: self.region,
501        }
502    }
503}
504
505impl From<&stedi_sdk_config::sdk_config::SdkConfig> for Builder {
506    fn from(input: &stedi_sdk_config::sdk_config::SdkConfig) -> Self {
507        let mut builder = Builder::default();
508        builder.set_api_key(input.api_key().cloned());
509        builder = builder.region(input.region().cloned());
510        builder.set_endpoint_url(input.endpoint_url().map(|s| s.to_string()));
511        // resiliency
512        builder.set_retry_config(input.retry_config().cloned());
513        builder.set_timeout_config(input.timeout_config().cloned());
514        builder.set_sleep_impl(input.sleep_impl());
515
516        builder.set_http_connector(input.http_connector().cloned());
517        builder.set_app_name(input.app_name().cloned());
518        builder
519    }
520}
521impl From<&stedi_sdk_config::sdk_config::SdkConfig> for Config {
522    fn from(sdk_config: &stedi_sdk_config::sdk_config::SdkConfig) -> Self {
523        Builder::from(sdk_config).build()
524    }
525}
526
527pub use aws_smithy_async::rt::sleep::{AsyncSleep, Sleep};
528
529/// Retry configuration
530///
531/// These are re-exported from `aws-smithy-types` for convenience.
532pub mod retry {
533    pub use aws_smithy_types::retry::{RetryConfig, RetryConfigBuilder, RetryMode};
534}
535/// Timeout configuration
536///
537/// These are re-exported from `aws-smithy-types` for convenience.
538pub mod timeout {
539    pub use aws_smithy_types::timeout::{TimeoutConfig, TimeoutConfigBuilder};
540}
541
542pub use aws_smithy_http_auth::api_key::AuthApiKey;