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