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#[derive(Debug, Default)]
8pub(crate) struct EndpointOverrideFeatureTrackerInterceptor;
9
10#[::aws_smithy_runtime_api::client::interceptors::dyn_dispatch_hint]
11impl ::aws_smithy_runtime_api::client::interceptors::Intercept for EndpointOverrideFeatureTrackerInterceptor {
12 fn name(&self) -> &'static str {
13 "EndpointOverrideFeatureTrackerInterceptor"
14 }
15
16 fn read_before_execution(
17 &self,
18 _context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<'_>,
19 cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
20 ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
21 if cfg.load::<::aws_types::endpoint_config::EndpointUrl>().is_some() {
22 cfg.interceptor_state()
23 .store_append(::aws_runtime::sdk_feature::AwsSdkFeature::EndpointOverride);
24 }
25 ::std::result::Result::Ok(())
26 }
27}
28
29#[cfg(test)]
30mod test {
31
32 #[test]
34 fn test_1() {
35 let params = crate::config::endpoint::Params::builder()
36 .endpoint("https://test.codecatalyst.global.api.aws".to_string())
37 .build()
38 .expect("invalid params");
39 let resolver = crate::config::endpoint::DefaultResolver::new();
40 let endpoint = resolver.resolve_endpoint(¶ms);
41 let endpoint = endpoint.expect("Expected valid endpoint: https://test.codecatalyst.global.api.aws");
42 assert_eq!(
43 endpoint,
44 ::aws_smithy_types::endpoint::Endpoint::builder()
45 .url("https://test.codecatalyst.global.api.aws")
46 .build()
47 );
48 }
49
50 #[test]
52 fn test_2() {
53 let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
54 let resolver = crate::config::endpoint::DefaultResolver::new();
55 let endpoint = resolver.resolve_endpoint(¶ms);
56 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst.global.api.aws");
57 assert_eq!(
58 endpoint,
59 ::aws_smithy_types::endpoint::Endpoint::builder()
60 .url("https://codecatalyst.global.api.aws")
61 .build()
62 );
63 }
64
65 #[test]
67 fn test_3() {
68 let params = crate::config::endpoint::Params::builder().use_fips(true).build().expect("invalid params");
69 let resolver = crate::config::endpoint::DefaultResolver::new();
70 let endpoint = resolver.resolve_endpoint(¶ms);
71 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst-fips.global.api.aws");
72 assert_eq!(
73 endpoint,
74 ::aws_smithy_types::endpoint::Endpoint::builder()
75 .url("https://codecatalyst-fips.global.api.aws")
76 .build()
77 );
78 }
79
80 #[test]
82 fn test_4() {
83 let params = crate::config::endpoint::Params::builder()
84 .region("aws-global".to_string())
85 .build()
86 .expect("invalid params");
87 let resolver = crate::config::endpoint::DefaultResolver::new();
88 let endpoint = resolver.resolve_endpoint(¶ms);
89 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst.global.api.aws");
90 assert_eq!(
91 endpoint,
92 ::aws_smithy_types::endpoint::Endpoint::builder()
93 .url("https://codecatalyst.global.api.aws")
94 .build()
95 );
96 }
97
98 #[test]
100 fn test_5() {
101 let params = crate::config::endpoint::Params::builder()
102 .region("aws-global".to_string())
103 .use_fips(true)
104 .build()
105 .expect("invalid params");
106 let resolver = crate::config::endpoint::DefaultResolver::new();
107 let endpoint = resolver.resolve_endpoint(¶ms);
108 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst-fips.global.api.aws");
109 assert_eq!(
110 endpoint,
111 ::aws_smithy_types::endpoint::Endpoint::builder()
112 .url("https://codecatalyst-fips.global.api.aws")
113 .build()
114 );
115 }
116
117 #[test]
119 fn test_6() {
120 let params = crate::config::endpoint::Params::builder()
121 .region("us-west-2".to_string())
122 .build()
123 .expect("invalid params");
124 let resolver = crate::config::endpoint::DefaultResolver::new();
125 let endpoint = resolver.resolve_endpoint(¶ms);
126 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst.global.api.aws");
127 assert_eq!(
128 endpoint,
129 ::aws_smithy_types::endpoint::Endpoint::builder()
130 .url("https://codecatalyst.global.api.aws")
131 .build()
132 );
133 }
134
135 #[test]
137 fn test_7() {
138 let params = crate::config::endpoint::Params::builder()
139 .region("us-west-2".to_string())
140 .use_fips(true)
141 .build()
142 .expect("invalid params");
143 let resolver = crate::config::endpoint::DefaultResolver::new();
144 let endpoint = resolver.resolve_endpoint(¶ms);
145 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst-fips.global.api.aws");
146 assert_eq!(
147 endpoint,
148 ::aws_smithy_types::endpoint::Endpoint::builder()
149 .url("https://codecatalyst-fips.global.api.aws")
150 .build()
151 );
152 }
153
154 #[test]
156 fn test_8() {
157 let params = crate::config::endpoint::Params::builder()
158 .region("us-east-1".to_string())
159 .build()
160 .expect("invalid params");
161 let resolver = crate::config::endpoint::DefaultResolver::new();
162 let endpoint = resolver.resolve_endpoint(¶ms);
163 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst.global.api.aws");
164 assert_eq!(
165 endpoint,
166 ::aws_smithy_types::endpoint::Endpoint::builder()
167 .url("https://codecatalyst.global.api.aws")
168 .build()
169 );
170 }
171
172 #[test]
174 fn test_9() {
175 let params = crate::config::endpoint::Params::builder()
176 .region("us-east-1".to_string())
177 .use_fips(true)
178 .build()
179 .expect("invalid params");
180 let resolver = crate::config::endpoint::DefaultResolver::new();
181 let endpoint = resolver.resolve_endpoint(¶ms);
182 let endpoint = endpoint.expect("Expected valid endpoint: https://codecatalyst-fips.global.api.aws");
183 assert_eq!(
184 endpoint,
185 ::aws_smithy_types::endpoint::Endpoint::builder()
186 .url("https://codecatalyst-fips.global.api.aws")
187 .build()
188 );
189 }
190}
191
192pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
194 fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
196
197 fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
201 where
202 Self: Sized + 'static,
203 {
204 ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
205 }
206}
207
208#[derive(Debug)]
209struct DowncastParams<T>(T);
210impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
211where
212 T: ResolveEndpoint,
213{
214 fn resolve_endpoint<'a>(
215 &'a self,
216 params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
217 ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
218 let ep = match params.get::<crate::config::endpoint::Params>() {
219 Some(params) => self.0.resolve_endpoint(params),
220 None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
221 };
222 ep
223 }
224}
225
226#[derive(Debug, Default)]
228pub struct DefaultResolver {
229 partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
230}
231
232impl DefaultResolver {
233 pub fn new() -> Self {
235 Self {
236 partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
237 }
238 }
239
240 fn resolve_endpoint(
241 &self,
242 params: &crate::config::endpoint::Params,
243 ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
244 let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
245 Ok(
246 crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
247 .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
248 )
249 }
250}
251
252impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
253 fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'_> {
254 ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
255 }
256}
257
258#[non_exhaustive]
259#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
260pub struct Params {
262 pub(crate) use_fips: bool,
264 pub(crate) region: ::std::option::Option<::std::string::String>,
266 pub(crate) endpoint: ::std::option::Option<::std::string::String>,
268}
269impl Params {
270 pub fn builder() -> crate::config::endpoint::ParamsBuilder {
272 crate::config::endpoint::ParamsBuilder::default()
273 }
274 pub fn use_fips(&self) -> ::std::option::Option<bool> {
276 Some(self.use_fips)
277 }
278 pub fn region(&self) -> ::std::option::Option<&str> {
280 self.region.as_deref()
281 }
282 pub fn endpoint(&self) -> ::std::option::Option<&str> {
284 self.endpoint.as_deref()
285 }
286}
287
288#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
290pub struct ParamsBuilder {
291 use_fips: ::std::option::Option<bool>,
292 region: ::std::option::Option<::std::string::String>,
293 endpoint: ::std::option::Option<::std::string::String>,
294}
295impl ParamsBuilder {
296 pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
298 if let Some(region) = &self.region {
299 if !crate::endpoint_lib::host::is_valid_host_label(
300 region.as_ref() as &str,
301 true,
302 &mut crate::endpoint_lib::diagnostic::DiagnosticCollector::new(),
303 ) {
304 return Err(crate::config::endpoint::InvalidParams::invalid_value(
305 "region",
306 "must be a valid host label",
307 ));
308 }
309 };
310 Ok(
311 #[allow(clippy::unnecessary_lazy_evaluations)]
312 crate::config::endpoint::Params {
313 use_fips: self
314 .use_fips
315 .or_else(|| Some(false))
316 .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
317 region: self.region,
318 endpoint: self.endpoint,
319 },
320 )
321 }
322 pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
327 self.use_fips = Some(value.into());
328 self
329 }
330
331 pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
336 self.use_fips = param;
337 self
338 }
339 pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
343 self.region = Some(value.into());
344 self
345 }
346
347 pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
351 self.region = param;
352 self
353 }
354 pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
358 self.endpoint = Some(value.into());
359 self
360 }
361
362 pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
366 self.endpoint = param;
367 self
368 }
369}
370
371#[derive(Debug)]
373pub struct InvalidParams {
374 field: std::borrow::Cow<'static, str>,
375 kind: InvalidParamsErrorKind,
376}
377
378#[derive(Debug)]
380enum InvalidParamsErrorKind {
381 MissingField,
382 InvalidValue { message: &'static str },
383}
384
385impl InvalidParams {
386 #[allow(dead_code)]
387 fn missing(field: &'static str) -> Self {
388 Self {
389 field: field.into(),
390 kind: InvalidParamsErrorKind::MissingField,
391 }
392 }
393
394 #[allow(dead_code)]
395 fn invalid_value(field: &'static str, message: &'static str) -> Self {
396 Self {
397 field: field.into(),
398 kind: InvalidParamsErrorKind::InvalidValue { message },
399 }
400 }
401}
402
403impl std::fmt::Display for InvalidParams {
404 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
405 match self.kind {
406 InvalidParamsErrorKind::MissingField => write!(f, "a required field was missing: `{}`", self.field),
407 InvalidParamsErrorKind::InvalidValue { message } => write!(f, "invalid value for field: `{}` - {}", self.field, message),
408 }
409 }
410}
411
412impl std::error::Error for InvalidParams {}
413
414mod internals;