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