aws_sdk_notificationscontacts/config/
endpoint.rs1pub 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#[cfg(test)]
7mod test {
8
9 #[test]
11 fn test_1() {
12 let params = crate::config::endpoint::Params::builder()
13 .endpoint("https://example.com".to_string())
14 .use_fips(false)
15 .build()
16 .expect("invalid params");
17 let resolver = crate::config::endpoint::DefaultResolver::new();
18 let endpoint = resolver.resolve_endpoint(¶ms);
19 let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
20 assert_eq!(
21 endpoint,
22 ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
23 );
24 }
25
26 #[test]
28 fn test_2() {
29 let params = crate::config::endpoint::Params::builder()
30 .endpoint("https://example.com".to_string())
31 .use_fips(true)
32 .build()
33 .expect("invalid params");
34 let resolver = crate::config::endpoint::DefaultResolver::new();
35 let endpoint = resolver.resolve_endpoint(¶ms);
36 let error = endpoint
37 .expect_err("expected error: Invalid Configuration: FIPS and custom endpoint are not supported [For custom endpoint with fips enabled]");
38 assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
39 }
40
41 #[test]
43 fn test_3() {
44 let params = crate::config::endpoint::Params::builder()
45 .region("us-east-1".to_string())
46 .use_fips(true)
47 .build()
48 .expect("invalid params");
49 let resolver = crate::config::endpoint::DefaultResolver::new();
50 let endpoint = resolver.resolve_endpoint(¶ms);
51 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts-fips.us-east-1.api.aws");
52 assert_eq!(
53 endpoint,
54 ::aws_smithy_types::endpoint::Endpoint::builder()
55 .url("https://notifications-contacts-fips.us-east-1.api.aws")
56 .property(
57 "authSchemes",
58 vec![{
59 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
60 out.insert("name".to_string(), "sigv4".to_string().into());
61 out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
62 out
63 }
64 .into()]
65 )
66 .build()
67 );
68 }
69
70 #[test]
72 fn test_4() {
73 let params = crate::config::endpoint::Params::builder()
74 .region("us-east-1".to_string())
75 .use_fips(false)
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://notifications-contacts.us-east-1.api.aws");
81 assert_eq!(
82 endpoint,
83 ::aws_smithy_types::endpoint::Endpoint::builder()
84 .url("https://notifications-contacts.us-east-1.api.aws")
85 .property(
86 "authSchemes",
87 vec![{
88 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
89 out.insert("name".to_string(), "sigv4".to_string().into());
90 out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
91 out
92 }
93 .into()]
94 )
95 .build()
96 );
97 }
98
99 #[test]
101 fn test_5() {
102 let params = crate::config::endpoint::Params::builder()
103 .region("cn-northwest-1".to_string())
104 .use_fips(true)
105 .build()
106 .expect("invalid params");
107 let resolver = crate::config::endpoint::DefaultResolver::new();
108 let endpoint = resolver.resolve_endpoint(¶ms);
109 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts-fips.cn-northwest-1.api.amazonwebservices.com.cn");
110 assert_eq!(
111 endpoint,
112 ::aws_smithy_types::endpoint::Endpoint::builder()
113 .url("https://notifications-contacts-fips.cn-northwest-1.api.amazonwebservices.com.cn")
114 .property(
115 "authSchemes",
116 vec![{
117 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
118 out.insert("name".to_string(), "sigv4".to_string().into());
119 out.insert("signingRegion".to_string(), "cn-northwest-1".to_string().into());
120 out
121 }
122 .into()]
123 )
124 .build()
125 );
126 }
127
128 #[test]
130 fn test_6() {
131 let params = crate::config::endpoint::Params::builder()
132 .region("cn-northwest-1".to_string())
133 .use_fips(false)
134 .build()
135 .expect("invalid params");
136 let resolver = crate::config::endpoint::DefaultResolver::new();
137 let endpoint = resolver.resolve_endpoint(¶ms);
138 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts.cn-northwest-1.api.amazonwebservices.com.cn");
139 assert_eq!(
140 endpoint,
141 ::aws_smithy_types::endpoint::Endpoint::builder()
142 .url("https://notifications-contacts.cn-northwest-1.api.amazonwebservices.com.cn")
143 .property(
144 "authSchemes",
145 vec![{
146 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
147 out.insert("name".to_string(), "sigv4".to_string().into());
148 out.insert("signingRegion".to_string(), "cn-northwest-1".to_string().into());
149 out
150 }
151 .into()]
152 )
153 .build()
154 );
155 }
156
157 #[test]
159 fn test_7() {
160 let params = crate::config::endpoint::Params::builder()
161 .region("us-gov-west-1".to_string())
162 .use_fips(true)
163 .build()
164 .expect("invalid params");
165 let resolver = crate::config::endpoint::DefaultResolver::new();
166 let endpoint = resolver.resolve_endpoint(¶ms);
167 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts-fips.us-gov-west-1.api.aws");
168 assert_eq!(
169 endpoint,
170 ::aws_smithy_types::endpoint::Endpoint::builder()
171 .url("https://notifications-contacts-fips.us-gov-west-1.api.aws")
172 .property(
173 "authSchemes",
174 vec![{
175 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
176 out.insert("name".to_string(), "sigv4".to_string().into());
177 out.insert("signingRegion".to_string(), "us-gov-west-1".to_string().into());
178 out
179 }
180 .into()]
181 )
182 .build()
183 );
184 }
185
186 #[test]
188 fn test_8() {
189 let params = crate::config::endpoint::Params::builder()
190 .region("us-gov-west-1".to_string())
191 .use_fips(false)
192 .build()
193 .expect("invalid params");
194 let resolver = crate::config::endpoint::DefaultResolver::new();
195 let endpoint = resolver.resolve_endpoint(¶ms);
196 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts.us-gov-west-1.api.aws");
197 assert_eq!(
198 endpoint,
199 ::aws_smithy_types::endpoint::Endpoint::builder()
200 .url("https://notifications-contacts.us-gov-west-1.api.aws")
201 .property(
202 "authSchemes",
203 vec![{
204 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
205 out.insert("name".to_string(), "sigv4".to_string().into());
206 out.insert("signingRegion".to_string(), "us-gov-west-1".to_string().into());
207 out
208 }
209 .into()]
210 )
211 .build()
212 );
213 }
214
215 #[test]
217 fn test_9() {
218 let params = crate::config::endpoint::Params::builder()
219 .region("us-iso-east-1".to_string())
220 .use_fips(true)
221 .build()
222 .expect("invalid params");
223 let resolver = crate::config::endpoint::DefaultResolver::new();
224 let endpoint = resolver.resolve_endpoint(¶ms);
225 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts-fips.us-iso-east-1.c2s.ic.gov");
226 assert_eq!(
227 endpoint,
228 ::aws_smithy_types::endpoint::Endpoint::builder()
229 .url("https://notifications-contacts-fips.us-iso-east-1.c2s.ic.gov")
230 .property(
231 "authSchemes",
232 vec![{
233 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
234 out.insert("name".to_string(), "sigv4".to_string().into());
235 out.insert("signingRegion".to_string(), "us-iso-east-1".to_string().into());
236 out
237 }
238 .into()]
239 )
240 .build()
241 );
242 }
243
244 #[test]
246 fn test_10() {
247 let params = crate::config::endpoint::Params::builder()
248 .region("us-iso-east-1".to_string())
249 .use_fips(false)
250 .build()
251 .expect("invalid params");
252 let resolver = crate::config::endpoint::DefaultResolver::new();
253 let endpoint = resolver.resolve_endpoint(¶ms);
254 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts.us-iso-east-1.c2s.ic.gov");
255 assert_eq!(
256 endpoint,
257 ::aws_smithy_types::endpoint::Endpoint::builder()
258 .url("https://notifications-contacts.us-iso-east-1.c2s.ic.gov")
259 .property(
260 "authSchemes",
261 vec![{
262 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
263 out.insert("name".to_string(), "sigv4".to_string().into());
264 out.insert("signingRegion".to_string(), "us-iso-east-1".to_string().into());
265 out
266 }
267 .into()]
268 )
269 .build()
270 );
271 }
272
273 #[test]
275 fn test_11() {
276 let params = crate::config::endpoint::Params::builder()
277 .region("us-isob-east-1".to_string())
278 .use_fips(true)
279 .build()
280 .expect("invalid params");
281 let resolver = crate::config::endpoint::DefaultResolver::new();
282 let endpoint = resolver.resolve_endpoint(¶ms);
283 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts-fips.us-isob-east-1.sc2s.sgov.gov");
284 assert_eq!(
285 endpoint,
286 ::aws_smithy_types::endpoint::Endpoint::builder()
287 .url("https://notifications-contacts-fips.us-isob-east-1.sc2s.sgov.gov")
288 .property(
289 "authSchemes",
290 vec![{
291 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
292 out.insert("name".to_string(), "sigv4".to_string().into());
293 out.insert("signingRegion".to_string(), "us-isob-east-1".to_string().into());
294 out
295 }
296 .into()]
297 )
298 .build()
299 );
300 }
301
302 #[test]
304 fn test_12() {
305 let params = crate::config::endpoint::Params::builder()
306 .region("us-isob-east-1".to_string())
307 .use_fips(false)
308 .build()
309 .expect("invalid params");
310 let resolver = crate::config::endpoint::DefaultResolver::new();
311 let endpoint = resolver.resolve_endpoint(¶ms);
312 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts.us-isob-east-1.sc2s.sgov.gov");
313 assert_eq!(
314 endpoint,
315 ::aws_smithy_types::endpoint::Endpoint::builder()
316 .url("https://notifications-contacts.us-isob-east-1.sc2s.sgov.gov")
317 .property(
318 "authSchemes",
319 vec![{
320 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
321 out.insert("name".to_string(), "sigv4".to_string().into());
322 out.insert("signingRegion".to_string(), "us-isob-east-1".to_string().into());
323 out
324 }
325 .into()]
326 )
327 .build()
328 );
329 }
330
331 #[test]
333 fn test_13() {
334 let params = crate::config::endpoint::Params::builder()
335 .region("eu-isoe-west-1".to_string())
336 .use_fips(true)
337 .build()
338 .expect("invalid params");
339 let resolver = crate::config::endpoint::DefaultResolver::new();
340 let endpoint = resolver.resolve_endpoint(¶ms);
341 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts-fips.eu-isoe-west-1.cloud.adc-e.uk");
342 assert_eq!(
343 endpoint,
344 ::aws_smithy_types::endpoint::Endpoint::builder()
345 .url("https://notifications-contacts-fips.eu-isoe-west-1.cloud.adc-e.uk")
346 .property(
347 "authSchemes",
348 vec![{
349 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
350 out.insert("name".to_string(), "sigv4".to_string().into());
351 out.insert("signingRegion".to_string(), "eu-isoe-west-1".to_string().into());
352 out
353 }
354 .into()]
355 )
356 .build()
357 );
358 }
359
360 #[test]
362 fn test_14() {
363 let params = crate::config::endpoint::Params::builder()
364 .region("eu-isoe-west-1".to_string())
365 .use_fips(false)
366 .build()
367 .expect("invalid params");
368 let resolver = crate::config::endpoint::DefaultResolver::new();
369 let endpoint = resolver.resolve_endpoint(¶ms);
370 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts.eu-isoe-west-1.cloud.adc-e.uk");
371 assert_eq!(
372 endpoint,
373 ::aws_smithy_types::endpoint::Endpoint::builder()
374 .url("https://notifications-contacts.eu-isoe-west-1.cloud.adc-e.uk")
375 .property(
376 "authSchemes",
377 vec![{
378 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
379 out.insert("name".to_string(), "sigv4".to_string().into());
380 out.insert("signingRegion".to_string(), "eu-isoe-west-1".to_string().into());
381 out
382 }
383 .into()]
384 )
385 .build()
386 );
387 }
388
389 #[test]
391 fn test_15() {
392 let params = crate::config::endpoint::Params::builder()
393 .region("us-isof-south-1".to_string())
394 .use_fips(true)
395 .build()
396 .expect("invalid params");
397 let resolver = crate::config::endpoint::DefaultResolver::new();
398 let endpoint = resolver.resolve_endpoint(¶ms);
399 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts-fips.us-isof-south-1.csp.hci.ic.gov");
400 assert_eq!(
401 endpoint,
402 ::aws_smithy_types::endpoint::Endpoint::builder()
403 .url("https://notifications-contacts-fips.us-isof-south-1.csp.hci.ic.gov")
404 .property(
405 "authSchemes",
406 vec![{
407 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
408 out.insert("name".to_string(), "sigv4".to_string().into());
409 out.insert("signingRegion".to_string(), "us-isof-south-1".to_string().into());
410 out
411 }
412 .into()]
413 )
414 .build()
415 );
416 }
417
418 #[test]
420 fn test_16() {
421 let params = crate::config::endpoint::Params::builder()
422 .region("us-isof-south-1".to_string())
423 .use_fips(false)
424 .build()
425 .expect("invalid params");
426 let resolver = crate::config::endpoint::DefaultResolver::new();
427 let endpoint = resolver.resolve_endpoint(¶ms);
428 let endpoint = endpoint.expect("Expected valid endpoint: https://notifications-contacts.us-isof-south-1.csp.hci.ic.gov");
429 assert_eq!(
430 endpoint,
431 ::aws_smithy_types::endpoint::Endpoint::builder()
432 .url("https://notifications-contacts.us-isof-south-1.csp.hci.ic.gov")
433 .property(
434 "authSchemes",
435 vec![{
436 let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
437 out.insert("name".to_string(), "sigv4".to_string().into());
438 out.insert("signingRegion".to_string(), "us-isof-south-1".to_string().into());
439 out
440 }
441 .into()]
442 )
443 .build()
444 );
445 }
446
447 #[test]
449 fn test_17() {
450 let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
451 let resolver = crate::config::endpoint::DefaultResolver::new();
452 let endpoint = resolver.resolve_endpoint(¶ms);
453 let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
454 assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
455 }
456}
457
458pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
460 fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
462
463 fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
467 where
468 Self: Sized + 'static,
469 {
470 ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
471 }
472}
473
474#[derive(Debug)]
475struct DowncastParams<T>(T);
476impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
477where
478 T: ResolveEndpoint,
479{
480 fn resolve_endpoint<'a>(
481 &'a self,
482 params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
483 ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
484 let ep = match params.get::<crate::config::endpoint::Params>() {
485 Some(params) => self.0.resolve_endpoint(params),
486 None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
487 };
488 ep
489 }
490}
491
492#[derive(Debug, Default)]
494pub struct DefaultResolver {
495 partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
496}
497
498impl DefaultResolver {
499 pub fn new() -> Self {
501 Self {
502 partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
503 }
504 }
505
506 fn resolve_endpoint(
507 &self,
508 params: &crate::config::endpoint::Params,
509 ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
510 let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
511 Ok(
512 crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
513 .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
514 )
515 }
516}
517
518impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
519 fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture {
520 ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
521 }
522}
523
524#[non_exhaustive]
525#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
526pub struct Params {
528 pub(crate) use_fips: bool,
530 pub(crate) endpoint: ::std::option::Option<::std::string::String>,
532 pub(crate) region: ::std::option::Option<::std::string::String>,
534}
535impl Params {
536 pub fn builder() -> crate::config::endpoint::ParamsBuilder {
538 crate::config::endpoint::ParamsBuilder::default()
539 }
540 pub fn use_fips(&self) -> ::std::option::Option<bool> {
542 Some(self.use_fips)
543 }
544 pub fn endpoint(&self) -> ::std::option::Option<&str> {
546 self.endpoint.as_deref()
547 }
548 pub fn region(&self) -> ::std::option::Option<&str> {
550 self.region.as_deref()
551 }
552}
553
554#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
556pub struct ParamsBuilder {
557 use_fips: ::std::option::Option<bool>,
558 endpoint: ::std::option::Option<::std::string::String>,
559 region: ::std::option::Option<::std::string::String>,
560}
561impl ParamsBuilder {
562 pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
564 Ok(
565 #[allow(clippy::unnecessary_lazy_evaluations)]
566 crate::config::endpoint::Params {
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 region: self.region,
573 },
574 )
575 }
576 pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
581 self.use_fips = Some(value.into());
582 self
583 }
584
585 pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
590 self.use_fips = param;
591 self
592 }
593 pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
597 self.endpoint = Some(value.into());
598 self
599 }
600
601 pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
605 self.endpoint = param;
606 self
607 }
608 pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
612 self.region = Some(value.into());
613 self
614 }
615
616 pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
620 self.region = param;
621 self
622 }
623}
624
625#[derive(Debug)]
627pub struct InvalidParams {
628 field: std::borrow::Cow<'static, str>,
629}
630
631impl InvalidParams {
632 #[allow(dead_code)]
633 fn missing(field: &'static str) -> Self {
634 Self { field: field.into() }
635 }
636}
637
638impl std::fmt::Display for InvalidParams {
639 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
640 write!(f, "a required field was missing: `{}`", self.field)
641 }
642}
643
644impl std::error::Error for InvalidParams {}
645
646mod internals;