aws_sdk_networkflowmonitor/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://example.com".to_string())
14 .use_fips(false)
15 .build()
16 .expect("invalid params");
17 let resolver = crate::config::endpoint::DefaultResolver::new();
18 let endpoint = resolver.resolve_endpoint(¶ms);
19 let endpoint = endpoint.expect("Expected valid endpoint: https://example.com");
20 assert_eq!(
21 endpoint,
22 ::aws_smithy_types::endpoint::Endpoint::builder().url("https://example.com").build()
23 );
24 }
25
26 #[test]
28 fn test_2() {
29 let params = crate::config::endpoint::Params::builder()
30 .endpoint("https://example.com".to_string())
31 .use_fips(true)
32 .build()
33 .expect("invalid params");
34 let resolver = crate::config::endpoint::DefaultResolver::new();
35 let endpoint = resolver.resolve_endpoint(¶ms);
36 let error = endpoint
37 .expect_err("expected error: Invalid Configuration: FIPS and custom endpoint are not supported [For custom endpoint with fips enabled]");
38 assert_eq!(format!("{}", error), "Invalid Configuration: FIPS and custom endpoint are not supported")
39 }
40
41 #[test]
43 fn test_3() {
44 let params = crate::config::endpoint::Params::builder()
45 .region("us-east-1".to_string())
46 .use_fips(true)
47 .build()
48 .expect("invalid params");
49 let resolver = crate::config::endpoint::DefaultResolver::new();
50 let endpoint = resolver.resolve_endpoint(¶ms);
51 let endpoint = endpoint.expect("Expected valid endpoint: https://networkflowmonitor-fips.us-east-1.api.aws");
52 assert_eq!(
53 endpoint,
54 ::aws_smithy_types::endpoint::Endpoint::builder()
55 .url("https://networkflowmonitor-fips.us-east-1.api.aws")
56 .build()
57 );
58 }
59
60 #[test]
62 fn test_4() {
63 let params = crate::config::endpoint::Params::builder()
64 .region("us-east-1".to_string())
65 .use_fips(false)
66 .build()
67 .expect("invalid params");
68 let resolver = crate::config::endpoint::DefaultResolver::new();
69 let endpoint = resolver.resolve_endpoint(¶ms);
70 let endpoint = endpoint.expect("Expected valid endpoint: https://networkflowmonitor.us-east-1.api.aws");
71 assert_eq!(
72 endpoint,
73 ::aws_smithy_types::endpoint::Endpoint::builder()
74 .url("https://networkflowmonitor.us-east-1.api.aws")
75 .build()
76 );
77 }
78
79 #[test]
81 fn test_5() {
82 let params = crate::config::endpoint::Params::builder()
83 .region("cn-northwest-1".to_string())
84 .use_fips(true)
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://networkflowmonitor-fips.cn-northwest-1.api.amazonwebservices.com.cn");
90 assert_eq!(
91 endpoint,
92 ::aws_smithy_types::endpoint::Endpoint::builder()
93 .url("https://networkflowmonitor-fips.cn-northwest-1.api.amazonwebservices.com.cn")
94 .build()
95 );
96 }
97
98 #[test]
100 fn test_6() {
101 let params = crate::config::endpoint::Params::builder()
102 .region("cn-northwest-1".to_string())
103 .use_fips(false)
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://networkflowmonitor.cn-northwest-1.api.amazonwebservices.com.cn");
109 assert_eq!(
110 endpoint,
111 ::aws_smithy_types::endpoint::Endpoint::builder()
112 .url("https://networkflowmonitor.cn-northwest-1.api.amazonwebservices.com.cn")
113 .build()
114 );
115 }
116
117 #[test]
119 fn test_7() {
120 let params = crate::config::endpoint::Params::builder()
121 .region("us-gov-west-1".to_string())
122 .use_fips(true)
123 .build()
124 .expect("invalid params");
125 let resolver = crate::config::endpoint::DefaultResolver::new();
126 let endpoint = resolver.resolve_endpoint(¶ms);
127 let endpoint = endpoint.expect("Expected valid endpoint: https://networkflowmonitor-fips.us-gov-west-1.api.aws");
128 assert_eq!(
129 endpoint,
130 ::aws_smithy_types::endpoint::Endpoint::builder()
131 .url("https://networkflowmonitor-fips.us-gov-west-1.api.aws")
132 .build()
133 );
134 }
135
136 #[test]
138 fn test_8() {
139 let params = crate::config::endpoint::Params::builder()
140 .region("us-gov-west-1".to_string())
141 .use_fips(false)
142 .build()
143 .expect("invalid params");
144 let resolver = crate::config::endpoint::DefaultResolver::new();
145 let endpoint = resolver.resolve_endpoint(¶ms);
146 let endpoint = endpoint.expect("Expected valid endpoint: https://networkflowmonitor.us-gov-west-1.api.aws");
147 assert_eq!(
148 endpoint,
149 ::aws_smithy_types::endpoint::Endpoint::builder()
150 .url("https://networkflowmonitor.us-gov-west-1.api.aws")
151 .build()
152 );
153 }
154
155 #[test]
157 fn test_9() {
158 let params = crate::config::endpoint::Params::builder().build().expect("invalid params");
159 let resolver = crate::config::endpoint::DefaultResolver::new();
160 let endpoint = resolver.resolve_endpoint(¶ms);
161 let error = endpoint.expect_err("expected error: Invalid Configuration: Missing Region [Missing region]");
162 assert_eq!(format!("{}", error), "Invalid Configuration: Missing Region")
163 }
164}
165
166pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
168 fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>;
170
171 fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver
175 where
176 Self: Sized + 'static,
177 {
178 ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self))
179 }
180}
181
182#[derive(Debug)]
183struct DowncastParams<T>(T);
184impl<T> ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams<T>
185where
186 T: ResolveEndpoint,
187{
188 fn resolve_endpoint<'a>(
189 &'a self,
190 params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams,
191 ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> {
192 let ep = match params.get::<crate::config::endpoint::Params>() {
193 Some(params) => self.0.resolve_endpoint(params),
194 None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())),
195 };
196 ep
197 }
198}
199
200#[derive(Debug, Default)]
202pub struct DefaultResolver {
203 partition_resolver: crate::endpoint_lib::partition::PartitionResolver,
204}
205
206impl DefaultResolver {
207 pub fn new() -> Self {
209 Self {
210 partition_resolver: crate::endpoint_lib::DEFAULT_PARTITION_RESOLVER.clone(),
211 }
212 }
213
214 fn resolve_endpoint(
215 &self,
216 params: &crate::config::endpoint::Params,
217 ) -> ::std::result::Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> {
218 let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
219 Ok(
220 crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver)
221 .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?,
222 )
223 }
224}
225
226impl crate::config::endpoint::ResolveEndpoint for DefaultResolver {
227 fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'_> {
228 ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params))
229 }
230}
231
232#[non_exhaustive]
233#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
234pub struct Params {
236 pub(crate) use_fips: bool,
238 pub(crate) endpoint: ::std::option::Option<::std::string::String>,
240 pub(crate) region: ::std::option::Option<::std::string::String>,
242}
243impl Params {
244 pub fn builder() -> crate::config::endpoint::ParamsBuilder {
246 crate::config::endpoint::ParamsBuilder::default()
247 }
248 pub fn use_fips(&self) -> ::std::option::Option<bool> {
250 Some(self.use_fips)
251 }
252 pub fn endpoint(&self) -> ::std::option::Option<&str> {
254 self.endpoint.as_deref()
255 }
256 pub fn region(&self) -> ::std::option::Option<&str> {
258 self.region.as_deref()
259 }
260}
261
262#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
264pub struct ParamsBuilder {
265 use_fips: ::std::option::Option<bool>,
266 endpoint: ::std::option::Option<::std::string::String>,
267 region: ::std::option::Option<::std::string::String>,
268}
269impl ParamsBuilder {
270 pub fn build(self) -> ::std::result::Result<crate::config::endpoint::Params, crate::config::endpoint::InvalidParams> {
272 Ok(
273 #[allow(clippy::unnecessary_lazy_evaluations)]
274 crate::config::endpoint::Params {
275 use_fips: self
276 .use_fips
277 .or_else(|| Some(false))
278 .ok_or_else(|| crate::config::endpoint::InvalidParams::missing("use_fips"))?,
279 endpoint: self.endpoint,
280 region: self.region,
281 },
282 )
283 }
284 pub fn use_fips(mut self, value: impl Into<bool>) -> Self {
289 self.use_fips = Some(value.into());
290 self
291 }
292
293 pub fn set_use_fips(mut self, param: Option<bool>) -> Self {
298 self.use_fips = param;
299 self
300 }
301 pub fn endpoint(mut self, value: impl Into<::std::string::String>) -> Self {
305 self.endpoint = Some(value.into());
306 self
307 }
308
309 pub fn set_endpoint(mut self, param: Option<::std::string::String>) -> Self {
313 self.endpoint = param;
314 self
315 }
316 pub fn region(mut self, value: impl Into<::std::string::String>) -> Self {
320 self.region = Some(value.into());
321 self
322 }
323
324 pub fn set_region(mut self, param: Option<::std::string::String>) -> Self {
328 self.region = param;
329 self
330 }
331}
332
333#[derive(Debug)]
335pub struct InvalidParams {
336 field: std::borrow::Cow<'static, str>,
337}
338
339impl InvalidParams {
340 #[allow(dead_code)]
341 fn missing(field: &'static str) -> Self {
342 Self { field: field.into() }
343 }
344}
345
346impl std::fmt::Display for InvalidParams {
347 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
348 write!(f, "a required field was missing: `{}`", self.field)
349 }
350}
351
352impl std::error::Error for InvalidParams {}
353
354mod internals;