aws_sdk_shield/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 region aws-global with FIPS disabled and DualStack disabled
32    #[test]
33    fn test_1() {
34        let params = crate::config::endpoint::Params::builder()
35            .region("aws-global".to_string())
36            .use_fips(false)
37            .use_dual_stack(false)
38            .build()
39            .expect("invalid params");
40        let resolver = crate::config::endpoint::DefaultResolver::new();
41        let endpoint = resolver.resolve_endpoint(&params);
42        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.us-east-1.amazonaws.com");
43        assert_eq!(
44            endpoint,
45            ::aws_smithy_types::endpoint::Endpoint::builder()
46                .url("https://shield.us-east-1.amazonaws.com")
47                .property(
48                    "authSchemes",
49                    vec![{
50                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
51                        out.insert("name".to_string(), "sigv4".to_string().into());
52                        out.insert("signingName".to_string(), "shield".to_string().into());
53                        out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
54                        out
55                    }
56                    .into()]
57                )
58                .build()
59        );
60    }
61
62    /// For region aws-global with FIPS enabled and DualStack disabled
63    #[test]
64    fn test_2() {
65        let params = crate::config::endpoint::Params::builder()
66            .region("aws-global".to_string())
67            .use_fips(true)
68            .use_dual_stack(false)
69            .build()
70            .expect("invalid params");
71        let resolver = crate::config::endpoint::DefaultResolver::new();
72        let endpoint = resolver.resolve_endpoint(&params);
73        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.us-east-1.amazonaws.com");
74        assert_eq!(
75            endpoint,
76            ::aws_smithy_types::endpoint::Endpoint::builder()
77                .url("https://shield-fips.us-east-1.amazonaws.com")
78                .property(
79                    "authSchemes",
80                    vec![{
81                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
82                        out.insert("name".to_string(), "sigv4".to_string().into());
83                        out.insert("signingName".to_string(), "shield".to_string().into());
84                        out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
85                        out
86                    }
87                    .into()]
88                )
89                .build()
90        );
91    }
92
93    /// For region us-east-1 with FIPS enabled and DualStack enabled
94    #[test]
95    fn test_3() {
96        let params = crate::config::endpoint::Params::builder()
97            .region("us-east-1".to_string())
98            .use_fips(true)
99            .use_dual_stack(true)
100            .build()
101            .expect("invalid params");
102        let resolver = crate::config::endpoint::DefaultResolver::new();
103        let endpoint = resolver.resolve_endpoint(&params);
104        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.us-east-1.api.aws");
105        assert_eq!(
106            endpoint,
107            ::aws_smithy_types::endpoint::Endpoint::builder()
108                .url("https://shield-fips.us-east-1.api.aws")
109                .build()
110        );
111    }
112
113    /// For region us-east-1 with FIPS enabled and DualStack disabled
114    #[test]
115    fn test_4() {
116        let params = crate::config::endpoint::Params::builder()
117            .region("us-east-1".to_string())
118            .use_fips(true)
119            .use_dual_stack(false)
120            .build()
121            .expect("invalid params");
122        let resolver = crate::config::endpoint::DefaultResolver::new();
123        let endpoint = resolver.resolve_endpoint(&params);
124        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.us-east-1.amazonaws.com");
125        assert_eq!(
126            endpoint,
127            ::aws_smithy_types::endpoint::Endpoint::builder()
128                .url("https://shield-fips.us-east-1.amazonaws.com")
129                .property(
130                    "authSchemes",
131                    vec![{
132                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
133                        out.insert("name".to_string(), "sigv4".to_string().into());
134                        out.insert("signingName".to_string(), "shield".to_string().into());
135                        out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
136                        out
137                    }
138                    .into()]
139                )
140                .build()
141        );
142    }
143
144    /// For region us-east-1 with FIPS disabled and DualStack enabled
145    #[test]
146    fn test_5() {
147        let params = crate::config::endpoint::Params::builder()
148            .region("us-east-1".to_string())
149            .use_fips(false)
150            .use_dual_stack(true)
151            .build()
152            .expect("invalid params");
153        let resolver = crate::config::endpoint::DefaultResolver::new();
154        let endpoint = resolver.resolve_endpoint(&params);
155        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.us-east-1.api.aws");
156        assert_eq!(
157            endpoint,
158            ::aws_smithy_types::endpoint::Endpoint::builder()
159                .url("https://shield.us-east-1.api.aws")
160                .build()
161        );
162    }
163
164    /// For region us-east-1 with FIPS disabled and DualStack disabled
165    #[test]
166    fn test_6() {
167        let params = crate::config::endpoint::Params::builder()
168            .region("us-east-1".to_string())
169            .use_fips(false)
170            .use_dual_stack(false)
171            .build()
172            .expect("invalid params");
173        let resolver = crate::config::endpoint::DefaultResolver::new();
174        let endpoint = resolver.resolve_endpoint(&params);
175        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.us-east-1.amazonaws.com");
176        assert_eq!(
177            endpoint,
178            ::aws_smithy_types::endpoint::Endpoint::builder()
179                .url("https://shield.us-east-1.amazonaws.com")
180                .property(
181                    "authSchemes",
182                    vec![{
183                        let mut out = ::std::collections::HashMap::<String, ::aws_smithy_types::Document>::new();
184                        out.insert("name".to_string(), "sigv4".to_string().into());
185                        out.insert("signingName".to_string(), "shield".to_string().into());
186                        out.insert("signingRegion".to_string(), "us-east-1".to_string().into());
187                        out
188                    }
189                    .into()]
190                )
191                .build()
192        );
193    }
194
195    /// For region cn-north-1 with FIPS enabled and DualStack enabled
196    #[test]
197    fn test_7() {
198        let params = crate::config::endpoint::Params::builder()
199            .region("cn-north-1".to_string())
200            .use_fips(true)
201            .use_dual_stack(true)
202            .build()
203            .expect("invalid params");
204        let resolver = crate::config::endpoint::DefaultResolver::new();
205        let endpoint = resolver.resolve_endpoint(&params);
206        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.cn-north-1.api.amazonwebservices.com.cn");
207        assert_eq!(
208            endpoint,
209            ::aws_smithy_types::endpoint::Endpoint::builder()
210                .url("https://shield-fips.cn-north-1.api.amazonwebservices.com.cn")
211                .build()
212        );
213    }
214
215    /// For region cn-north-1 with FIPS enabled and DualStack disabled
216    #[test]
217    fn test_8() {
218        let params = crate::config::endpoint::Params::builder()
219            .region("cn-north-1".to_string())
220            .use_fips(true)
221            .use_dual_stack(false)
222            .build()
223            .expect("invalid params");
224        let resolver = crate::config::endpoint::DefaultResolver::new();
225        let endpoint = resolver.resolve_endpoint(&params);
226        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.cn-north-1.amazonaws.com.cn");
227        assert_eq!(
228            endpoint,
229            ::aws_smithy_types::endpoint::Endpoint::builder()
230                .url("https://shield-fips.cn-north-1.amazonaws.com.cn")
231                .build()
232        );
233    }
234
235    /// For region cn-north-1 with FIPS disabled and DualStack enabled
236    #[test]
237    fn test_9() {
238        let params = crate::config::endpoint::Params::builder()
239            .region("cn-north-1".to_string())
240            .use_fips(false)
241            .use_dual_stack(true)
242            .build()
243            .expect("invalid params");
244        let resolver = crate::config::endpoint::DefaultResolver::new();
245        let endpoint = resolver.resolve_endpoint(&params);
246        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.cn-north-1.api.amazonwebservices.com.cn");
247        assert_eq!(
248            endpoint,
249            ::aws_smithy_types::endpoint::Endpoint::builder()
250                .url("https://shield.cn-north-1.api.amazonwebservices.com.cn")
251                .build()
252        );
253    }
254
255    /// For region cn-north-1 with FIPS disabled and DualStack disabled
256    #[test]
257    fn test_10() {
258        let params = crate::config::endpoint::Params::builder()
259            .region("cn-north-1".to_string())
260            .use_fips(false)
261            .use_dual_stack(false)
262            .build()
263            .expect("invalid params");
264        let resolver = crate::config::endpoint::DefaultResolver::new();
265        let endpoint = resolver.resolve_endpoint(&params);
266        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.cn-north-1.amazonaws.com.cn");
267        assert_eq!(
268            endpoint,
269            ::aws_smithy_types::endpoint::Endpoint::builder()
270                .url("https://shield.cn-north-1.amazonaws.com.cn")
271                .build()
272        );
273    }
274
275    /// For region us-gov-east-1 with FIPS enabled and DualStack enabled
276    #[test]
277    fn test_11() {
278        let params = crate::config::endpoint::Params::builder()
279            .region("us-gov-east-1".to_string())
280            .use_fips(true)
281            .use_dual_stack(true)
282            .build()
283            .expect("invalid params");
284        let resolver = crate::config::endpoint::DefaultResolver::new();
285        let endpoint = resolver.resolve_endpoint(&params);
286        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.us-gov-east-1.api.aws");
287        assert_eq!(
288            endpoint,
289            ::aws_smithy_types::endpoint::Endpoint::builder()
290                .url("https://shield-fips.us-gov-east-1.api.aws")
291                .build()
292        );
293    }
294
295    /// For region us-gov-east-1 with FIPS enabled and DualStack disabled
296    #[test]
297    fn test_12() {
298        let params = crate::config::endpoint::Params::builder()
299            .region("us-gov-east-1".to_string())
300            .use_fips(true)
301            .use_dual_stack(false)
302            .build()
303            .expect("invalid params");
304        let resolver = crate::config::endpoint::DefaultResolver::new();
305        let endpoint = resolver.resolve_endpoint(&params);
306        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.us-gov-east-1.amazonaws.com");
307        assert_eq!(
308            endpoint,
309            ::aws_smithy_types::endpoint::Endpoint::builder()
310                .url("https://shield-fips.us-gov-east-1.amazonaws.com")
311                .build()
312        );
313    }
314
315    /// For region us-gov-east-1 with FIPS disabled and DualStack enabled
316    #[test]
317    fn test_13() {
318        let params = crate::config::endpoint::Params::builder()
319            .region("us-gov-east-1".to_string())
320            .use_fips(false)
321            .use_dual_stack(true)
322            .build()
323            .expect("invalid params");
324        let resolver = crate::config::endpoint::DefaultResolver::new();
325        let endpoint = resolver.resolve_endpoint(&params);
326        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.us-gov-east-1.api.aws");
327        assert_eq!(
328            endpoint,
329            ::aws_smithy_types::endpoint::Endpoint::builder()
330                .url("https://shield.us-gov-east-1.api.aws")
331                .build()
332        );
333    }
334
335    /// For region us-gov-east-1 with FIPS disabled and DualStack disabled
336    #[test]
337    fn test_14() {
338        let params = crate::config::endpoint::Params::builder()
339            .region("us-gov-east-1".to_string())
340            .use_fips(false)
341            .use_dual_stack(false)
342            .build()
343            .expect("invalid params");
344        let resolver = crate::config::endpoint::DefaultResolver::new();
345        let endpoint = resolver.resolve_endpoint(&params);
346        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.us-gov-east-1.amazonaws.com");
347        assert_eq!(
348            endpoint,
349            ::aws_smithy_types::endpoint::Endpoint::builder()
350                .url("https://shield.us-gov-east-1.amazonaws.com")
351                .build()
352        );
353    }
354
355    /// For region us-iso-east-1 with FIPS enabled and DualStack disabled
356    #[test]
357    fn test_15() {
358        let params = crate::config::endpoint::Params::builder()
359            .region("us-iso-east-1".to_string())
360            .use_fips(true)
361            .use_dual_stack(false)
362            .build()
363            .expect("invalid params");
364        let resolver = crate::config::endpoint::DefaultResolver::new();
365        let endpoint = resolver.resolve_endpoint(&params);
366        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.us-iso-east-1.c2s.ic.gov");
367        assert_eq!(
368            endpoint,
369            ::aws_smithy_types::endpoint::Endpoint::builder()
370                .url("https://shield-fips.us-iso-east-1.c2s.ic.gov")
371                .build()
372        );
373    }
374
375    /// For region us-iso-east-1 with FIPS disabled and DualStack disabled
376    #[test]
377    fn test_16() {
378        let params = crate::config::endpoint::Params::builder()
379            .region("us-iso-east-1".to_string())
380            .use_fips(false)
381            .use_dual_stack(false)
382            .build()
383            .expect("invalid params");
384        let resolver = crate::config::endpoint::DefaultResolver::new();
385        let endpoint = resolver.resolve_endpoint(&params);
386        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.us-iso-east-1.c2s.ic.gov");
387        assert_eq!(
388            endpoint,
389            ::aws_smithy_types::endpoint::Endpoint::builder()
390                .url("https://shield.us-iso-east-1.c2s.ic.gov")
391                .build()
392        );
393    }
394
395    /// For region us-isob-east-1 with FIPS enabled and DualStack disabled
396    #[test]
397    fn test_17() {
398        let params = crate::config::endpoint::Params::builder()
399            .region("us-isob-east-1".to_string())
400            .use_fips(true)
401            .use_dual_stack(false)
402            .build()
403            .expect("invalid params");
404        let resolver = crate::config::endpoint::DefaultResolver::new();
405        let endpoint = resolver.resolve_endpoint(&params);
406        let endpoint = endpoint.expect("Expected valid endpoint: https://shield-fips.us-isob-east-1.sc2s.sgov.gov");
407        assert_eq!(
408            endpoint,
409            ::aws_smithy_types::endpoint::Endpoint::builder()
410                .url("https://shield-fips.us-isob-east-1.sc2s.sgov.gov")
411                .build()
412        );
413    }
414
415    /// For region us-isob-east-1 with FIPS disabled and DualStack disabled
416    #[test]
417    fn test_18() {
418        let params = crate::config::endpoint::Params::builder()
419            .region("us-isob-east-1".to_string())
420            .use_fips(false)
421            .use_dual_stack(false)
422            .build()
423            .expect("invalid params");
424        let resolver = crate::config::endpoint::DefaultResolver::new();
425        let endpoint = resolver.resolve_endpoint(&params);
426        let endpoint = endpoint.expect("Expected valid endpoint: https://shield.us-isob-east-1.sc2s.sgov.gov");
427        assert_eq!(
428            endpoint,
429            ::aws_smithy_types::endpoint::Endpoint::builder()
430                .url("https://shield.us-isob-east-1.sc2s.sgov.gov")
431                .build()
432        );
433    }
434
435    /// For custom endpoint with region set and fips disabled and dualstack disabled
436    #[test]
437    fn test_19() {
438        let params = crate::config::endpoint::Params::builder()
439            .region("us-east-1".to_string())
440            .use_fips(false)
441            .use_dual_stack(false)
442            .endpoint("https://example.com".to_string())
443            .build()
444            .expect("invalid params");
445        let resolver = crate::config::endpoint::DefaultResolver::new();
446        let endpoint = resolver.resolve_endpoint(&params);
447        let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
448        assert_eq!(
449            endpoint,
450            ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
451        );
452    }
453
454    /// For custom endpoint with region not set and fips disabled and dualstack disabled
455    #[test]
456    fn test_20() {
457        let params = crate::config::endpoint::Params::builder()
458            .use_fips(false)
459            .use_dual_stack(false)
460            .endpoint("https://example.com".to_string())
461            .build()
462            .expect("invalid params");
463        let resolver = crate::config::endpoint::DefaultResolver::new();
464        let endpoint = resolver.resolve_endpoint(&params);
465        let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
466        assert_eq!(
467            endpoint,
468            ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
469        );
470    }
471
472    /// For custom endpoint with fips enabled and dualstack disabled
473    #[test]
474    fn test_21() {
475        let params = crate::config::endpoint::Params::builder()
476            .region("us-east-1".to_string())
477            .use_fips(true)
478            .use_dual_stack(false)
479            .endpoint("https://example.com".to_string())
480            .build()
481            .expect("invalid params");
482        let resolver = crate::config::endpoint::DefaultResolver::new();
483        let endpoint = resolver.resolve_endpoint(&params);
484        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]");
485        assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
486    }
487
488    /// For custom endpoint with fips disabled and dualstack enabled
489    #[test]
490    fn test_22() {
491        let params = crate::config::endpoint::Params::builder()
492            .region("us-east-1".to_string())
493            .use_fips(false)
494            .use_dual_stack(true)
495            .endpoint("https://example.com".to_string())
496            .build()
497            .expect("invalid params");
498        let resolver = crate::config::endpoint::DefaultResolver::new();
499        let endpoint = resolver.resolve_endpoint(&params);
500        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]");
501        assert_eq!(
502            format!("{}", error),
503            "Invalid Configuration: Dualstack and custom endpoint are not supported"
504        )
505    }
506
507    /// Missing region
508    #[test]
509    fn test_23() {
510        let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
511        let resolver = crate::config::endpoint::DefaultResolver::new();
512        let endpoint = resolver.resolve_endpoint(&params);
513        let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
514        assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
515    }
516}
517
518/// Endpoint resolver trait specific to AWS Shield
519pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
520    /// Resolve an endpoint with the given parameters
521    fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
522
523    /// Convert this service-specific resolver into a `SharedEndpointResolver`
524    ///
525    /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`.
526    fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
527    where
528        Self: Sized + 'static,
529    {
530        ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
531    }
532}
533
534#[derive(Debug)]
535struct DowncastParams<T>(T);
536impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
537where
538    T: ResolveEndpoint,
539{
540    fn resolve_endpoint<'a>(
541        &'a self,
542        params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
543    ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
544        let ep = match params.get::<crate::config::endpoint::Params>() {
545            Some(params) => self.0.resolve_endpoint(params),
546            None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
547        };
548        ep
549    }
550}
551
552/// The default endpoint resolver
553#[derive(Debug, Default)]
554pub struct DefaultResolver {
555    partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
556}
557
558impl DefaultResolver {
559    /// Create a new endpoint resolver with default settings
560    pub fn new() -> Self {
561        Self {
562            partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
563        }
564    }
565
566    fn resolve_endpoint(
567        &self,
568        params: &crate::config::endpoint::Params,
569    ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
570        let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
571        Ok(
572            crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
573                .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
574        )
575    }
576}
577
578impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
579    fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'_> {
580        ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
581    }
582}
583
584#[non_exhaustive]
585#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
586/// Configuration parameters for resolving the correct endpoint
587pub struct Params {
588    /// The AWS region used to dispatch the request.
589    pub(crate) region: ::std::option::Option<::std::string::String>,
590    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
591    pub(crate) use_dual_stack: bool,
592    /// 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.
593    pub(crate) use_fips: bool,
594    /// Override the endpoint used to send this request
595    pub(crate) endpoint: ::std::option::Option<::std::string::String>,
596}
597impl Params {
598    /// Create a builder for [`Params`]
599    pub fn builder() -> crate::config::endpoint::ParamsBuilder {
600        crate::config::endpoint::ParamsBuilder::default()
601    }
602    /// The AWS region used to dispatch the request.
603    pub fn region(&self) -> ::std::option::Option<&str> {
604        self.region.as_deref()
605    }
606    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
607    pub fn use_dual_stack(&self) -> ::std::option::Option<bool> {
608        Some(self.use_dual_stack)
609    }
610    /// 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.
611    pub fn use_fips(&self) -> ::std::option::Option<bool> {
612        Some(self.use_fips)
613    }
614    /// Override the endpoint used to send this request
615    pub fn endpoint(&self) -> ::std::option::Option<&str> {
616        self.endpoint.as_deref()
617    }
618}
619
620/// Builder for [`Params`]
621#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
622pub struct ParamsBuilder {
623    region: ::std::option::Option<::std::string::String>,
624    use_dual_stack: ::std::option::Option<bool>,
625    use_fips: ::std::option::Option<bool>,
626    endpoint: ::std::option::Option<::std::string::String>,
627}
628impl ParamsBuilder {
629    /// Consume this builder, creating [`Params`].
630    pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
631        if let Some(region) = &self.region {
632            if !crate::endpoint_lib::host::is_valid_host_label(
633                region.as_ref() as &str,
634                true,
635                &mut crate::endpoint_lib::diagnostic::DiagnosticCollector::new(),
636            ) {
637                return Err(crate::config::endpoint::InvalidParams::invalid_value(
638                    "region",
639                    "must be a valid host label",
640                ));
641            }
642        };
643        Ok(
644            #[allow(clippy::unnecessary_lazy_evaluations)]
645            crate::config::endpoint::Params {
646                region: self.region,
647                use_dual_stack: self
648                    .use_dual_stack
649                    .or_else(|| Some(false))
650                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_dual_stack"))?,
651                use_fips: self
652                    .use_fips
653                    .or_else(|| Some(false))
654                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
655                endpoint: self.endpoint,
656            },
657        )
658    }
659    /// Sets the value for region
660    ///
661    /// The AWS region used to dispatch the request.
662    pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
663        self.region = Some(value.into());
664        self
665    }
666
667    /// Sets the value for region
668    ///
669    /// The AWS region used to dispatch the request.
670    pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
671        self.region = param;
672        self
673    }
674    /// Sets the value for use_dual_stack
675    ///
676    /// When unset, this parameter has a default value of `false`.
677    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
678    pub fn use_dual_stack(mut self, value: impl Into<bool>) -> Self {
679        self.use_dual_stack = Some(value.into());
680        self
681    }
682
683    /// Sets the value for use_dual_stack
684    ///
685    /// When unset, this parameter has a default value of `false`.
686    /// When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
687    pub fn set_use_dual_stack(mut self, param: Option<bool>) -> Self {
688        self.use_dual_stack = param;
689        self
690    }
691    /// Sets the value for use_fips
692    ///
693    /// When unset, this parameter has a default value of `false`.
694    /// 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.
695    pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
696        self.use_fips = Some(value.into());
697        self
698    }
699
700    /// Sets the value for use_fips
701    ///
702    /// When unset, this parameter has a default value of `false`.
703    /// 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.
704    pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
705        self.use_fips = param;
706        self
707    }
708    /// Sets the value for endpoint
709    ///
710    /// Override the endpoint used to send this request
711    pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
712        self.endpoint = Some(value.into());
713        self
714    }
715
716    /// Sets the value for endpoint
717    ///
718    /// Override the endpoint used to send this request
719    pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
720        self.endpoint = param;
721        self
722    }
723}
724
725/// An error that occurred during endpoint resolution
726#[derive(Debug)]
727pub struct InvalidParams {
728    field: std::borrow::Cow<'static, str>,
729    kind: InvalidParamsErrorKind,
730}
731
732/// The kind of invalid parameter error
733#[derive(Debug)]
734enum InvalidParamsErrorKind {
735    MissingField,
736    InvalidValue { message: &'static str },
737}
738
739impl InvalidParams {
740    #[allow(dead_code)]
741    fn missing(field: &'static str) -> Self {
742        Self {
743            field: field.into(),
744            kind: InvalidParamsErrorKind::MissingField,
745        }
746    }
747
748    #[allow(dead_code)]
749    fn invalid_value(field: &'static str, message: &'static str) -> Self {
750        Self {
751            field: field.into(),
752            kind: InvalidParamsErrorKind::InvalidValue { message },
753        }
754    }
755}
756
757impl std::fmt::Display for InvalidParams {
758    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
759        match self.kind {
760            InvalidParamsErrorKind::MissingField => write!(f, "a required field was missing: `{}`", self.field),
761            InvalidParamsErrorKind::InvalidValue { message } => write!(f, "invalid value for field: `{}` - {}", self.field, message),
762        }
763    }
764}
765
766impl std::error::Error for InvalidParams {}
767
768mod internals;