aws_sdk_datazone/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#[cfg(test)]
7mod test {
8
9    /// For region us-east-1 with FIPS enabled and DualStack enabled
10    #[test]
11    fn test_1() {
12        let params = crate::config::endpoint::Params::builder()
13            .region("us-east-1".to_string())
14            .use_fips(true)
15            .build()
16            .expect("invalid params");
17        let resolver = crate::config::endpoint::DefaultResolver::new();
18        let endpoint = resolver.resolve_endpoint(&params);
19        let endpoint = endpoint.expect("Expected valid endpoint: https://datazone-fips.us-east-1.api.aws");
20        assert_eq!(
21            endpoint,
22            ::aws_smithy_types::endpoint::Endpoint::builder()
23                .url("https://datazone-fips.us-east-1.api.aws")
24                .build()
25        );
26    }
27
28    /// For region us-east-1 with FIPS disabled and DualStack enabled
29    #[test]
30    fn test_2() {
31        let params = crate::config::endpoint::Params::builder()
32            .region("us-east-1".to_string())
33            .use_fips(false)
34            .build()
35            .expect("invalid params");
36        let resolver = crate::config::endpoint::DefaultResolver::new();
37        let endpoint = resolver.resolve_endpoint(&params);
38        let endpoint = endpoint.expect("Expected valid endpoint: https://datazone.us-east-1.api.aws");
39        assert_eq!(
40            endpoint,
41            ::aws_smithy_types::endpoint::Endpoint::builder()
42                .url("https://datazone.us-east-1.api.aws")
43                .build()
44        );
45    }
46
47    /// For region cn-north-1 with FIPS enabled and DualStack enabled
48    #[test]
49    fn test_3() {
50        let params = crate::config::endpoint::Params::builder()
51            .region("cn-north-1".to_string())
52            .use_fips(true)
53            .build()
54            .expect("invalid params");
55        let resolver = crate::config::endpoint::DefaultResolver::new();
56        let endpoint = resolver.resolve_endpoint(&params);
57        let endpoint = endpoint.expect("Expected valid endpoint: https://datazone-fips.cn-north-1.api.amazonwebservices.com.cn");
58        assert_eq!(
59            endpoint,
60            ::aws_smithy_types::endpoint::Endpoint::builder()
61                .url("https://datazone-fips.cn-north-1.api.amazonwebservices.com.cn")
62                .build()
63        );
64    }
65
66    /// For region cn-north-1 with FIPS disabled and DualStack enabled
67    #[test]
68    fn test_4() {
69        let params = crate::config::endpoint::Params::builder()
70            .region("cn-north-1".to_string())
71            .use_fips(false)
72            .build()
73            .expect("invalid params");
74        let resolver = crate::config::endpoint::DefaultResolver::new();
75        let endpoint = resolver.resolve_endpoint(&params);
76        let endpoint = endpoint.expect("Expected valid endpoint: https://datazone.cn-north-1.api.amazonwebservices.com.cn");
77        assert_eq!(
78            endpoint,
79            ::aws_smithy_types::endpoint::Endpoint::builder()
80                .url("https://datazone.cn-north-1.api.amazonwebservices.com.cn")
81                .build()
82        );
83    }
84
85    /// For region us-gov-east-1 with FIPS enabled and DualStack enabled
86    #[test]
87    fn test_5() {
88        let params = crate::config::endpoint::Params::builder()
89            .region("us-gov-east-1".to_string())
90            .use_fips(true)
91            .build()
92            .expect("invalid params");
93        let resolver = crate::config::endpoint::DefaultResolver::new();
94        let endpoint = resolver.resolve_endpoint(&params);
95        let endpoint = endpoint.expect("Expected valid endpoint: https://datazone-fips.us-gov-east-1.api.aws");
96        assert_eq!(
97            endpoint,
98            ::aws_smithy_types::endpoint::Endpoint::builder()
99                .url("https://datazone-fips.us-gov-east-1.api.aws")
100                .build()
101        );
102    }
103
104    /// For region us-gov-east-1 with FIPS disabled and DualStack enabled
105    #[test]
106    fn test_6() {
107        let params = crate::config::endpoint::Params::builder()
108            .region("us-gov-east-1".to_string())
109            .use_fips(false)
110            .build()
111            .expect("invalid params");
112        let resolver = crate::config::endpoint::DefaultResolver::new();
113        let endpoint = resolver.resolve_endpoint(&params);
114        let endpoint = endpoint.expect("Expected valid endpoint: https://datazone.us-gov-east-1.api.aws");
115        assert_eq!(
116            endpoint,
117            ::aws_smithy_types::endpoint::Endpoint::builder()
118                .url("https://datazone.us-gov-east-1.api.aws")
119                .build()
120        );
121    }
122
123    /// For custom endpoint with region set and fips disabled and dualstack disabled
124    #[test]
125    fn test_7() {
126        let params = crate::config::endpoint::Params::builder()
127            .region("us-east-1".to_string())
128            .use_fips(false)
129            .endpoint("https://example.com".to_string())
130            .build()
131            .expect("invalid params");
132        let resolver = crate::config::endpoint::DefaultResolver::new();
133        let endpoint = resolver.resolve_endpoint(&params);
134        let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
135        assert_eq!(
136            endpoint,
137            ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
138        );
139    }
140
141    /// For custom endpoint with region not set and fips disabled and dualstack disabled
142    #[test]
143    fn test_8() {
144        let params = crate::config::endpoint::Params::builder()
145            .use_fips(false)
146            .endpoint("https://example.com".to_string())
147            .build()
148            .expect("invalid params");
149        let resolver = crate::config::endpoint::DefaultResolver::new();
150        let endpoint = resolver.resolve_endpoint(&params);
151        let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
152        assert_eq!(
153            endpoint,
154            ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
155        );
156    }
157
158    /// For custom endpoint with fips enabled and dualstack disabled
159    #[test]
160    fn test_9() {
161        let params = crate::config::endpoint::Params::builder()
162            .region("us-east-1".to_string())
163            .use_fips(true)
164            .endpoint("https://example.com".to_string())
165            .build()
166            .expect("invalid params");
167        let resolver = crate::config::endpoint::DefaultResolver::new();
168        let endpoint = resolver.resolve_endpoint(&params);
169        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]");
170        assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
171    }
172
173    /// Missing region
174    #[test]
175    fn test_10() {
176        let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
177        let resolver = crate::config::endpoint::DefaultResolver::new();
178        let endpoint = resolver.resolve_endpoint(&params);
179        let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
180        assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
181    }
182}
183
184/// Endpoint resolver trait specific to Amazon DataZone
185pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
186    /// Resolve an endpoint with the given parameters
187    fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
188
189    /// Convert this service-specific resolver into a `SharedEndpointResolver`
190    ///
191    /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`.
192    fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
193    where
194        Self: Sized + 'static,
195    {
196        ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
197    }
198}
199
200#[derive(Debug)]
201struct DowncastParams<T>(T);
202impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
203where
204    T: ResolveEndpoint,
205{
206    fn resolve_endpoint<'a>(
207        &'a self,
208        params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
209    ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
210        let ep = match params.get::<crate::config::endpoint::Params>() {
211            Some(params) => self.0.resolve_endpoint(params),
212            None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
213        };
214        ep
215    }
216}
217
218/// The default endpoint resolver
219#[derive(Debug, Default)]
220pub struct DefaultResolver {
221    partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
222}
223
224impl DefaultResolver {
225    /// Create a new endpoint resolver with default settings
226    pub fn new() -> Self {
227        Self {
228            partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
229        }
230    }
231
232    fn resolve_endpoint(
233        &self,
234        params: &crate::config::endpoint::Params,
235    ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
236        let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
237        Ok(
238            crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
239                .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
240        )
241    }
242}
243
244impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
245    fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'_> {
246        ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
247    }
248}
249
250#[non_exhaustive]
251#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
252/// Configuration parameters for resolving the correct endpoint
253pub struct Params {
254    /// The AWS region used to dispatch the request.
255    pub(crate) region: ::std::option::Option<::std::string::String>,
256    /// 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.
257    pub(crate) use_fips: bool,
258    /// Override the endpoint used to send this request
259    pub(crate) endpoint: ::std::option::Option<::std::string::String>,
260}
261impl Params {
262    /// Create a builder for [`Params`]
263    pub fn builder() -> crate::config::endpoint::ParamsBuilder {
264        crate::config::endpoint::ParamsBuilder::default()
265    }
266    /// The AWS region used to dispatch the request.
267    pub fn region(&self) -> ::std::option::Option<&str> {
268        self.region.as_deref()
269    }
270    /// 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.
271    pub fn use_fips(&self) -> ::std::option::Option<bool> {
272        Some(self.use_fips)
273    }
274    /// Override the endpoint used to send this request
275    pub fn endpoint(&self) -> ::std::option::Option<&str> {
276        self.endpoint.as_deref()
277    }
278}
279
280/// Builder for [`Params`]
281#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
282pub struct ParamsBuilder {
283    region: ::std::option::Option<::std::string::String>,
284    use_fips: ::std::option::Option<bool>,
285    endpoint: ::std::option::Option<::std::string::String>,
286}
287impl ParamsBuilder {
288    /// Consume this builder, creating [`Params`].
289    pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
290        Ok(
291            #[allow(clippy::unnecessary_lazy_evaluations)]
292            crate::config::endpoint::Params {
293                region: self.region,
294                use_fips: self
295                    .use_fips
296                    .or_else(|| Some(false))
297                    .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
298                endpoint: self.endpoint,
299            },
300        )
301    }
302    /// Sets the value for region
303    ///
304    /// The AWS region used to dispatch the request.
305    pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
306        self.region = Some(value.into());
307        self
308    }
309
310    /// Sets the value for region
311    ///
312    /// The AWS region used to dispatch the request.
313    pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
314        self.region = param;
315        self
316    }
317    /// Sets the value for use_fips
318    ///
319    /// When unset, this parameter has a default value of `false`.
320    /// 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.
321    pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
322        self.use_fips = Some(value.into());
323        self
324    }
325
326    /// Sets the value for use_fips
327    ///
328    /// When unset, this parameter has a default value of `false`.
329    /// 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.
330    pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
331        self.use_fips = param;
332        self
333    }
334    /// Sets the value for endpoint
335    ///
336    /// Override the endpoint used to send this request
337    pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
338        self.endpoint = Some(value.into());
339        self
340    }
341
342    /// Sets the value for endpoint
343    ///
344    /// Override the endpoint used to send this request
345    pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
346        self.endpoint = param;
347        self
348    }
349}
350
351/// An error that occurred during endpoint resolution
352#[derive(Debug)]
353pub struct InvalidParams {
354    field: std::borrow::Cow<'static, str>,
355}
356
357impl InvalidParams {
358    #[allow(dead_code)]
359    fn missing(field: &'static str) -> Self {
360        Self { field: field.into() }
361    }
362}
363
364impl std::fmt::Display for InvalidParams {
365    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
366        write!(f, "a required field was missing: `{}`", self.field)
367    }
368}
369
370impl std::error::Error for InvalidParams {}
371
372mod internals;