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
use aws_endpoint::AwsAuthStage;
use aws_http::auth::CredentialsStage;
use aws_http::recursion_detection::RecursionDetectionStage;
use aws_http::user_agent::UserAgentStage;
use aws_sig_auth::middleware::SigV4SigningStage;
use aws_sig_auth::signer::SigV4Signer;
use aws_smithy_http::endpoint::middleware::SmithyEndpointStage;
use aws_smithy_http_tower::map_request::{AsyncMapRequestLayer, MapRequestLayer};
use std::fmt::Debug;
use tower::ServiceBuilder;
macro_rules! stack_type {
($first: ty, $($rest:ty),+) => {
tower::layer::util::Stack<$first, stack_type!($($rest),+)>
};
($only: ty) => {
tower::layer::util::Stack<$only, tower::layer::util::Identity>
}
}
type DefaultMiddlewareStack = stack_type!(
MapRequestLayer<RecursionDetectionStage>,
MapRequestLayer<SigV4SigningStage>,
AsyncMapRequestLayer<CredentialsStage>,
MapRequestLayer<UserAgentStage>,
MapRequestLayer<AwsAuthStage>,
MapRequestLayer<SmithyEndpointStage>
);
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct DefaultMiddleware;
impl DefaultMiddleware {
pub fn new() -> Self {
DefaultMiddleware::default()
}
}
fn base() -> ServiceBuilder<DefaultMiddlewareStack> {
let credential_provider = AsyncMapRequestLayer::for_mapper(CredentialsStage::new());
let signer = MapRequestLayer::for_mapper(SigV4SigningStage::new(SigV4Signer::new()));
let endpoint_stage = MapRequestLayer::for_mapper(SmithyEndpointStage::new());
let auth_stage = MapRequestLayer::for_mapper(AwsAuthStage);
let user_agent = MapRequestLayer::for_mapper(UserAgentStage::new());
let recursion_detection = MapRequestLayer::for_mapper(RecursionDetectionStage::new());
ServiceBuilder::new()
.layer(endpoint_stage)
.layer(auth_stage)
.layer(user_agent)
.layer(credential_provider)
.layer(signer)
.layer(recursion_detection)
}
impl<S> tower::Layer<S> for DefaultMiddleware {
type Service = <DefaultMiddlewareStack as tower::Layer<S>>::Service;
fn layer(&self, inner: S) -> Self::Service {
base().service(inner)
}
}