Skip to main content

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