Skip to main content

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