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