aws_sdk_support/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/// Interceptor that tracks endpoint override business metric.
7#[derive(Debug, Default)]
8pub(crate) struct EndpointOverrideFeatureTrackerInterceptor;
9
10impl ::aws_smithy_runtime_api::client::interceptors::Intercept for EndpointOverrideFeatureTrackerInterceptor {
11    fn name(&self) -> &'static str {
12        "EndpointOverrideFeatureTrackerInterceptor"
13    }
14
15    fn read_before_execution(
16        &self,
17        _context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<'_>,
18        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
19    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
20        if cfg.load::<::aws_types::endpoint_config::EndpointUrl>().is_some() {
21            cfg.interceptor_state()
22                .store_append(::aws_runtime::sdk_feature::AwsSdkFeature::EndpointOverride);
23        }
24        ::std::result::Result::Ok(())
25    }
26}
27
28#[cfg(test)]
29mod test {
30
31    /// For region aws-global with FIPS disabled and DualStack disabled
32    #[test]
33    fn test_1() {
34        let params = crate::config::endpoint::Params::builder()
35            .region("aws-global".to_string())
36            .use_fips(false)
37            .use_dual_stack(false)
38            .build()
39            .expect("invalid params");
40        let resolver = crate::config::endpoint::DefaultResolver::new();
41        let endpoint = resolver.resolve_endpoint(&params);
42        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-east-1.amazonaws.com");
43        assert_eq!(
44            endpoint,
45            ::aws_smithy_types::endpoint::Endpoint::builder()
46                .url("https://support.us-east-1.amazonaws.com")
47                .property(
48                    "authSchemes",
49                    vec![{
50                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
51                        out.insert("name".to_string(), "sigv4".to_string().into());
52                        out.insert("signingName".to_string(), "support".to_string().into());
53                        out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
54                        out
55                    }
56                    .into()]
57                )
58                .build()
59        );
60    }
61
62    /// For region us-east-1 with FIPS enabled and DualStack enabled
63    #[test]
64    fn test_2() {
65        let params = crate::config::endpoint::Params::builder()
66            .region("us-east-1".to_string())
67            .use_fips(true)
68            .use_dual_stack(true)
69            .build()
70            .expect("invalid params");
71        let resolver = crate::config::endpoint::DefaultResolver::new();
72        let endpoint = resolver.resolve_endpoint(&params);
73        let endpoint = endpoint.expect("Expected valid endpoint: https://support-fips.us-east-1.api.aws");
74        assert_eq!(
75            endpoint,
76            ::aws_smithy_types::endpoint::Endpoint::builder()
77                .url("https://support-fips.us-east-1.api.aws")
78                .build()
79        );
80    }
81
82    /// For region us-east-1 with FIPS enabled and DualStack disabled
83    #[test]
84    fn test_3() {
85        let params = crate::config::endpoint::Params::builder()
86            .region("us-east-1".to_string())
87            .use_fips(true)
88            .use_dual_stack(false)
89            .build()
90            .expect("invalid params");
91        let resolver = crate::config::endpoint::DefaultResolver::new();
92        let endpoint = resolver.resolve_endpoint(&params);
93        let endpoint = endpoint.expect("Expected valid endpoint: https://support-fips.us-east-1.amazonaws.com");
94        assert_eq!(
95            endpoint,
96            ::aws_smithy_types::endpoint::Endpoint::builder()
97                .url("https://support-fips.us-east-1.amazonaws.com")
98                .build()
99        );
100    }
101
102    /// For region us-east-1 with FIPS disabled and DualStack enabled
103    #[test]
104    fn test_4() {
105        let params = crate::config::endpoint::Params::builder()
106            .region("us-east-1".to_string())
107            .use_fips(false)
108            .use_dual_stack(true)
109            .build()
110            .expect("invalid params");
111        let resolver = crate::config::endpoint::DefaultResolver::new();
112        let endpoint = resolver.resolve_endpoint(&params);
113        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-east-1.api.aws");
114        assert_eq!(
115            endpoint,
116            ::aws_smithy_types::endpoint::Endpoint::builder()
117                .url("https://support.us-east-1.api.aws")
118                .build()
119        );
120    }
121
122    /// For region us-east-1 with FIPS disabled and DualStack disabled
123    #[test]
124    fn test_5() {
125        let params = crate::config::endpoint::Params::builder()
126            .region("us-east-1".to_string())
127            .use_fips(false)
128            .use_dual_stack(false)
129            .build()
130            .expect("invalid params");
131        let resolver = crate::config::endpoint::DefaultResolver::new();
132        let endpoint = resolver.resolve_endpoint(&params);
133        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-east-1.amazonaws.com");
134        assert_eq!(
135            endpoint,
136            ::aws_smithy_types::endpoint::Endpoint::builder()
137                .url("https://support.us-east-1.amazonaws.com")
138                .property(
139                    "authSchemes",
140                    vec![{
141                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
142                        out.insert("name".to_string(), "sigv4".to_string().into());
143                        out.insert("signingName".to_string(), "support".to_string().into());
144                        out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
145                        out
146                    }
147                    .into()]
148                )
149                .build()
150        );
151    }
152
153    /// For region aws-cn-global with FIPS disabled and DualStack disabled
154    #[test]
155    fn test_6() {
156        let params = crate::config::endpoint::Params::builder()
157            .region("aws-cn-global".to_string())
158            .use_fips(false)
159            .use_dual_stack(false)
160            .build()
161            .expect("invalid params");
162        let resolver = crate::config::endpoint::DefaultResolver::new();
163        let endpoint = resolver.resolve_endpoint(&params);
164        let endpoint = endpoint.expect("Expected valid endpoint: https://support.cn-north-1.amazonaws.com.cn");
165        assert_eq!(
166            endpoint,
167            ::aws_smithy_types::endpoint::Endpoint::builder()
168                .url("https://support.cn-north-1.amazonaws.com.cn")
169                .property(
170                    "authSchemes",
171                    vec![{
172                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
173                        out.insert("name".to_string(), "sigv4".to_string().into());
174                        out.insert("signingName".to_string(), "support".to_string().into());
175                        out.insert("signingRegion".to_string(), "cn-north-1".to_string().into());
176                        out
177                    }
178                    .into()]
179                )
180                .build()
181        );
182    }
183
184    /// For region cn-north-1 with FIPS enabled and DualStack enabled
185    #[test]
186    fn test_7() {
187        let params = crate::config::endpoint::Params::builder()
188            .region("cn-north-1".to_string())
189            .use_fips(true)
190            .use_dual_stack(true)
191            .build()
192            .expect("invalid params");
193        let resolver = crate::config::endpoint::DefaultResolver::new();
194        let endpoint = resolver.resolve_endpoint(&params);
195        let endpoint = endpoint.expect("Expected valid endpoint: https://support-fips.cn-north-1.api.amazonwebservices.com.cn");
196        assert_eq!(
197            endpoint,
198            ::aws_smithy_types::endpoint::Endpoint::builder()
199                .url("https://support-fips.cn-north-1.api.amazonwebservices.com.cn")
200                .build()
201        );
202    }
203
204    /// For region cn-north-1 with FIPS enabled and DualStack disabled
205    #[test]
206    fn test_8() {
207        let params = crate::config::endpoint::Params::builder()
208            .region("cn-north-1".to_string())
209            .use_fips(true)
210            .use_dual_stack(false)
211            .build()
212            .expect("invalid params");
213        let resolver = crate::config::endpoint::DefaultResolver::new();
214        let endpoint = resolver.resolve_endpoint(&params);
215        let endpoint = endpoint.expect("Expected valid endpoint: https://support-fips.cn-north-1.amazonaws.com.cn");
216        assert_eq!(
217            endpoint,
218            ::aws_smithy_types::endpoint::Endpoint::builder()
219                .url("https://support-fips.cn-north-1.amazonaws.com.cn")
220                .build()
221        );
222    }
223
224    /// For region cn-north-1 with FIPS disabled and DualStack enabled
225    #[test]
226    fn test_9() {
227        let params = crate::config::endpoint::Params::builder()
228            .region("cn-north-1".to_string())
229            .use_fips(false)
230            .use_dual_stack(true)
231            .build()
232            .expect("invalid params");
233        let resolver = crate::config::endpoint::DefaultResolver::new();
234        let endpoint = resolver.resolve_endpoint(&params);
235        let endpoint = endpoint.expect("Expected valid endpoint: https://support.cn-north-1.api.amazonwebservices.com.cn");
236        assert_eq!(
237            endpoint,
238            ::aws_smithy_types::endpoint::Endpoint::builder()
239                .url("https://support.cn-north-1.api.amazonwebservices.com.cn")
240                .build()
241        );
242    }
243
244    /// For region cn-north-1 with FIPS disabled and DualStack disabled
245    #[test]
246    fn test_10() {
247        let params = crate::config::endpoint::Params::builder()
248            .region("cn-north-1".to_string())
249            .use_fips(false)
250            .use_dual_stack(false)
251            .build()
252            .expect("invalid params");
253        let resolver = crate::config::endpoint::DefaultResolver::new();
254        let endpoint = resolver.resolve_endpoint(&params);
255        let endpoint = endpoint.expect("Expected valid endpoint: https://support.cn-north-1.amazonaws.com.cn");
256        assert_eq!(
257            endpoint,
258            ::aws_smithy_types::endpoint::Endpoint::builder()
259                .url("https://support.cn-north-1.amazonaws.com.cn")
260                .property(
261                    "authSchemes",
262                    vec![{
263                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
264                        out.insert("name".to_string(), "sigv4".to_string().into());
265                        out.insert("signingName".to_string(), "support".to_string().into());
266                        out.insert("signingRegion".to_string(), "cn-north-1".to_string().into());
267                        out
268                    }
269                    .into()]
270                )
271                .build()
272        );
273    }
274
275    /// For region aws-us-gov-global with FIPS disabled and DualStack disabled
276    #[test]
277    fn test_11() {
278        let params = crate::config::endpoint::Params::builder()
279            .region("aws-us-gov-global".to_string())
280            .use_fips(false)
281            .use_dual_stack(false)
282            .build()
283            .expect("invalid params");
284        let resolver = crate::config::endpoint::DefaultResolver::new();
285        let endpoint = resolver.resolve_endpoint(&params);
286        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-gov-west-1.amazonaws.com");
287        assert_eq!(
288            endpoint,
289            ::aws_smithy_types::endpoint::Endpoint::builder()
290                .url("https://support.us-gov-west-1.amazonaws.com")
291                .property(
292                    "authSchemes",
293                    vec![{
294                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
295                        out.insert("name".to_string(), "sigv4".to_string().into());
296                        out.insert("signingName".to_string(), "support".to_string().into());
297                        out.insert("signingRegion".to_string(), "us-gov-west-1".to_string().into());
298                        out
299                    }
300                    .into()]
301                )
302                .build()
303        );
304    }
305
306    /// For region aws-us-gov-global with FIPS enabled and DualStack disabled
307    #[test]
308    fn test_12() {
309        let params = crate::config::endpoint::Params::builder()
310            .region("aws-us-gov-global".to_string())
311            .use_fips(true)
312            .use_dual_stack(false)
313            .build()
314            .expect("invalid params");
315        let resolver = crate::config::endpoint::DefaultResolver::new();
316        let endpoint = resolver.resolve_endpoint(&params);
317        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-gov-west-1.amazonaws.com");
318        assert_eq!(
319            endpoint,
320            ::aws_smithy_types::endpoint::Endpoint::builder()
321                .url("https://support.us-gov-west-1.amazonaws.com")
322                .property(
323                    "authSchemes",
324                    vec![{
325                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
326                        out.insert("name".to_string(), "sigv4".to_string().into());
327                        out.insert("signingName".to_string(), "support".to_string().into());
328                        out.insert("signingRegion".to_string(), "us-gov-west-1".to_string().into());
329                        out
330                    }
331                    .into()]
332                )
333                .build()
334        );
335    }
336
337    /// For region us-gov-east-1 with FIPS enabled and DualStack enabled
338    #[test]
339    fn test_13() {
340        let params = crate::config::endpoint::Params::builder()
341            .region("us-gov-east-1".to_string())
342            .use_fips(true)
343            .use_dual_stack(true)
344            .build()
345            .expect("invalid params");
346        let resolver = crate::config::endpoint::DefaultResolver::new();
347        let endpoint = resolver.resolve_endpoint(&params);
348        let endpoint = endpoint.expect("Expected valid endpoint: https://support-fips.us-gov-east-1.api.aws");
349        assert_eq!(
350            endpoint,
351            ::aws_smithy_types::endpoint::Endpoint::builder()
352                .url("https://support-fips.us-gov-east-1.api.aws")
353                .build()
354        );
355    }
356
357    /// For region us-gov-east-1 with FIPS enabled and DualStack disabled
358    #[test]
359    fn test_14() {
360        let params = crate::config::endpoint::Params::builder()
361            .region("us-gov-east-1".to_string())
362            .use_fips(true)
363            .use_dual_stack(false)
364            .build()
365            .expect("invalid params");
366        let resolver = crate::config::endpoint::DefaultResolver::new();
367        let endpoint = resolver.resolve_endpoint(&params);
368        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-gov-west-1.amazonaws.com");
369        assert_eq!(
370            endpoint,
371            ::aws_smithy_types::endpoint::Endpoint::builder()
372                .url("https://support.us-gov-west-1.amazonaws.com")
373                .property(
374                    "authSchemes",
375                    vec![{
376                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
377                        out.insert("name".to_string(), "sigv4".to_string().into());
378                        out.insert("signingName".to_string(), "support".to_string().into());
379                        out.insert("signingRegion".to_string(), "us-gov-west-1".to_string().into());
380                        out
381                    }
382                    .into()]
383                )
384                .build()
385        );
386    }
387
388    /// For region us-gov-east-1 with FIPS disabled and DualStack enabled
389    #[test]
390    fn test_15() {
391        let params = crate::config::endpoint::Params::builder()
392            .region("us-gov-east-1".to_string())
393            .use_fips(false)
394            .use_dual_stack(true)
395            .build()
396            .expect("invalid params");
397        let resolver = crate::config::endpoint::DefaultResolver::new();
398        let endpoint = resolver.resolve_endpoint(&params);
399        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-gov-east-1.api.aws");
400        assert_eq!(
401            endpoint,
402            ::aws_smithy_types::endpoint::Endpoint::builder()
403                .url("https://support.us-gov-east-1.api.aws")
404                .build()
405        );
406    }
407
408    /// For region us-gov-east-1 with FIPS disabled and DualStack disabled
409    #[test]
410    fn test_16() {
411        let params = crate::config::endpoint::Params::builder()
412            .region("us-gov-east-1".to_string())
413            .use_fips(false)
414            .use_dual_stack(false)
415            .build()
416            .expect("invalid params");
417        let resolver = crate::config::endpoint::DefaultResolver::new();
418        let endpoint = resolver.resolve_endpoint(&params);
419        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-gov-west-1.amazonaws.com");
420        assert_eq!(
421            endpoint,
422            ::aws_smithy_types::endpoint::Endpoint::builder()
423                .url("https://support.us-gov-west-1.amazonaws.com")
424                .property(
425                    "authSchemes",
426                    vec![{
427                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
428                        out.insert("name".to_string(), "sigv4".to_string().into());
429                        out.insert("signingName".to_string(), "support".to_string().into());
430                        out.insert("signingRegion".to_string(), "us-gov-west-1".to_string().into());
431                        out
432                    }
433                    .into()]
434                )
435                .build()
436        );
437    }
438
439    /// For region aws-iso-global with FIPS disabled and DualStack disabled
440    #[test]
441    fn test_17() {
442        let params = crate::config::endpoint::Params::builder()
443            .region("aws-iso-global".to_string())
444            .use_fips(false)
445            .use_dual_stack(false)
446            .build()
447            .expect("invalid params");
448        let resolver = crate::config::endpoint::DefaultResolver::new();
449        let endpoint = resolver.resolve_endpoint(&params);
450        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-iso-east-1.c2s.ic.gov");
451        assert_eq!(
452            endpoint,
453            ::aws_smithy_types::endpoint::Endpoint::builder()
454                .url("https://support.us-iso-east-1.c2s.ic.gov")
455                .property(
456                    "authSchemes",
457                    vec![{
458                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
459                        out.insert("name".to_string(), "sigv4".to_string().into());
460                        out.insert("signingName".to_string(), "support".to_string().into());
461                        out.insert("signingRegion".to_string(), "us-iso-east-1".to_string().into());
462                        out
463                    }
464                    .into()]
465                )
466                .build()
467        );
468    }
469
470    /// For region us-iso-east-1 with FIPS enabled and DualStack disabled
471    #[test]
472    fn test_18() {
473        let params = crate::config::endpoint::Params::builder()
474            .region("us-iso-east-1".to_string())
475            .use_fips(true)
476            .use_dual_stack(false)
477            .build()
478            .expect("invalid params");
479        let resolver = crate::config::endpoint::DefaultResolver::new();
480        let endpoint = resolver.resolve_endpoint(&params);
481        let endpoint = endpoint.expect("Expected valid endpoint: https://support-fips.us-iso-east-1.c2s.ic.gov");
482        assert_eq!(
483            endpoint,
484            ::aws_smithy_types::endpoint::Endpoint::builder()
485                .url("https://support-fips.us-iso-east-1.c2s.ic.gov")
486                .build()
487        );
488    }
489
490    /// For region us-iso-east-1 with FIPS disabled and DualStack disabled
491    #[test]
492    fn test_19() {
493        let params = crate::config::endpoint::Params::builder()
494            .region("us-iso-east-1".to_string())
495            .use_fips(false)
496            .use_dual_stack(false)
497            .build()
498            .expect("invalid params");
499        let resolver = crate::config::endpoint::DefaultResolver::new();
500        let endpoint = resolver.resolve_endpoint(&params);
501        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-iso-east-1.c2s.ic.gov");
502        assert_eq!(
503            endpoint,
504            ::aws_smithy_types::endpoint::Endpoint::builder()
505                .url("https://support.us-iso-east-1.c2s.ic.gov")
506                .property(
507                    "authSchemes",
508                    vec![{
509                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
510                        out.insert("name".to_string(), "sigv4".to_string().into());
511                        out.insert("signingName".to_string(), "support".to_string().into());
512                        out.insert("signingRegion".to_string(), "us-iso-east-1".to_string().into());
513                        out
514                    }
515                    .into()]
516                )
517                .build()
518        );
519    }
520
521    /// For region aws-iso-b-global with FIPS disabled and DualStack disabled
522    #[test]
523    fn test_20() {
524        let params = crate::config::endpoint::Params::builder()
525            .region("aws-iso-b-global".to_string())
526            .use_fips(false)
527            .use_dual_stack(false)
528            .build()
529            .expect("invalid params");
530        let resolver = crate::config::endpoint::DefaultResolver::new();
531        let endpoint = resolver.resolve_endpoint(&params);
532        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-isob-east-1.sc2s.sgov.gov");
533        assert_eq!(
534            endpoint,
535            ::aws_smithy_types::endpoint::Endpoint::builder()
536                .url("https://support.us-isob-east-1.sc2s.sgov.gov")
537                .property(
538                    "authSchemes",
539                    vec![{
540                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
541                        out.insert("name".to_string(), "sigv4".to_string().into());
542                        out.insert("signingName".to_string(), "support".to_string().into());
543                        out.insert("signingRegion".to_string(), "us-isob-east-1".to_string().into());
544                        out
545                    }
546                    .into()]
547                )
548                .build()
549        );
550    }
551
552    /// For region us-isob-east-1 with FIPS enabled and DualStack disabled
553    #[test]
554    fn test_21() {
555        let params = crate::config::endpoint::Params::builder()
556            .region("us-isob-east-1".to_string())
557            .use_fips(true)
558            .use_dual_stack(false)
559            .build()
560            .expect("invalid params");
561        let resolver = crate::config::endpoint::DefaultResolver::new();
562        let endpoint = resolver.resolve_endpoint(&params);
563        let endpoint = endpoint.expect("Expected valid endpoint: https://support-fips.us-isob-east-1.sc2s.sgov.gov");
564        assert_eq!(
565            endpoint,
566            ::aws_smithy_types::endpoint::Endpoint::builder()
567                .url("https://support-fips.us-isob-east-1.sc2s.sgov.gov")
568                .build()
569        );
570    }
571
572    /// For region us-isob-east-1 with FIPS disabled and DualStack disabled
573    #[test]
574    fn test_22() {
575        let params = crate::config::endpoint::Params::builder()
576            .region("us-isob-east-1".to_string())
577            .use_fips(false)
578            .use_dual_stack(false)
579            .build()
580            .expect("invalid params");
581        let resolver = crate::config::endpoint::DefaultResolver::new();
582        let endpoint = resolver.resolve_endpoint(&params);
583        let endpoint = endpoint.expect("Expected valid endpoint: https://support.us-isob-east-1.sc2s.sgov.gov");
584        assert_eq!(
585            endpoint,
586            ::aws_smithy_types::endpoint::Endpoint::builder()
587                .url("https://support.us-isob-east-1.sc2s.sgov.gov")
588                .property(
589                    "authSchemes",
590                    vec![{
591                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
592                        out.insert("name".to_string(), "sigv4".to_string().into());
593                        out.insert("signingName".to_string(), "support".to_string().into());
594                        out.insert("signingRegion".to_string(), "us-isob-east-1".to_string().into());
595                        out
596                    }
597                    .into()]
598                )
599                .build()
600        );
601    }
602
603    /// For custom endpoint with region set and fips disabled and dualstack disabled
604    #[test]
605    fn test_23() {
606        let params = crate::config::endpoint::Params::builder()
607            .region("us-east-1".to_string())
608            .use_fips(false)
609            .use_dual_stack(false)
610            .endpoint("https://example.com".to_string())
611            .build()
612            .expect("invalid params");
613        let resolver = crate::config::endpoint::DefaultResolver::new();
614        let endpoint = resolver.resolve_endpoint(&params);
615        let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
616        assert_eq!(
617            endpoint,
618            ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
619        );
620    }
621
622    /// For custom endpoint with region not set and fips disabled and dualstack disabled
623    #[test]
624    fn test_24() {
625        let params = crate::config::endpoint::Params::builder()
626            .use_fips(false)
627            .use_dual_stack(false)
628            .endpoint("https://example.com".to_string())
629            .build()
630            .expect("invalid params");
631        let resolver = crate::config::endpoint::DefaultResolver::new();
632        let endpoint = resolver.resolve_endpoint(&params);
633        let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
634        assert_eq!(
635            endpoint,
636            ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
637        );
638    }
639
640    /// For custom endpoint with fips enabled and dualstack disabled
641    #[test]
642    fn test_25() {
643        let params = crate::config::endpoint::Params::builder()
644            .region("us-east-1".to_string())
645            .use_fips(true)
646            .use_dual_stack(false)
647            .endpoint("https://example.com".to_string())
648            .build()
649            .expect("invalid params");
650        let resolver = crate::config::endpoint::DefaultResolver::new();
651        let endpoint = resolver.resolve_endpoint(&params);
652        let error = endpoint.expect_err("expected error: Invalid Configuration: FIPS and custom endpoint are not supported [For custom endpoint with fips enabled and dualstack disabled]");
653        assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
654    }
655
656    /// For custom endpoint with fips disabled and dualstack enabled
657    #[test]
658    fn test_26() {
659        let params = crate::config::endpoint::Params::builder()
660            .region("us-east-1".to_string())
661            .use_fips(false)
662            .use_dual_stack(true)
663            .endpoint("https://example.com".to_string())
664            .build()
665            .expect("invalid params");
666        let resolver = crate::config::endpoint::DefaultResolver::new();
667        let endpoint = resolver.resolve_endpoint(&params);
668        let error = endpoint.expect_err("expected error: Invalid Configuration: Dualstack and custom endpoint are not supported [For custom endpoint with fips disabled and dualstack enabled]");
669        assert_eq!(
670            format!("{}", error),
671            "Invalid Configuration: Dualstack and custom endpoint are not supported"
672        )
673    }
674
675    /// Missing region
676    #[test]
677    fn test_27() {
678        let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
679        let resolver = crate::config::endpoint::DefaultResolver::new();
680        let endpoint = resolver.resolve_endpoint(&params);
681        let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
682        assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
683    }
684}
685
686/// Endpoint resolver trait specific to AWS Support
687pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
688    /// Resolve an endpoint with the given parameters
689    fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
690
691    /// Convert this service-specific resolver into a `SharedEndpointResolver`
692    ///
693    /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`.
694    fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
695    where
696        Self: Sized + 'static,
697    {
698        ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
699    }
700}
701
702#[derive(Debug)]
703struct DowncastParams<T>(T);
704impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
705where
706    T: ResolveEndpoint,
707{
708    fn resolve_endpoint<'a>(
709        &'a self,
710        params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
711    ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
712        let ep = match params.get::<crate::config::endpoint::Params>() {
713            Some(params) => self.0.resolve_endpoint(params),
714            None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
715        };
716        ep
717    }
718}
719
720/// The default endpoint resolver
721#[derive(Debug, Default)]
722pub struct DefaultResolver {
723    partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
724}
725
726impl DefaultResolver {
727    /// Create a new endpoint resolver with default settings
728    pub fn new() -> Self {
729        Self {
730            partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
731        }
732    }
733
734    fn resolve_endpoint(
735        &self,
736        params: &crate::config::endpoint::Params,
737    ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
738        let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
739        Ok(
740            crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
741                .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
742        )
743    }
744}
745
746impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
747    fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'_> {
748        ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
749    }
750}
751
752#[non_exhaustive]
753#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
754/// Configuration parameters for resolving the correct endpoint
755pub struct Params {
756    /// The AWS region used to dispatch the request.
757    pub(crate) region: ::std::option::Option<::std::string::String>,
758    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
759    pub(crate) use_dual_stack: bool,
760    /// 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.
761    pub(crate) use_fips: bool,
762    /// Override the endpoint used to send this request
763    pub(crate) endpoint: ::std::option::Option<::std::string::String>,
764}
765impl Params {
766    /// Create a builder for [`Params`]
767    pub fn builder() -> crate::config::endpoint::ParamsBuilder {
768        crate::config::endpoint::ParamsBuilder::default()
769    }
770    /// The AWS region used to dispatch the request.
771    pub fn region(&self) -> ::std::option::Option<&str> {
772        self.region.as_deref()
773    }
774    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
775    pub fn use_dual_stack(&self) -> ::std::option::Option<bool> {
776        Some(self.use_dual_stack)
777    }
778    /// 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.
779    pub fn use_fips(&self) -> ::std::option::Option<bool> {
780        Some(self.use_fips)
781    }
782    /// Override the endpoint used to send this request
783    pub fn endpoint(&self) -> ::std::option::Option<&str> {
784        self.endpoint.as_deref()
785    }
786}
787
788/// Builder for [`Params`]
789#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
790pub struct ParamsBuilder {
791    region: ::std::option::Option<::std::string::String>,
792    use_dual_stack: ::std::option::Option<bool>,
793    use_fips: ::std::option::Option<bool>,
794    endpoint: ::std::option::Option<::std::string::String>,
795}
796impl ParamsBuilder {
797    /// Consume this builder, creating [`Params`].
798    pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
799        if let Some(region) = &self.region {
800            if !crate::endpoint_lib::host::is_valid_host_label(
801                region.as_ref() as &str,
802                true,
803                &mut crate::endpoint_lib::diagnostic::DiagnosticCollector::new(),
804            ) {
805                return Err(crate::config::endpoint::InvalidParams::invalid_value(
806                    "region",
807                    "must be a valid host label",
808                ));
809            }
810        };
811        Ok(
812            #[allow(clippy::unnecessary_lazy_evaluations)]
813            crate::config::endpoint::Params {
814                region: self.region,
815                use_dual_stack: self
816                    .use_dual_stack
817                    .or_else(|| Some(false))
818                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_dual_stack"))?,
819                use_fips: self
820                    .use_fips
821                    .or_else(|| Some(false))
822                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
823                endpoint: self.endpoint,
824            },
825        )
826    }
827    /// Sets the value for region
828    ///
829    /// The AWS region used to dispatch the request.
830    pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
831        self.region = Some(value.into());
832        self
833    }
834
835    /// Sets the value for region
836    ///
837    /// The AWS region used to dispatch the request.
838    pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
839        self.region = param;
840        self
841    }
842    /// Sets the value for use_dual_stack
843    ///
844    /// When unset, this parameter has a default value of `false`.
845    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
846    pub fn use_dual_stack(mut self, value: impl Into<bool>) -> Self {
847        self.use_dual_stack = Some(value.into());
848        self
849    }
850
851    /// Sets the value for use_dual_stack
852    ///
853    /// When unset, this parameter has a default value of `false`.
854    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
855    pub fn set_use_dual_stack(mut self, param: Option<bool>) -> Self {
856        self.use_dual_stack = param;
857        self
858    }
859    /// Sets the value for use_fips
860    ///
861    /// When unset, this parameter has a default value of `false`.
862    /// 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.
863    pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
864        self.use_fips = Some(value.into());
865        self
866    }
867
868    /// Sets the value for use_fips
869    ///
870    /// When unset, this parameter has a default value of `false`.
871    /// 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.
872    pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
873        self.use_fips = param;
874        self
875    }
876    /// Sets the value for endpoint
877    ///
878    /// Override the endpoint used to send this request
879    pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
880        self.endpoint = Some(value.into());
881        self
882    }
883
884    /// Sets the value for endpoint
885    ///
886    /// Override the endpoint used to send this request
887    pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
888        self.endpoint = param;
889        self
890    }
891}
892
893/// An error that occurred during endpoint resolution
894#[derive(Debug)]
895pub struct InvalidParams {
896    field: std::borrow::Cow<'static, str>,
897    kind: InvalidParamsErrorKind,
898}
899
900/// The kind of invalid parameter error
901#[derive(Debug)]
902enum InvalidParamsErrorKind {
903    MissingField,
904    InvalidValue { message: &'static str },
905}
906
907impl InvalidParams {
908    #[allow(dead_code)]
909    fn missing(field: &'static str) -> Self {
910        Self {
911            field: field.into(),
912            kind: InvalidParamsErrorKind::MissingField,
913        }
914    }
915
916    #[allow(dead_code)]
917    fn invalid_value(field: &'static str, message: &'static str) -> Self {
918        Self {
919            field: field.into(),
920            kind: InvalidParamsErrorKind::InvalidValue { message },
921        }
922    }
923}
924
925impl std::fmt::Display for InvalidParams {
926    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
927        match self.kind {
928            InvalidParamsErrorKind::MissingField => write!(f, "a required field was missing: `{}`", self.field),
929            InvalidParamsErrorKind::InvalidValue { message } => write!(f, "invalid value for field: `{}` - {}", self.field, message),
930        }
931    }
932}
933
934impl std::error::Error for InvalidParams {}
935
936mod internals;