1pub 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#[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 #[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 .build()
39 .expect("invalid params");
40 let resolver = crate::config::endpoint::DefaultResolver::new();
41 let endpoint = resolver.resolve_endpoint(¶ms);
42 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth-fips.us-east-1.api.aws");
43 assert_eq!(
44 endpoint,
45 ::aws_smithy_types::endpoint::Endpoint::builder()
46 .url("https://eks-auth-fips.us-east-1.api.aws")
47 .build()
48 );
49 }
50
51 #[test]
53 fn test_2() {
54 let params = crate::config::endpoint::Params::builder()
55 .region("us-east-1".to_string())
56 .use_fips(false)
57 .build()
58 .expect("invalid params");
59 let resolver = crate::config::endpoint::DefaultResolver::new();
60 let endpoint = resolver.resolve_endpoint(¶ms);
61 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth.us-east-1.api.aws");
62 assert_eq!(
63 endpoint,
64 ::aws_smithy_types::endpoint::Endpoint::builder()
65 .url("https://eks-auth.us-east-1.api.aws")
66 .build()
67 );
68 }
69
70 #[test]
72 fn test_3() {
73 let params = crate::config::endpoint::Params::builder()
74 .region("cn-north-1".to_string())
75 .use_fips(true)
76 .build()
77 .expect("invalid params");
78 let resolver = crate::config::endpoint::DefaultResolver::new();
79 let endpoint = resolver.resolve_endpoint(¶ms);
80 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth-fips.cn-north-1.api.amazonwebservices.com.cn");
81 assert_eq!(
82 endpoint,
83 ::aws_smithy_types::endpoint::Endpoint::builder()
84 .url("https://eks-auth-fips.cn-north-1.api.amazonwebservices.com.cn")
85 .build()
86 );
87 }
88
89 #[test]
91 fn test_4() {
92 let params = crate::config::endpoint::Params::builder()
93 .region("cn-north-1".to_string())
94 .use_fips(false)
95 .build()
96 .expect("invalid params");
97 let resolver = crate::config::endpoint::DefaultResolver::new();
98 let endpoint = resolver.resolve_endpoint(¶ms);
99 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth.cn-north-1.api.amazonwebservices.com.cn");
100 assert_eq!(
101 endpoint,
102 ::aws_smithy_types::endpoint::Endpoint::builder()
103 .url("https://eks-auth.cn-north-1.api.amazonwebservices.com.cn")
104 .build()
105 );
106 }
107
108 #[test]
110 fn test_5() {
111 let params = crate::config::endpoint::Params::builder()
112 .region("us-gov-east-1".to_string())
113 .use_fips(true)
114 .build()
115 .expect("invalid params");
116 let resolver = crate::config::endpoint::DefaultResolver::new();
117 let endpoint = resolver.resolve_endpoint(¶ms);
118 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth-fips.us-gov-east-1.api.aws");
119 assert_eq!(
120 endpoint,
121 ::aws_smithy_types::endpoint::Endpoint::builder()
122 .url("https://eks-auth-fips.us-gov-east-1.api.aws")
123 .build()
124 );
125 }
126
127 #[test]
129 fn test_6() {
130 let params = crate::config::endpoint::Params::builder()
131 .region("us-gov-east-1".to_string())
132 .use_fips(false)
133 .build()
134 .expect("invalid params");
135 let resolver = crate::config::endpoint::DefaultResolver::new();
136 let endpoint = resolver.resolve_endpoint(¶ms);
137 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth.us-gov-east-1.api.aws");
138 assert_eq!(
139 endpoint,
140 ::aws_smithy_types::endpoint::Endpoint::builder()
141 .url("https://eks-auth.us-gov-east-1.api.aws")
142 .build()
143 );
144 }
145
146 #[test]
148 fn test_7() {
149 let params = crate::config::endpoint::Params::builder()
150 .region("us-east-1".to_string())
151 .use_fips(false)
152 .endpoint("https://example.com".to_string())
153 .build()
154 .expect("invalid params");
155 let resolver = crate::config::endpoint::DefaultResolver::new();
156 let endpoint = resolver.resolve_endpoint(¶ms);
157 let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
158 assert_eq!(
159 endpoint,
160 ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
161 );
162 }
163
164 #[test]
166 fn test_8() {
167 let params = crate::config::endpoint::Params::builder()
168 .use_fips(false)
169 .endpoint("https://example.com".to_string())
170 .build()
171 .expect("invalid params");
172 let resolver = crate::config::endpoint::DefaultResolver::new();
173 let endpoint = resolver.resolve_endpoint(¶ms);
174 let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
175 assert_eq!(
176 endpoint,
177 ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
178 );
179 }
180
181 #[test]
183 fn test_9() {
184 let params = crate::config::endpoint::Params::builder()
185 .region("us-east-1".to_string())
186 .use_fips(true)
187 .endpoint("https://example.com".to_string())
188 .build()
189 .expect("invalid params");
190 let resolver = crate::config::endpoint::DefaultResolver::new();
191 let endpoint = resolver.resolve_endpoint(¶ms);
192 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]");
193 assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
194 }
195
196 #[test]
198 fn test_10() {
199 let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
200 let resolver = crate::config::endpoint::DefaultResolver::new();
201 let endpoint = resolver.resolve_endpoint(¶ms);
202 let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
203 assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
204 }
205}
206
207pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
209 fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
211
212 fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
216 where
217 Self: Sized + 'static,
218 {
219 ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
220 }
221}
222
223#[derive(Debug)]
224struct DowncastParams<T>(T);
225impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
226where
227 T: ResolveEndpoint,
228{
229 fn resolve_endpoint<'a>(
230 &'a self,
231 params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
232 ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
233 let ep = match params.get::<crate::config::endpoint::Params>() {
234 Some(params) => self.0.resolve_endpoint(params),
235 None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
236 };
237 ep
238 }
239}
240
241#[derive(Debug)]
242pub struct DefaultResolver {
244 partition_resolver: &'static crate::endpoint_lib::partition::PartitionResolver,
245 endpoint_cache: ::arc_swap::ArcSwap<::std::option::Option<(Params, ::aws_smithy_types::endpoint::Endpoint)>>,
246}
247
248impl Default for DefaultResolver {
249 fn default() -> Self {
250 Self::new()
251 }
252}
253
254impl DefaultResolver {
255 pub fn new() -> Self {
257 Self {
258 partition_resolver: &crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER,
259 endpoint_cache: ::arc_swap::ArcSwap::from_pointee(None),
260 }
261 }
262
263 #[allow(
264 unused_variables,
265 unused_parens,
266 clippy::double_parens,
267 clippy::useless_conversion,
268 clippy::bool_comparison,
269 clippy::comparison_to_empty,
270 clippy::needless_borrow,
271 clippy::useless_asref,
272 clippy::redundant_closure_call,
273 clippy::clone_on_copy,
274 clippy::single_char_add_str
275 )]
276 fn resolve_endpoint<'a>(
277 &'a self,
278 params: &'a crate::config::endpoint::Params,
279 ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
280 let mut _diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
281 #[allow(unused_mut)]
282 let mut context = ConditionContext::default();
283
284 let region = ¶ms.region;
286 let use_fips = ¶ms.use_fips;
287 let endpoint = ¶ms.endpoint;
288
289 let mut current_ref: i32 = 2;
290 loop {
291 match current_ref {
292 ref_val if ref_val >= 100_000_000 => {
293 return match (ref_val - 100_000_000) as usize {
294 0 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
295 "No endpoint rule matched",
296 )) as ::aws_smithy_runtime_api::box_error::BoxError),
297 1 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
298 "Invalid Configuration: FIPS and custom endpoint are not supported".to_string(),
299 )) as ::aws_smithy_runtime_api::box_error::BoxError),
300 2 => {
301 let endpoint = params.endpoint.as_deref().unwrap_or_default();
302 ::std::result::Result::Ok(::aws_smithy_types::endpoint::Endpoint::builder().url(endpoint.to_owned()).build())
303 }
304 3 => {
305 let region = params.region.as_deref().unwrap_or_default();
306 let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
307 ::std::result::Result::Ok(
308 ::aws_smithy_types::endpoint::Endpoint::builder()
309 .url({
310 let mut out = String::new();
311 out.push_str("https://eks-auth-fips.");
312 #[allow(clippy::needless_borrow)]
313 out.push_str(®ion.as_ref());
314 out.push_str(".");
315 #[allow(clippy::needless_borrow)]
316 out.push_str(&partition_result.dual_stack_dns_suffix());
317 out
318 })
319 .build(),
320 )
321 }
322 4 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
323 "FIPS is enabled but this partition does not support FIPS".to_string(),
324 )) as ::aws_smithy_runtime_api::box_error::BoxError),
325 5 => {
326 let region = params.region.as_deref().unwrap_or_default();
327 let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
328 ::std::result::Result::Ok(
329 ::aws_smithy_types::endpoint::Endpoint::builder()
330 .url({
331 let mut out = String::new();
332 out.push_str("https://eks-auth.");
333 #[allow(clippy::needless_borrow)]
334 out.push_str(®ion.as_ref());
335 out.push_str(".");
336 #[allow(clippy::needless_borrow)]
337 out.push_str(&partition_result.dual_stack_dns_suffix());
338 out
339 })
340 .build(),
341 )
342 }
343 6 => {
344 let region = params.region.as_deref().unwrap_or_default();
345 let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
346 ::std::result::Result::Ok(
347 ::aws_smithy_types::endpoint::Endpoint::builder()
348 .url({
349 let mut out = String::new();
350 out.push_str("https://eks-auth-fips.");
351 #[allow(clippy::needless_borrow)]
352 out.push_str(®ion.as_ref());
353 out.push_str(".");
354 #[allow(clippy::needless_borrow)]
355 out.push_str(&partition_result.dns_suffix());
356 out
357 })
358 .build(),
359 )
360 }
361 7 => {
362 let region = params.region.as_deref().unwrap_or_default();
363 let partition_result = context.partition_result.as_ref().expect("Guaranteed to have a value by earlier checks.");
364 ::std::result::Result::Ok(
365 ::aws_smithy_types::endpoint::Endpoint::builder()
366 .url({
367 let mut out = String::new();
368 out.push_str("https://eks-auth.");
369 #[allow(clippy::needless_borrow)]
370 out.push_str(®ion.as_ref());
371 out.push_str(".");
372 #[allow(clippy::needless_borrow)]
373 out.push_str(&partition_result.dns_suffix());
374 out
375 })
376 .build(),
377 )
378 }
379 8 => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
380 "Invalid Configuration: Missing Region".to_string(),
381 )) as ::aws_smithy_runtime_api::box_error::BoxError),
382 _ => ::std::result::Result::Err(Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message(
383 "No endpoint rule matched",
384 )) as ::aws_smithy_runtime_api::box_error::BoxError),
385 };
386 }
387 1 | -1 => {
388 return ::std::result::Result::Err(
389 Box::new(::aws_smithy_http::endpoint::ResolveEndpointError::message("No endpoint rule matched"))
390 as ::aws_smithy_runtime_api::box_error::BoxError,
391 )
392 }
393 ref_val => {
394 let is_complement = ref_val < 0;
395 let node = &NODES[(ref_val.unsigned_abs() as usize) - 1];
396 let condition_result = match node.condition_index {
397 0 => endpoint.is_some(),
398 1 => region.is_some(),
399 2 => (|_diagnostic_collector: &mut crate::endpoint_lib::diagnostic::DiagnosticCollector| -> bool {
400 let partition_result = &mut context.partition_result;
401 let partition_resolver = &self.partition_resolver;
402 {
403 *partition_result = partition_resolver
404 .resolve_partition(if let Some(param) = region { param } else { return false }, _diagnostic_collector)
405 .map(|inner| inner.into());
406 partition_result.is_some()
407 }
408 })(&mut _diagnostic_collector),
409 3 => (use_fips) == (&true),
410 4 => (|_diagnostic_collector: &mut crate::endpoint_lib::diagnostic::DiagnosticCollector| -> bool {
411 let partition_result = &context.partition_result;
412 let partition_resolver = &self.partition_resolver;
413 (if let Some(inner) = partition_result {
414 inner.supports_fips()
415 } else {
416 return false;
417 }) == (true)
418 })(&mut _diagnostic_collector),
419 5 => (|_diagnostic_collector: &mut crate::endpoint_lib::diagnostic::DiagnosticCollector| -> bool {
420 let partition_result = &context.partition_result;
421 let partition_resolver = &self.partition_resolver;
422 (if let Some(inner) = partition_result {
423 inner.supports_dual_stack()
424 } else {
425 return false;
426 }) == (true)
427 })(&mut _diagnostic_collector),
428 _ => unreachable!("Invalid condition index"),
429 };
430 current_ref = if is_complement ^ condition_result { node.high_ref } else { node.low_ref };
431 }
432 }
433 }
434 }
435}
436
437impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
438 fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
439 let cached = self.endpoint_cache.load();
441 if let Some((cached_params, cached_endpoint)) = cached.as_ref() {
442 if cached_params == params {
443 return ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(::std::result::Result::Ok(cached_endpoint.clone()));
444 }
445 }
446 drop(cached);
447 let result = self.resolve_endpoint(params);
448 if let ::std::result::Result::Ok(ref endpoint) = result {
449 self.endpoint_cache.store(::std::sync::Arc::new(Some((params.clone(), endpoint.clone()))));
450 }
451 ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(result)
452 }
453}
454const NODES: [crate::endpoint_lib::bdd_interpreter::BddNode; 9] = [
455 crate::endpoint_lib::bdd_interpreter::BddNode {
456 condition_index: -1,
457 high_ref: 1,
458 low_ref: -1,
459 },
460 crate::endpoint_lib::bdd_interpreter::BddNode {
461 condition_index: 0,
462 high_ref: 9,
463 low_ref: 3,
464 },
465 crate::endpoint_lib::bdd_interpreter::BddNode {
466 condition_index: 1,
467 high_ref: 4,
468 low_ref: 100000008,
469 },
470 crate::endpoint_lib::bdd_interpreter::BddNode {
471 condition_index: 2,
472 high_ref: 5,
473 low_ref: 100000008,
474 },
475 crate::endpoint_lib::bdd_interpreter::BddNode {
476 condition_index: 3,
477 high_ref: 7,
478 low_ref: 6,
479 },
480 crate::endpoint_lib::bdd_interpreter::BddNode {
481 condition_index: 5,
482 high_ref: 100000005,
483 low_ref: 100000007,
484 },
485 crate::endpoint_lib::bdd_interpreter::BddNode {
486 condition_index: 4,
487 high_ref: 8,
488 low_ref: 100000004,
489 },
490 crate::endpoint_lib::bdd_interpreter::BddNode {
491 condition_index: 5,
492 high_ref: 100000003,
493 low_ref: 100000006,
494 },
495 crate::endpoint_lib::bdd_interpreter::BddNode {
496 condition_index: 3,
497 high_ref: 100000001,
498 low_ref: 100000002,
499 },
500];
501#[derive(Default)]
504#[allow(unused_lifetimes)]
505pub(crate) struct ConditionContext<'a> {
506 pub(crate) partition_result: Option<crate::endpoint_lib::partition::Partition<'a>>,
507 phantom: std::marker::PhantomData<&'a ()>,
509}
510
511#[non_exhaustive]
512#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
513pub struct Params {
515 pub(crate) region: ::std::option::Option<::std::string::String>,
517 pub(crate) use_fips: bool,
519 pub(crate) endpoint: ::std::option::Option<::std::string::String>,
521}
522impl Params {
523 pub fn builder() -> crate::config::endpoint::ParamsBuilder {
525 crate::config::endpoint::ParamsBuilder::default()
526 }
527 pub fn region(&self) -> ::std::option::Option<&str> {
529 self.region.as_deref()
530 }
531 pub fn use_fips(&self) -> ::std::option::Option<bool> {
533 Some(self.use_fips)
534 }
535 pub fn endpoint(&self) -> ::std::option::Option<&str> {
537 self.endpoint.as_deref()
538 }
539}
540
541#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
543pub struct ParamsBuilder {
544 region: ::std::option::Option<::std::string::String>,
545 use_fips: ::std::option::Option<bool>,
546 endpoint: ::std::option::Option<::std::string::String>,
547}
548impl ParamsBuilder {
549 pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
551 if let Some(region) = &self.region {
552 if !crate::endpoint_lib::host::is_valid_host_label(
553 region.as_ref() as &str,
554 true,
555 &mut crate::endpoint_lib::diagnostic::DiagnosticCollector::new(),
556 ) {
557 return Err(crate::config::endpoint::InvalidParams::invalid_value(
558 "region",
559 "must be a valid host label",
560 ));
561 }
562 };
563 Ok(
564 #[allow(clippy::unnecessary_lazy_evaluations)]
565 crate::config::endpoint::Params {
566 region: self.region,
567 use_fips: self
568 .use_fips
569 .or_else(|| Some(false))
570 .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
571 endpoint: self.endpoint,
572 },
573 )
574 }
575 pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
579 self.region = Some(value.into());
580 self
581 }
582
583 pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
587 self.region = param;
588 self
589 }
590 pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
595 self.use_fips = Some(value.into());
596 self
597 }
598
599 pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
604 self.use_fips = param;
605 self
606 }
607 pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
611 self.endpoint = Some(value.into());
612 self
613 }
614
615 pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
619 self.endpoint = param;
620 self
621 }
622}
623
624#[derive(Debug)]
626pub struct InvalidParams {
627 field: std::borrow::Cow<'static, str>,
628 kind: InvalidParamsErrorKind,
629}
630
631#[derive(Debug)]
633enum InvalidParamsErrorKind {
634 MissingField,
635 InvalidValue { message: &'static str },
636}
637
638impl InvalidParams {
639 #[allow(dead_code)]
640 fn missing(field: &'static str) -> Self {
641 Self {
642 field: field.into(),
643 kind: InvalidParamsErrorKind::MissingField,
644 }
645 }
646
647 #[allow(dead_code)]
648 fn invalid_value(field: &'static str, message: &'static str) -> Self {
649 Self {
650 field: field.into(),
651 kind: InvalidParamsErrorKind::InvalidValue { message },
652 }
653 }
654}
655
656impl std::fmt::Display for InvalidParams {
657 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
658 match self.kind {
659 InvalidParamsErrorKind::MissingField => write!(f, "a required field was missing: `{}`", self.field),
660 InvalidParamsErrorKind::InvalidValue { message } => write!(f, "invalid value for field: `{}` - {}", self.field, message),
661 }
662 }
663}
664
665impl std::error::Error for InvalidParams {}