1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
pub use aws_smithy_client::retry::Config as RetryConfig;
use aws_endpoint::AwsEndpointStage;
use aws_http::auth::CredentialsStage;
use aws_http::user_agent::UserAgentStage;
use aws_sig_auth::middleware::SigV4SigningStage;
use aws_sig_auth::signer::SigV4Signer;
pub use aws_smithy_http::result::{SdkError, SdkSuccess};
use aws_smithy_http_tower::map_request::{AsyncMapRequestLayer, MapRequestLayer};
use std::fmt::Debug;
use tower::layer::util::Stack;
use tower::ServiceBuilder;
type AwsMiddlewareStack = Stack<
MapRequestLayer<SigV4SigningStage>,
Stack<
AsyncMapRequestLayer<CredentialsStage>,
Stack<MapRequestLayer<UserAgentStage>, MapRequestLayer<AwsEndpointStage>>,
>,
>;
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct AwsMiddleware;
impl<S> tower::Layer<S> for AwsMiddleware {
type Service = <AwsMiddlewareStack as tower::Layer<S>>::Service;
fn layer(&self, inner: S) -> Self::Service {
let credential_provider = AsyncMapRequestLayer::for_mapper(CredentialsStage::new());
let signer = MapRequestLayer::for_mapper(SigV4SigningStage::new(SigV4Signer::new()));
let endpoint_resolver = MapRequestLayer::for_mapper(AwsEndpointStage);
let user_agent = MapRequestLayer::for_mapper(UserAgentStage::new());
ServiceBuilder::new()
.layer(endpoint_resolver)
.layer(user_agent)
.layer(credential_provider)
.layer(signer)
.service(inner)
}
}
pub type Client<C> = aws_smithy_client::Client<C, AwsMiddleware>;
#[doc(inline)]
pub use aws_smithy_client::erase::DynConnector;
pub type StandardClient = Client<DynConnector>;
#[doc(inline)]
pub use aws_smithy_client::bounds::SmithyConnector;
pub type Builder<C> = aws_smithy_client::Builder<C, AwsMiddleware>;
#[cfg(any(feature = "native-tls", feature = "rustls"))]
pub fn https() -> StandardClient {
#[cfg(feature = "rustls")]
let with_https = |b: Builder<_>| b.rustls();
#[cfg(not(feature = "rustls"))]
let with_https = |b: Builder<_>| b.native_tls();
with_https(aws_smithy_client::Builder::new())
.build()
.into_dyn_connector()
}
mod static_tests {
#[cfg(any(feature = "rustls", feature = "native-tls"))]
#[allow(dead_code)]
fn construct_default_client() {
let c = crate::Client::https();
fn is_send_sync<T: Send + Sync>(_c: T) {}
is_send_sync(c);
}
}
#[cfg(test)]
mod tests {
#[cfg(any(feature = "rustls", feature = "native-tls"))]
#[test]
fn client_debug_includes_retry_info() {
let client = crate::Client::https();
let s = format!("{:?}", client);
assert!(s.contains("quota_available"));
}
}