Skip to main content

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