aws_sdk_iotmanagedintegrations/config/
endpoint.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture;
3pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver;
4pub use ::aws_smithy_types::endpoint::Endpoint;
5
6#[cfg(test)]
7mod test {
8
9    /// For custom endpoint with region not set and fips disabled
10    #[test]
11    fn test_1() {
12        let params = crate::config::endpoint::Params::builder()
13            .endpoint("https://example.com".to_string())
14            .use_fips(false)
15            .build()
16            .expect("invalid params");
17        let resolver = crate::config::endpoint::DefaultResolver::new();
18        let endpoint = resolver.resolve_endpoint(&params);
19        let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
20        assert_eq!(
21            endpoint,
22            ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
23        );
24    }
25
26    /// For custom endpoint with fips enabled
27    #[test]
28    fn test_2() {
29        let params = crate::config::endpoint::Params::builder()
30            .endpoint("https://example.com".to_string())
31            .use_fips(true)
32            .build()
33            .expect("invalid params");
34        let resolver = crate::config::endpoint::DefaultResolver::new();
35        let endpoint = resolver.resolve_endpoint(&params);
36        let error = endpoint
37            .expect_err("expected error: Invalid Configuration: FIPS and custom endpoint are not supported [For custom endpoint with fips enabled]");
38        assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
39    }
40
41    /// For region us-east-1 with FIPS enabled and DualStack enabled
42    #[test]
43    fn test_3() {
44        let params = crate::config::endpoint::Params::builder()
45            .region("us-east-1".to_string())
46            .use_fips(true)
47            .build()
48            .expect("invalid params");
49        let resolver = crate::config::endpoint::DefaultResolver::new();
50        let endpoint = resolver.resolve_endpoint(&params);
51        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations-fips.us-east-1.api.aws");
52        assert_eq!(
53            endpoint,
54            ::aws_smithy_types::endpoint::Endpoint::builder()
55                .url("https://api.iotmanagedintegrations-fips.us-east-1.api.aws")
56                .build()
57        );
58    }
59
60    /// For region us-east-1 with FIPS disabled and DualStack enabled
61    #[test]
62    fn test_4() {
63        let params = crate::config::endpoint::Params::builder()
64            .region("us-east-1".to_string())
65            .use_fips(false)
66            .build()
67            .expect("invalid params");
68        let resolver = crate::config::endpoint::DefaultResolver::new();
69        let endpoint = resolver.resolve_endpoint(&params);
70        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations.us-east-1.api.aws");
71        assert_eq!(
72            endpoint,
73            ::aws_smithy_types::endpoint::Endpoint::builder()
74                .url("https://api.iotmanagedintegrations.us-east-1.api.aws")
75                .build()
76        );
77    }
78
79    /// For region cn-northwest-1 with FIPS enabled and DualStack enabled
80    #[test]
81    fn test_5() {
82        let params = crate::config::endpoint::Params::builder()
83            .region("cn-northwest-1".to_string())
84            .use_fips(true)
85            .build()
86            .expect("invalid params");
87        let resolver = crate::config::endpoint::DefaultResolver::new();
88        let endpoint = resolver.resolve_endpoint(&params);
89        let endpoint =
90            endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations-fips.cn-northwest-1.api.amazonwebservices.com.cn");
91        assert_eq!(
92            endpoint,
93            ::aws_smithy_types::endpoint::Endpoint::builder()
94                .url("https://api.iotmanagedintegrations-fips.cn-northwest-1.api.amazonwebservices.com.cn")
95                .build()
96        );
97    }
98
99    /// For region cn-northwest-1 with FIPS disabled and DualStack enabled
100    #[test]
101    fn test_6() {
102        let params = crate::config::endpoint::Params::builder()
103            .region("cn-northwest-1".to_string())
104            .use_fips(false)
105            .build()
106            .expect("invalid params");
107        let resolver = crate::config::endpoint::DefaultResolver::new();
108        let endpoint = resolver.resolve_endpoint(&params);
109        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations.cn-northwest-1.api.amazonwebservices.com.cn");
110        assert_eq!(
111            endpoint,
112            ::aws_smithy_types::endpoint::Endpoint::builder()
113                .url("https://api.iotmanagedintegrations.cn-northwest-1.api.amazonwebservices.com.cn")
114                .build()
115        );
116    }
117
118    /// For region us-gov-west-1 with FIPS enabled and DualStack enabled
119    #[test]
120    fn test_7() {
121        let params = crate::config::endpoint::Params::builder()
122            .region("us-gov-west-1".to_string())
123            .use_fips(true)
124            .build()
125            .expect("invalid params");
126        let resolver = crate::config::endpoint::DefaultResolver::new();
127        let endpoint = resolver.resolve_endpoint(&params);
128        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations-fips.us-gov-west-1.api.aws");
129        assert_eq!(
130            endpoint,
131            ::aws_smithy_types::endpoint::Endpoint::builder()
132                .url("https://api.iotmanagedintegrations-fips.us-gov-west-1.api.aws")
133                .build()
134        );
135    }
136
137    /// For region us-gov-west-1 with FIPS disabled and DualStack enabled
138    #[test]
139    fn test_8() {
140        let params = crate::config::endpoint::Params::builder()
141            .region("us-gov-west-1".to_string())
142            .use_fips(false)
143            .build()
144            .expect("invalid params");
145        let resolver = crate::config::endpoint::DefaultResolver::new();
146        let endpoint = resolver.resolve_endpoint(&params);
147        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations.us-gov-west-1.api.aws");
148        assert_eq!(
149            endpoint,
150            ::aws_smithy_types::endpoint::Endpoint::builder()
151                .url("https://api.iotmanagedintegrations.us-gov-west-1.api.aws")
152                .build()
153        );
154    }
155
156    /// For region us-iso-east-1 with FIPS enabled and DualStack enabled
157    #[test]
158    fn test_9() {
159        let params = crate::config::endpoint::Params::builder()
160            .region("us-iso-east-1".to_string())
161            .use_fips(true)
162            .build()
163            .expect("invalid params");
164        let resolver = crate::config::endpoint::DefaultResolver::new();
165        let endpoint = resolver.resolve_endpoint(&params);
166        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations-fips.us-iso-east-1.c2s.ic.gov");
167        assert_eq!(
168            endpoint,
169            ::aws_smithy_types::endpoint::Endpoint::builder()
170                .url("https://api.iotmanagedintegrations-fips.us-iso-east-1.c2s.ic.gov")
171                .build()
172        );
173    }
174
175    /// For region us-iso-east-1 with FIPS disabled and DualStack enabled
176    #[test]
177    fn test_10() {
178        let params = crate::config::endpoint::Params::builder()
179            .region("us-iso-east-1".to_string())
180            .use_fips(false)
181            .build()
182            .expect("invalid params");
183        let resolver = crate::config::endpoint::DefaultResolver::new();
184        let endpoint = resolver.resolve_endpoint(&params);
185        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations.us-iso-east-1.c2s.ic.gov");
186        assert_eq!(
187            endpoint,
188            ::aws_smithy_types::endpoint::Endpoint::builder()
189                .url("https://api.iotmanagedintegrations.us-iso-east-1.c2s.ic.gov")
190                .build()
191        );
192    }
193
194    /// For region us-isob-east-1 with FIPS enabled and DualStack enabled
195    #[test]
196    fn test_11() {
197        let params = crate::config::endpoint::Params::builder()
198            .region("us-isob-east-1".to_string())
199            .use_fips(true)
200            .build()
201            .expect("invalid params");
202        let resolver = crate::config::endpoint::DefaultResolver::new();
203        let endpoint = resolver.resolve_endpoint(&params);
204        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations-fips.us-isob-east-1.sc2s.sgov.gov");
205        assert_eq!(
206            endpoint,
207            ::aws_smithy_types::endpoint::Endpoint::builder()
208                .url("https://api.iotmanagedintegrations-fips.us-isob-east-1.sc2s.sgov.gov")
209                .build()
210        );
211    }
212
213    /// For region us-isob-east-1 with FIPS disabled and DualStack enabled
214    #[test]
215    fn test_12() {
216        let params = crate::config::endpoint::Params::builder()
217            .region("us-isob-east-1".to_string())
218            .use_fips(false)
219            .build()
220            .expect("invalid params");
221        let resolver = crate::config::endpoint::DefaultResolver::new();
222        let endpoint = resolver.resolve_endpoint(&params);
223        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations.us-isob-east-1.sc2s.sgov.gov");
224        assert_eq!(
225            endpoint,
226            ::aws_smithy_types::endpoint::Endpoint::builder()
227                .url("https://api.iotmanagedintegrations.us-isob-east-1.sc2s.sgov.gov")
228                .build()
229        );
230    }
231
232    /// For region eu-isoe-west-1 with FIPS enabled and DualStack enabled
233    #[test]
234    fn test_13() {
235        let params = crate::config::endpoint::Params::builder()
236            .region("eu-isoe-west-1".to_string())
237            .use_fips(true)
238            .build()
239            .expect("invalid params");
240        let resolver = crate::config::endpoint::DefaultResolver::new();
241        let endpoint = resolver.resolve_endpoint(&params);
242        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations-fips.eu-isoe-west-1.cloud.adc-e.uk");
243        assert_eq!(
244            endpoint,
245            ::aws_smithy_types::endpoint::Endpoint::builder()
246                .url("https://api.iotmanagedintegrations-fips.eu-isoe-west-1.cloud.adc-e.uk")
247                .build()
248        );
249    }
250
251    /// For region eu-isoe-west-1 with FIPS disabled and DualStack enabled
252    #[test]
253    fn test_14() {
254        let params = crate::config::endpoint::Params::builder()
255            .region("eu-isoe-west-1".to_string())
256            .use_fips(false)
257            .build()
258            .expect("invalid params");
259        let resolver = crate::config::endpoint::DefaultResolver::new();
260        let endpoint = resolver.resolve_endpoint(&params);
261        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations.eu-isoe-west-1.cloud.adc-e.uk");
262        assert_eq!(
263            endpoint,
264            ::aws_smithy_types::endpoint::Endpoint::builder()
265                .url("https://api.iotmanagedintegrations.eu-isoe-west-1.cloud.adc-e.uk")
266                .build()
267        );
268    }
269
270    /// For region us-isof-south-1 with FIPS enabled and DualStack enabled
271    #[test]
272    fn test_15() {
273        let params = crate::config::endpoint::Params::builder()
274            .region("us-isof-south-1".to_string())
275            .use_fips(true)
276            .build()
277            .expect("invalid params");
278        let resolver = crate::config::endpoint::DefaultResolver::new();
279        let endpoint = resolver.resolve_endpoint(&params);
280        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations-fips.us-isof-south-1.csp.hci.ic.gov");
281        assert_eq!(
282            endpoint,
283            ::aws_smithy_types::endpoint::Endpoint::builder()
284                .url("https://api.iotmanagedintegrations-fips.us-isof-south-1.csp.hci.ic.gov")
285                .build()
286        );
287    }
288
289    /// For region us-isof-south-1 with FIPS disabled and DualStack enabled
290    #[test]
291    fn test_16() {
292        let params = crate::config::endpoint::Params::builder()
293            .region("us-isof-south-1".to_string())
294            .use_fips(false)
295            .build()
296            .expect("invalid params");
297        let resolver = crate::config::endpoint::DefaultResolver::new();
298        let endpoint = resolver.resolve_endpoint(&params);
299        let endpoint = endpoint.expect("Expected valid endpoint: https://api.iotmanagedintegrations.us-isof-south-1.csp.hci.ic.gov");
300        assert_eq!(
301            endpoint,
302            ::aws_smithy_types::endpoint::Endpoint::builder()
303                .url("https://api.iotmanagedintegrations.us-isof-south-1.csp.hci.ic.gov")
304                .build()
305        );
306    }
307
308    /// Missing region
309    #[test]
310    fn test_17() {
311        let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
312        let resolver = crate::config::endpoint::DefaultResolver::new();
313        let endpoint = resolver.resolve_endpoint(&params);
314        let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
315        assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
316    }
317}
318
319/// Endpoint resolver trait specific to Managed integrations for AWS IoT Device Management
320pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
321    /// Resolve an endpoint with the given parameters
322    fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
323
324    /// Convert this service-specific resolver into a `SharedEndpointResolver`
325    ///
326    /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`.
327    fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
328    where
329        Self: Sized + 'static,
330    {
331        ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
332    }
333}
334
335#[derive(Debug)]
336struct DowncastParams<T>(T);
337impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
338where
339    T: ResolveEndpoint,
340{
341    fn resolve_endpoint<'a>(
342        &'a self,
343        params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
344    ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
345        let ep = match params.get::<crate::config::endpoint::Params>() {
346            Some(params) => self.0.resolve_endpoint(params),
347            None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
348        };
349        ep
350    }
351}
352
353/// The default endpoint resolver
354#[derive(Debug, Default)]
355pub struct DefaultResolver {
356    partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
357}
358
359impl DefaultResolver {
360    /// Create a new endpoint resolver with default settings
361    pub fn new() -> Self {
362        Self {
363            partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
364        }
365    }
366
367    fn resolve_endpoint(
368        &self,
369        params: &crate::config::endpoint::Params,
370    ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
371        let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
372        Ok(
373            crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
374                .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
375        )
376    }
377}
378
379impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
380    fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture {
381        ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
382    }
383}
384
385#[non_exhaustive]
386#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
387/// Configuration parameters for resolving the correct endpoint
388pub struct Params {
389    /// 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.
390    pub(crate) use_fips: bool,
391    /// Override the endpoint used to send this request
392    pub(crate) endpoint: ::std::option::Option<::std::string::String>,
393    /// The AWS region used to dispatch the request.
394    pub(crate) region: ::std::option::Option<::std::string::String>,
395}
396impl Params {
397    /// Create a builder for [`Params`]
398    pub fn builder() -> crate::config::endpoint::ParamsBuilder {
399        crate::config::endpoint::ParamsBuilder::default()
400    }
401    /// 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.
402    pub fn use_fips(&self) -> ::std::option::Option<bool> {
403        Some(self.use_fips)
404    }
405    /// Override the endpoint used to send this request
406    pub fn endpoint(&self) -> ::std::option::Option<&str> {
407        self.endpoint.as_deref()
408    }
409    /// The AWS region used to dispatch the request.
410    pub fn region(&self) -> ::std::option::Option<&str> {
411        self.region.as_deref()
412    }
413}
414
415/// Builder for [`Params`]
416#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
417pub struct ParamsBuilder {
418    use_fips: ::std::option::Option<bool>,
419    endpoint: ::std::option::Option<::std::string::String>,
420    region: ::std::option::Option<::std::string::String>,
421}
422impl ParamsBuilder {
423    /// Consume this builder, creating [`Params`].
424    pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
425        Ok(
426            #[allow(clippy::unnecessary_lazy_evaluations)]
427            crate::config::endpoint::Params {
428                use_fips: self
429                    .use_fips
430                    .or_else(|| Some(false))
431                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
432                endpoint: self.endpoint,
433                region: self.region,
434            },
435        )
436    }
437    /// Sets the value for use_fips
438    ///
439    /// When unset, this parameter has a default value of `false`.
440    /// 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.
441    pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
442        self.use_fips = Some(value.into());
443        self
444    }
445
446    /// Sets the value for use_fips
447    ///
448    /// When unset, this parameter has a default value of `false`.
449    /// 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.
450    pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
451        self.use_fips = param;
452        self
453    }
454    /// Sets the value for endpoint
455    ///
456    /// Override the endpoint used to send this request
457    pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
458        self.endpoint = Some(value.into());
459        self
460    }
461
462    /// Sets the value for endpoint
463    ///
464    /// Override the endpoint used to send this request
465    pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
466        self.endpoint = param;
467        self
468    }
469    /// Sets the value for region
470    ///
471    /// The AWS region used to dispatch the request.
472    pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
473        self.region = Some(value.into());
474        self
475    }
476
477    /// Sets the value for region
478    ///
479    /// The AWS region used to dispatch the request.
480    pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
481        self.region = param;
482        self
483    }
484}
485
486/// An error that occurred during endpoint resolution
487#[derive(Debug)]
488pub struct InvalidParams {
489    field: std::borrow::Cow<'static, str>,
490}
491
492impl InvalidParams {
493    #[allow(dead_code)]
494    fn missing(field: &'static str) -> Self {
495        Self { field: field.into() }
496    }
497}
498
499impl std::fmt::Display for InvalidParams {
500    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
501        write!(f, "a required field was missing: `{}`", self.field)
502    }
503}
504
505impl std::error::Error for InvalidParams {}
506
507mod internals;