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    )]
543    fn resolve_endpoint<'a>(
544        &'a self,
545        params: &'a crate::config::endpoint::Params,
546    ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
547        let mut _diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
548        #[allow(unused_mut)]
549        let mut context = ConditionContext::default();
550
551        // Param bindings
552        let region = &params.region;
553        let use_dual_stack = &params.use_dual_stack;
554        let use_fips = &params.use_fips;
555        let endpoint = &params.endpoint;
556
557        let mut current_ref: i32 = 2;
558        loop {
559            match current_ref {
560                ref_val if ref_val >= 100_000_000 => {
561                    return match (ref_val - 100_000_000) as usize {
562                        0 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
563                            "No endpoint rule matched",
564                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
565                        1 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
566                            "Invalid Configuration: FIPS and custom endpoint are not supported".to_string(),
567                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
568                        2 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
569                            "Invalid Configuration: Dualstack and custom endpoint are not supported".to_string(),
570                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
571                        3 => {
572                            let endpoint = params.endpoint.as_deref().unwrap_or_default();
573                            ::std::result::Result::Ok(::aws_smithy_types::endpoint::Endpoint::builder().url(endpoint.to_owned()).build())
574                        }
575                        4 => {
576                            let region = params.region.as_deref().unwrap_or_default();
577                            let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
578                            ::std::result::Result::Ok(
579                                ::aws_smithy_types::endpoint::Endpoint::builder()
580                                    .url({
581                                        let mut out = String::new();
582                                        out.push_str("https://imagebuilder-fips.");
583                                        #[allow(clippy::needless_borrow)]
584                                        out.push_str(&region.as_ref());
585                                        out.push('.');
586                                        #[allow(clippy::needless_borrow)]
587                                        out.push_str(&partition_result.dual_stack_dns_suffix());
588                                        out
589                                    })
590                                    .build(),
591                            )
592                        }
593                        5 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
594                            "FIPS and DualStack are enabled, but this partition does not support one or both".to_string(),
595                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
596                        6 => {
597                            let region = params.region.as_deref().unwrap_or_default();
598                            ::std::result::Result::Ok(
599                                ::aws_smithy_types::endpoint::Endpoint::builder()
600                                    .url({
601                                        let mut out = String::new();
602                                        out.push_str("https://imagebuilder.");
603                                        #[allow(clippy::needless_borrow)]
604                                        out.push_str(&region.as_ref());
605                                        out.push_str(".amazonaws.com");
606                                        out
607                                    })
608                                    .build(),
609                            )
610                        }
611                        7 => {
612                            let region = params.region.as_deref().unwrap_or_default();
613                            let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
614                            ::std::result::Result::Ok(
615                                ::aws_smithy_types::endpoint::Endpoint::builder()
616                                    .url({
617                                        let mut out = String::new();
618                                        out.push_str("https://imagebuilder-fips.");
619                                        #[allow(clippy::needless_borrow)]
620                                        out.push_str(&region.as_ref());
621                                        out.push('.');
622                                        #[allow(clippy::needless_borrow)]
623                                        out.push_str(&partition_result.dns_suffix());
624                                        out
625                                    })
626                                    .build(),
627                            )
628                        }
629                        8 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
630                            "FIPS is enabled but this partition does not support FIPS".to_string(),
631                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
632                        9 => {
633                            let region = params.region.as_deref().unwrap_or_default();
634                            let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
635                            ::std::result::Result::Ok(
636                                ::aws_smithy_types::endpoint::Endpoint::builder()
637                                    .url({
638                                        let mut out = String::new();
639                                        out.push_str("https://imagebuilder.");
640                                        #[allow(clippy::needless_borrow)]
641                                        out.push_str(&region.as_ref());
642                                        out.push('.');
643                                        #[allow(clippy::needless_borrow)]
644                                        out.push_str(&partition_result.dual_stack_dns_suffix());
645                                        out
646                                    })
647                                    .build(),
648                            )
649                        }
650                        10 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
651                            "DualStack is enabled but this partition does not support DualStack".to_string(),
652                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
653                        11 => {
654                            let region = params.region.as_deref().unwrap_or_default();
655                            let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
656                            ::std::result::Result::Ok(
657                                ::aws_smithy_types::endpoint::Endpoint::builder()
658                                    .url({
659                                        let mut out = String::new();
660                                        out.push_str("https://imagebuilder.");
661                                        #[allow(clippy::needless_borrow)]
662                                        out.push_str(&region.as_ref());
663                                        out.push('.');
664                                        #[allow(clippy::needless_borrow)]
665                                        out.push_str(&partition_result.dns_suffix());
666                                        out
667                                    })
668                                    .build(),
669                            )
670                        }
671                        12 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
672                            "Invalid Configuration: Missing Region".to_string(),
673                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
674                        _ => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
675                            "No endpoint rule matched",
676                        )) as ::aws_smithy_runtime_api::box_error::BoxError),
677                    };
678                }
679                1 | -1 => {
680                    return ::std::result::Result::Err(
681                        Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message("No endpoint rule matched"))
682                            as ::aws_smithy_runtime_api::box_error::BoxError,
683                    )
684                }
685                ref_val => {
686                    let is_complement = ref_val < 0;
687                    let node = &NODES[(ref_val.unsigned_abs() as usize) - 1];
688                    let condition_result = match node.condition_index {
689                        0 => endpoint.is_some(),
690                        1 => region.is_some(),
691                        2 => (|_diagnostic_collector: &mut crate::endpoint_lib::diagnostic::DiagnosticCollector| -> bool {
692                            let partition_result = &mut context.partition_result;
693                            let partition_resolver = &self.partition_resolver;
694                            {
695                                *partition_result = partition_resolver
696                                    .resolve_partition(if let Some(param) = region { param } else { return false }, _diagnostic_collector)
697                                    .map(|inner| inner.into());
698                                partition_result.is_some()
699                            }
700                        })(&mut _diagnostic_collector),
701                        3 => (use_fips) == (&true),
702                        4 => (use_dual_stack) == (&true),
703                        5 => (|_diagnostic_collector: &mut crate::endpoint_lib::diagnostic::DiagnosticCollector| -> bool {
704                            let partition_result = &context.partition_result;
705                            let partition_resolver = &self.partition_resolver;
706                            (if let Some(inner) = partition_result {
707                                inner.supports_dual_stack()
708                            } else {
709                                return false;
710                            }) == (true)
711                        })(&mut _diagnostic_collector),
712                        6 => (|_diagnostic_collector: &mut crate::endpoint_lib::diagnostic::DiagnosticCollector| -> bool {
713                            let partition_result = &context.partition_result;
714                            let partition_resolver = &self.partition_resolver;
715                            (if let Some(inner) = partition_result {
716                                inner.supports_fips()
717                            } else {
718                                return false;
719                            }) == (true)
720                        })(&mut _diagnostic_collector),
721                        7 => (|_diagnostic_collector: &mut crate::endpoint_lib::diagnostic::DiagnosticCollector| -> bool {
722                            let partition_result = &context.partition_result;
723                            let partition_resolver = &self.partition_resolver;
724                            (if let Some(inner) = partition_result {
725                                inner.name()
726                            } else {
727                                return false;
728                            }) == ("aws-us-gov")
729                        })(&mut _diagnostic_collector),
730                        _ => unreachable!("Invalid condition index"),
731                    };
732                    current_ref = if is_complement ^ condition_result { node.high_ref } else { node.low_ref };
733                }
734            }
735        }
736    }
737}
738
739impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
740    fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
741        // Check single-entry cache (lock-free read via ArcSwap)
742        let cached = self.endpoint_cache.load();
743        if let Some((cached_params, cached_endpoint)) = cached.as_ref() {
744            if cached_params == params {
745                return ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(::std::result::Result::Ok(cached_endpoint.clone()));
746            }
747        }
748        drop(cached);
749        let result = self.resolve_endpoint(params);
750        if let ::std::result::Result::Ok(ref endpoint) = result {
751            self.endpoint_cache.store(::std::sync::Arc::new(Some((params.clone(), endpoint.clone()))));
752        }
753        ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(result)
754    }
755}
756const NODES: [crate::endpoint_lib::bdd_interpreter::BddNode; 14] = [
757    crate::endpoint_lib::bdd_interpreter::BddNode {
758        condition_index: -1,
759        high_ref: 1,
760        low_ref: -1,
761    },
762    crate::endpoint_lib::bdd_interpreter::BddNode {
763        condition_index: 0,
764        high_ref: 13,
765        low_ref: 3,
766    },
767    crate::endpoint_lib::bdd_interpreter::BddNode {
768        condition_index: 1,
769        high_ref: 4,
770        low_ref: 100000012,
771    },
772    crate::endpoint_lib::bdd_interpreter::BddNode {
773        condition_index: 2,
774        high_ref: 5,
775        low_ref: 100000012,
776    },
777    crate::endpoint_lib::bdd_interpreter::BddNode {
778        condition_index: 3,
779        high_ref: 8,
780        low_ref: 6,
781    },
782    crate::endpoint_lib::bdd_interpreter::BddNode {
783        condition_index: 4,
784        high_ref: 7,
785        low_ref: 100000011,
786    },
787    crate::endpoint_lib::bdd_interpreter::BddNode {
788        condition_index: 5,
789        high_ref: 100000009,
790        low_ref: 100000010,
791    },
792    crate::endpoint_lib::bdd_interpreter::BddNode {
793        condition_index: 4,
794        high_ref: 11,
795        low_ref: 9,
796    },
797    crate::endpoint_lib::bdd_interpreter::BddNode {
798        condition_index: 6,
799        high_ref: 10,
800        low_ref: 100000008,
801    },
802    crate::endpoint_lib::bdd_interpreter::BddNode {
803        condition_index: 7,
804        high_ref: 100000006,
805        low_ref: 100000007,
806    },
807    crate::endpoint_lib::bdd_interpreter::BddNode {
808        condition_index: 5,
809        high_ref: 12,
810        low_ref: 100000005,
811    },
812    crate::endpoint_lib::bdd_interpreter::BddNode {
813        condition_index: 6,
814        high_ref: 100000004,
815        low_ref: 100000005,
816    },
817    crate::endpoint_lib::bdd_interpreter::BddNode {
818        condition_index: 3,
819        high_ref: 100000001,
820        low_ref: 14,
821    },
822    crate::endpoint_lib::bdd_interpreter::BddNode {
823        condition_index: 4,
824        high_ref: 100000002,
825        low_ref: 100000003,
826    },
827];
828// These are all optional since they are set by conditions and will
829// all be unset when we start evaluation
830#[derive(Default)]
831#[allow(unused_lifetimes)]
832pub(crate) struct ConditionContext<'a> {
833    pub(crate) partition_result: Option<crate::endpoint_lib::partition::Partition<'a>>,
834    // Sometimes none of the members reference the lifetime, this makes it still valid
835    phantom: std::marker::PhantomData<&'a ()>,
836}
837
838#[non_exhaustive]
839#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
840/// Configuration parameters for resolving the correct endpoint
841pub struct Params {
842    /// The AWS region used to dispatch the request.
843    pub(crate) region: ::std::option::Option<::std::string::String>,
844    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
845    pub(crate) use_dual_stack: bool,
846    /// 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.
847    pub(crate) use_fips: bool,
848    /// Override the endpoint used to send this request
849    pub(crate) endpoint: ::std::option::Option<::std::string::String>,
850}
851impl Params {
852    /// Create a builder for [`Params`]
853    pub fn builder() -> crate::config::endpoint::ParamsBuilder {
854        crate::config::endpoint::ParamsBuilder::default()
855    }
856    /// The AWS region used to dispatch the request.
857    pub fn region(&self) -> ::std::option::Option<&str> {
858        self.region.as_deref()
859    }
860    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
861    pub fn use_dual_stack(&self) -> ::std::option::Option<bool> {
862        Some(self.use_dual_stack)
863    }
864    /// 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.
865    pub fn use_fips(&self) -> ::std::option::Option<bool> {
866        Some(self.use_fips)
867    }
868    /// Override the endpoint used to send this request
869    pub fn endpoint(&self) -> ::std::option::Option<&str> {
870        self.endpoint.as_deref()
871    }
872}
873
874/// Builder for [`Params`]
875#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
876pub struct ParamsBuilder {
877    region: ::std::option::Option<::std::string::String>,
878    use_dual_stack: ::std::option::Option<bool>,
879    use_fips: ::std::option::Option<bool>,
880    endpoint: ::std::option::Option<::std::string::String>,
881}
882impl ParamsBuilder {
883    /// Consume this builder, creating [`Params`].
884    pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
885        if let Some(region) = &self.region {
886            if !crate::endpoint_lib::host::is_valid_host_label(
887                region.as_ref() as &str,
888                true,
889                &mut crate::endpoint_lib::diagnostic::DiagnosticCollector::new(),
890            ) {
891                return Err(crate::config::endpoint::InvalidParams::invalid_value(
892                    "region",
893                    "must be a valid host label",
894                ));
895            }
896        };
897        Ok(
898            #[allow(clippy::unnecessary_lazy_evaluations)]
899            crate::config::endpoint::Params {
900                region: self.region,
901                use_dual_stack: self
902                    .use_dual_stack
903                    .or_else(|| Some(false))
904                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_dual_stack"))?,
905                use_fips: self
906                    .use_fips
907                    .or_else(|| Some(false))
908                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
909                endpoint: self.endpoint,
910            },
911        )
912    }
913    /// Sets the value for region
914    ///
915    /// The AWS region used to dispatch the request.
916    pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
917        self.region = Some(value.into());
918        self
919    }
920
921    /// Sets the value for region
922    ///
923    /// The AWS region used to dispatch the request.
924    pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
925        self.region = param;
926        self
927    }
928    /// Sets the value for use_dual_stack
929    ///
930    /// When unset, this parameter has a default value of `false`.
931    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
932    pub fn use_dual_stack(mut self, value: impl Into<bool>) -> Self {
933        self.use_dual_stack = Some(value.into());
934        self
935    }
936
937    /// Sets the value for use_dual_stack
938    ///
939    /// When unset, this parameter has a default value of `false`.
940    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
941    pub fn set_use_dual_stack(mut self, param: Option<bool>) -> Self {
942        self.use_dual_stack = param;
943        self
944    }
945    /// Sets the value for use_fips
946    ///
947    /// When unset, this parameter has a default value of `false`.
948    /// 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.
949    pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
950        self.use_fips = Some(value.into());
951        self
952    }
953
954    /// Sets the value for use_fips
955    ///
956    /// When unset, this parameter has a default value of `false`.
957    /// 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.
958    pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
959        self.use_fips = param;
960        self
961    }
962    /// Sets the value for endpoint
963    ///
964    /// Override the endpoint used to send this request
965    pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
966        self.endpoint = Some(value.into());
967        self
968    }
969
970    /// Sets the value for endpoint
971    ///
972    /// Override the endpoint used to send this request
973    pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
974        self.endpoint = param;
975        self
976    }
977}
978
979/// An error that occurred during endpoint resolution
980#[derive(Debug)]
981pub struct InvalidParams {
982    field: std::borrow::Cow<'static, str>,
983    kind: InvalidParamsErrorKind,
984}
985
986/// The kind of invalid parameter error
987#[derive(Debug)]
988enum InvalidParamsErrorKind {
989    MissingField,
990    InvalidValue { message: &'static str },
991}
992
993impl InvalidParams {
994    #[allow(dead_code)]
995    fn missing(field: &'static str) -> Self {
996        Self {
997            field: field.into(),
998            kind: InvalidParamsErrorKind::MissingField,
999        }
1000    }
1001
1002    #[allow(dead_code)]
1003    fn invalid_value(field: &'static str, message: &'static str) -> Self {
1004        Self {
1005            field: field.into(),
1006            kind: InvalidParamsErrorKind::InvalidValue { message },
1007        }
1008    }
1009}
1010
1011impl std::fmt::Display for InvalidParams {
1012    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1013        match self.kind {
1014            InvalidParamsErrorKind::MissingField => write!(f, "a required field was missing: `{}`", self.field),
1015            InvalidParamsErrorKind::InvalidValue { message } => write!(f, "invalid value for field: `{}` - {}", self.field, message),
1016        }
1017    }
1018}
1019
1020impl std::error::Error for InvalidParams {}