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