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