Skip to content

Commit afd0313

Browse files
author
Jon Gjengset
committed
Make AWS middleware example match real impl
The real AWS middleware in `aws-inlineable` has changed, but the example hasn't changed to follow suit.
1 parent b7a8eb5 commit afd0313

File tree

1 file changed

+60
-20
lines changed

1 file changed

+60
-20
lines changed

codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/client/FluentClientDecorator.kt

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -184,37 +184,77 @@ class GenericFluentClient(codegenContext: CodegenContext) : FluentClientCustomiz
184184
// Ignored as otherwise we'd need to pull in all these dev-dependencies.
185185
/// ```rust,ignore
186186
/// use aws_endpoint::AwsEndpointStage;
187+
/// use aws_http::auth::CredentialsStage;
188+
/// use aws_http::recursion_detection::RecursionDetectionStage;
187189
/// use aws_http::user_agent::UserAgentStage;
188190
/// use aws_sig_auth::middleware::SigV4SigningStage;
189191
/// use aws_sig_auth::signer::SigV4Signer;
190-
/// use aws_smithy_http_tower::map_request::MapRequestLayer;
191-
/// use tower::layer::util::Stack;
192+
/// use aws_smithy_client::retry::Config as RetryConfig;
193+
/// use aws_smithy_http_tower::map_request::{AsyncMapRequestLayer, MapRequestLayer};
194+
/// use std::fmt::Debug;
195+
/// use tower::layer::util::{Identity, Stack};
192196
/// use tower::ServiceBuilder;
193197
///
194-
/// type AwsMiddlewareStack =
195-
/// Stack<MapRequestLayer<SigV4SigningStage>,
196-
/// Stack<MapRequestLayer<UserAgentStage>,
197-
/// MapRequestLayer<AwsEndpointStage>>>,
198+
/// type AwsMiddlewareStack = Stack<
199+
/// MapRequestLayer<RecursionDetectionStage>,
200+
/// Stack<
201+
/// MapRequestLayer<SigV4SigningStage>,
202+
/// Stack<
203+
/// AsyncMapRequestLayer<CredentialsStage>,
204+
/// Stack<
205+
/// MapRequestLayer<UserAgentStage>,
206+
/// Stack<MapRequestLayer<AwsEndpointStage>, Identity>,
207+
/// >,
208+
/// >,
209+
/// >,
210+
/// >;
198211
///
199-
/// ##[derive(Debug, Default)]
212+
/// /// AWS Middleware Stack
213+
/// ///
214+
/// /// This implements the middleware stack for this service. It will:
215+
/// /// 1. Load credentials asynchronously into the property bag
216+
/// /// 2. Sign the request with SigV4
217+
/// /// 3. Resolve an Endpoint for the request
218+
/// /// 4. Add a user agent to the request
219+
/// #[derive(Debug, Default, Clone)]
220+
/// #[non_exhaustive]
200221
/// pub struct AwsMiddleware;
222+
///
223+
/// impl AwsMiddleware {
224+
/// /// Create a new `AwsMiddleware` stack
225+
/// ///
226+
/// /// Note: `AwsMiddleware` holds no state.
227+
/// pub fn new() -> Self {
228+
/// AwsMiddleware::default()
229+
/// }
230+
/// }
231+
///
232+
/// // define the middleware stack in a non-generic location to reduce code bloat.
233+
/// fn base() -> ServiceBuilder<AwsMiddlewareStack> {
234+
/// let credential_provider = AsyncMapRequestLayer::for_mapper(CredentialsStage::new());
235+
/// let signer = MapRequestLayer::for_mapper(SigV4SigningStage::new(SigV4Signer::new()));
236+
/// let endpoint_resolver = MapRequestLayer::for_mapper(AwsEndpointStage);
237+
/// let user_agent = MapRequestLayer::for_mapper(UserAgentStage::new());
238+
/// let recursion_detection = MapRequestLayer::for_mapper(RecursionDetectionStage::new());
239+
/// // These layers can be considered as occurring in order, that is:
240+
/// // 1. Resolve an endpoint
241+
/// // 2. Add a user agent
242+
/// // 3. Acquire credentials
243+
/// // 4. Sign with credentials
244+
/// // (5. Dispatch over the wire)
245+
/// ServiceBuilder::new()
246+
/// .layer(endpoint_resolver)
247+
/// .layer(user_agent)
248+
/// .layer(credential_provider)
249+
/// .layer(signer)
250+
/// .layer(recursion_detection)
251+
/// }
252+
///
201253
/// impl<S> tower::Layer<S> for AwsMiddleware {
202254
/// type Service = <AwsMiddlewareStack as tower::Layer<S>>::Service;
203255
///
204256
/// fn layer(&self, inner: S) -> Self::Service {
205-
/// let signer = MapRequestLayer::for_mapper(SigV4SigningStage::new(SigV4Signer::new())); _signer: MapRequestLaye
206-
/// let endpoint_resolver = MapRequestLayer::for_mapper(AwsEndpointStage); _endpoint_resolver: MapRequestLayer<Aw
207-
/// let user_agent = MapRequestLayer::for_mapper(UserAgentStage::new()); _user_agent: MapRequestLayer<UserAgentSt
208-
/// // These layers can be considered as occurring in order, that is:
209-
/// // 1. Resolve an endpoint
210-
/// // 2. Add a user agent
211-
/// // 3. Sign
212-
/// // (4. Dispatch over the wire)
213-
/// ServiceBuilder::new() _ServiceBuilder<Identity>
214-
/// .layer(endpoint_resolver) _ServiceBuilder<Stack<MapRequestLayer<_>, _>>
215-
/// .layer(user_agent) _ServiceBuilder<Stack<MapRequestLayer<_>, _>>
216-
/// .layer(signer) _ServiceBuilder<Stack<MapRequestLayer<_>, _>>
217-
/// .service(inner)
257+
/// base().service(inner)
218258
/// }
219259
/// }
220260
/// ```

0 commit comments

Comments
 (0)