aws_sdk_eksauth/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
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 #[test]
33 fn test_1() {
34 let params = crate::config::endpoint::Params::builder()
35 .region("us-east-1".to_string())
36 .use_fips(true)
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://eks-auth-fips.us-east-1.api.aws");
42 assert_eq!(
43 endpoint,
44 ::aws_smithy_types::endpoint::Endpoint::builder()
45 .url("https://eks-auth-fips.us-east-1.api.aws")
46 .build()
47 );
48 }
49
50 #[test]
52 fn test_2() {
53 let params = crate::config::endpoint::Params::builder()
54 .region("us-east-1".to_string())
55 .use_fips(false)
56 .build()
57 .expect("invalid params");
58 let resolver = crate::config::endpoint::DefaultResolver::new();
59 let endpoint = resolver.resolve_endpoint(¶ms);
60 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth.us-east-1.api.aws");
61 assert_eq!(
62 endpoint,
63 ::aws_smithy_types::endpoint::Endpoint::builder()
64 .url("https://eks-auth.us-east-1.api.aws")
65 .build()
66 );
67 }
68
69 #[test]
71 fn test_3() {
72 let params = crate::config::endpoint::Params::builder()
73 .region("cn-north-1".to_string())
74 .use_fips(true)
75 .build()
76 .expect("invalid params");
77 let resolver = crate::config::endpoint::DefaultResolver::new();
78 let endpoint = resolver.resolve_endpoint(¶ms);
79 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth-fips.cn-north-1.api.amazonwebservices.com.cn");
80 assert_eq!(
81 endpoint,
82 ::aws_smithy_types::endpoint::Endpoint::builder()
83 .url("https://eks-auth-fips.cn-north-1.api.amazonwebservices.com.cn")
84 .build()
85 );
86 }
87
88 #[test]
90 fn test_4() {
91 let params = crate::config::endpoint::Params::builder()
92 .region("cn-north-1".to_string())
93 .use_fips(false)
94 .build()
95 .expect("invalid params");
96 let resolver = crate::config::endpoint::DefaultResolver::new();
97 let endpoint = resolver.resolve_endpoint(¶ms);
98 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth.cn-north-1.api.amazonwebservices.com.cn");
99 assert_eq!(
100 endpoint,
101 ::aws_smithy_types::endpoint::Endpoint::builder()
102 .url("https://eks-auth.cn-north-1.api.amazonwebservices.com.cn")
103 .build()
104 );
105 }
106
107 #[test]
109 fn test_5() {
110 let params = crate::config::endpoint::Params::builder()
111 .region("us-gov-east-1".to_string())
112 .use_fips(true)
113 .build()
114 .expect("invalid params");
115 let resolver = crate::config::endpoint::DefaultResolver::new();
116 let endpoint = resolver.resolve_endpoint(¶ms);
117 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth-fips.us-gov-east-1.api.aws");
118 assert_eq!(
119 endpoint,
120 ::aws_smithy_types::endpoint::Endpoint::builder()
121 .url("https://eks-auth-fips.us-gov-east-1.api.aws")
122 .build()
123 );
124 }
125
126 #[test]
128 fn test_6() {
129 let params = crate::config::endpoint::Params::builder()
130 .region("us-gov-east-1".to_string())
131 .use_fips(false)
132 .build()
133 .expect("invalid params");
134 let resolver = crate::config::endpoint::DefaultResolver::new();
135 let endpoint = resolver.resolve_endpoint(¶ms);
136 let endpoint = endpoint.expect("Expected valid endpoint: https://eks-auth.us-gov-east-1.api.aws");
137 assert_eq!(
138 endpoint,
139 ::aws_smithy_types::endpoint::Endpoint::builder()
140 .url("https://eks-auth.us-gov-east-1.api.aws")
141 .build()
142 );
143 }
144
145 #[test]
147 fn test_7() {
148 let params = crate::config::endpoint::Params::builder()
149 .region("us-east-1".to_string())
150 .use_fips(false)
151 .endpoint("https://example.com".to_string())
152 .build()
153 .expect("invalid params");
154 let resolver = crate::config::endpoint::DefaultResolver::new();
155 let endpoint = resolver.resolve_endpoint(¶ms);
156 let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
157 assert_eq!(
158 endpoint,
159 ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
160 );
161 }
162
163 #[test]
165 fn test_8() {
166 let params = crate::config::endpoint::Params::builder()
167 .use_fips(false)
168 .endpoint("https://example.com".to_string())
169 .build()
170 .expect("invalid params");
171 let resolver = crate::config::endpoint::DefaultResolver::new();
172 let endpoint = resolver.resolve_endpoint(¶ms);
173 let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
174 assert_eq!(
175 endpoint,
176 ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
177 );
178 }
179
180 #[test]
182 fn test_9() {
183 let params = crate::config::endpoint::Params::builder()
184 .region("us-east-1".to_string())
185 .use_fips(true)
186 .endpoint("https://example.com".to_string())
187 .build()
188 .expect("invalid params");
189 let resolver = crate::config::endpoint::DefaultResolver::new();
190 let endpoint = resolver.resolve_endpoint(¶ms);
191 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]");
192 assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
193 }
194
195 #[test]
197 fn test_10() {
198 let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
199 let resolver = crate::config::endpoint::DefaultResolver::new();
200 let endpoint = resolver.resolve_endpoint(¶ms);
201 let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
202 assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
203 }
204}
205
206pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
208 fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
210
211 fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
215 where
216 Self: Sized + 'static,
217 {
218 ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
219 }
220}
221
222#[derive(Debug)]
223struct DowncastParams<T>(T);
224impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
225where
226 T: ResolveEndpoint,
227{
228 fn resolve_endpoint<'a>(
229 &'a self,
230 params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
231 ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
232 let ep = match params.get::<crate::config::endpoint::Params>() {
233 Some(params) => self.0.resolve_endpoint(params),
234 None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
235 };
236 ep
237 }
238}
239
240#[derive(Debug, Default)]
242pub struct DefaultResolver {
243 partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
244}
245
246impl DefaultResolver {
247 pub fn new() -> Self {
249 Self {
250 partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
251 }
252 }
253
254 fn resolve_endpoint(
255 &self,
256 params: &crate::config::endpoint::Params,
257 ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
258 let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
259 Ok(
260 crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
261 .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
262 )
263 }
264}
265
266impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
267 fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'_> {
268 ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
269 }
270}
271
272#[non_exhaustive]
273#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
274pub struct Params {
276 pub(crate) region: ::std::option::Option<::std::string::String>,
278 pub(crate) use_fips: bool,
280 pub(crate) endpoint: ::std::option::Option<::std::string::String>,
282}
283impl Params {
284 pub fn builder() -> crate::config::endpoint::ParamsBuilder {
286 crate::config::endpoint::ParamsBuilder::default()
287 }
288 pub fn region(&self) -> ::std::option::Option<&str> {
290 self.region.as_deref()
291 }
292 pub fn use_fips(&self) -> ::std::option::Option<bool> {
294 Some(self.use_fips)
295 }
296 pub fn endpoint(&self) -> ::std::option::Option<&str> {
298 self.endpoint.as_deref()
299 }
300}
301
302#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
304pub struct ParamsBuilder {
305 region: ::std::option::Option<::std::string::String>,
306 use_fips: ::std::option::Option<bool>,
307 endpoint: ::std::option::Option<::std::string::String>,
308}
309impl ParamsBuilder {
310 pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
312 if let Some(region) = &self.region {
313 if !crate::endpoint_lib::host::is_valid_host_label(
314 region.as_ref() as &str,
315 true,
316 &mut crate::endpoint_lib::diagnostic::DiagnosticCollector::new(),
317 ) {
318 return Err(crate::config::endpoint::InvalidParams::invalid_value(
319 "region",
320 "must be a valid host label",
321 ));
322 }
323 };
324 Ok(
325 #[allow(clippy::unnecessary_lazy_evaluations)]
326 crate::config::endpoint::Params {
327 region: self.region,
328 use_fips: self
329 .use_fips
330 .or_else(|| Some(false))
331 .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
332 endpoint: self.endpoint,
333 },
334 )
335 }
336 pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
340 self.region = Some(value.into());
341 self
342 }
343
344 pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
348 self.region = param;
349 self
350 }
351 pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
356 self.use_fips = Some(value.into());
357 self
358 }
359
360 pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
365 self.use_fips = param;
366 self
367 }
368 pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
372 self.endpoint = Some(value.into());
373 self
374 }
375
376 pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
380 self.endpoint = param;
381 self
382 }
383}
384
385#[derive(Debug)]
387pub struct InvalidParams {
388 field: std::borrow::Cow<'static, str>,
389 kind: InvalidParamsErrorKind,
390}
391
392#[derive(Debug)]
394enum InvalidParamsErrorKind {
395 MissingField,
396 InvalidValue { message: &'static str },
397}
398
399impl InvalidParams {
400 #[allow(dead_code)]
401 fn missing(field: &'static str) -> Self {
402 Self {
403 field: field.into(),
404 kind: InvalidParamsErrorKind::MissingField,
405 }
406 }
407
408 #[allow(dead_code)]
409 fn invalid_value(field: &'static str, message: &'static str) -> Self {
410 Self {
411 field: field.into(),
412 kind: InvalidParamsErrorKind::InvalidValue { message },
413 }
414 }
415}
416
417impl std::fmt::Display for InvalidParams {
418 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
419 match self.kind {
420 InvalidParamsErrorKind::MissingField => write!(f, "a required field was missing: `{}`", self.field),
421 InvalidParamsErrorKind::InvalidValue { message } => write!(f, "invalid value for field: `{}` - {}", self.field, message),
422 }
423 }
424}
425
426impl std::error::Error for InvalidParams {}
427
428mod internals;