aws_sdk_codecatalyst/config/
endpoint.rs1pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture;
3pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver;
4pub use ::aws_smithy_types::endpoint::Endpoint;
5
6#[cfg(test)]
7mod test {
8
9 #[test]
11 fn test_1() {
12 let params = crate::config::endpoint::Params::builder()
13 .endpoint("https://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(¶ms);
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 #[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(¶ms);
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 #[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(¶ms);
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 #[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(¶ms);
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 #[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(¶ms);
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 #[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(¶ms);
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 #[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(¶ms);
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 #[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(¶ms);
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 #[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(¶ms);
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
169pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
171 fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
173
174 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#[derive(Debug, Default)]
205pub struct DefaultResolver {
206 partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
207}
208
209impl DefaultResolver {
210 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)]
237pub struct Params {
239 pub(crate) use_fips: bool,
241 pub(crate) region: ::std::option::Option<::std::string::String>,
243 pub(crate) endpoint: ::std::option::Option<::std::string::String>,
245}
246impl Params {
247 pub fn builder() -> crate::config::endpoint::ParamsBuilder {
249 crate::config::endpoint::ParamsBuilder::default()
250 }
251 pub fn use_fips(&self) -> ::std::option::Option<bool> {
253 Some(self.use_fips)
254 }
255 pub fn region(&self) -> ::std::option::Option<&str> {
257 self.region.as_deref()
258 }
259 pub fn endpoint(&self) -> ::std::option::Option<&str> {
261 self.endpoint.as_deref()
262 }
263}
264
265#[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 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 pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
292 self.use_fips = Some(value.into());
293 self
294 }
295
296 pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
301 self.use_fips = param;
302 self
303 }
304 pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
308 self.region = Some(value.into());
309 self
310 }
311
312 pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
316 self.region = param;
317 self
318 }
319 pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
323 self.endpoint = Some(value.into());
324 self
325 }
326
327 pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
331 self.endpoint = param;
332 self
333 }
334}
335
336#[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;