From 6e16e2ba82453c077e2053b0a5c76ac960ce121d Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 13 Dec 2021 13:07:10 -0500 Subject: [PATCH] remove aws-hyper (#959) * Replace generated code references to AwsMiddleware from hyper with inline dependency * remove usages of aws-hyper * RIP aws-hyper * rename AwsMiddleware to default Middleware * Delete unused aws-hyper deps * Update changelog * Update RFC * Add deprecation note to aws-hyper --- CHANGELOG.next.toml | 6 ++ aws/rust-runtime/aws-config/Cargo.toml | 7 +- .../src/profile/credentials/exec.rs | 4 +- aws/rust-runtime/aws-config/src/sts.rs | 6 +- .../aws-config/src/sts/assume_role.rs | 6 +- .../aws-config/src/web_identity_token.rs | 6 +- aws/rust-runtime/aws-hyper/Cargo.toml | 23 +----- aws/rust-runtime/aws-hyper/README.md | 5 +- aws/rust-runtime/aws-hyper/src/lib.rs | 68 ++--------------- aws/rust-runtime/aws-inlineable/Cargo.toml | 6 ++ aws/rust-runtime/aws-inlineable/src/lib.rs | 3 + .../aws-inlineable/src/middleware.rs | 73 +++++++++++++++++++ .../tests/middleware_e2e_test.rs} | 4 +- .../smithy/rustsdk/AwsEndpointDecorator.kt | 7 +- .../rustsdk/AwsFluentClientDecorator.kt | 49 +++++++------ .../smithy/rustsdk/AwsPresigningDecorator.kt | 5 +- .../smithy/rustsdk/AwsRuntimeDependency.kt | 12 +++ .../amazon/smithy/rustsdk/InlineDependency.kt | 5 +- aws/sdk/examples/dynamodb/Cargo.toml | 1 - aws/sdk/examples/dynamodb/src/bin/crud.rs | 4 +- aws/sdk/examples/dynamodb/src/bin/movies.rs | 4 +- aws/sdk/examples/kms/Cargo.toml | 1 - aws/sdk/examples/secretsmanager/Cargo.toml | 1 - aws/sdk/integration-tests/dynamodb/Cargo.toml | 1 - .../dynamodb/tests/movies.rs | 4 +- aws/sdk/integration-tests/glacier/Cargo.toml | 1 - aws/sdk/integration-tests/iam/Cargo.toml | 1 - aws/sdk/integration-tests/kms/Cargo.toml | 1 - .../kms/tests/integration.rs | 4 +- aws/sdk/integration-tests/lambda/Cargo.toml | 1 - aws/sdk/integration-tests/polly/Cargo.toml | 1 - .../integration-tests/qldbsession/Cargo.toml | 1 - .../qldbsession/tests/integration.rs | 4 +- aws/sdk/integration-tests/s3/Cargo.toml | 1 - .../s3/tests/naughty-string-metadata.rs | 4 +- .../integration-tests/s3/tests/signing-it.rs | 4 +- .../integration-tests/s3control/Cargo.toml | 1 - .../s3control/tests/signing-it.rs | 4 +- aws/sdk/integration-tests/sts/Cargo.toml | 1 - .../transcribestreaming/Cargo.toml | 1 - .../rust/codegen/rustlang/CargoDependency.kt | 1 + .../generators/FluentClientDecorator.kt | 68 +++++++++-------- .../rfc0006_service_specific_middleware.md | 10 +-- 43 files changed, 219 insertions(+), 201 deletions(-) create mode 100644 aws/rust-runtime/aws-inlineable/src/middleware.rs rename aws/rust-runtime/{aws-hyper/tests/e2e_test.rs => aws-inlineable/tests/middleware_e2e_test.rs} (97%) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 68819f058..8b9835ba6 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -157,3 +157,9 @@ message = "Fixed a bug where certain characters caused a panic during URI encodi meta = { "breaking" = false, "tada" = false, "bug" = true } references = ["smithy-rs#953", "aws-sdk-rust#331"] author = "rcoh" + +[[aws-sdk-rust]] +message = "`aws-hyper::AwsMiddleware` is now generated into generated service clients directly. If you used `aws_hyper::Middleware`, use ::middleware::DefaultMiddleware` instead." +meta = { "breaking" = false, "tada" = false, "bug" = false } +references = ["smithy-rs#959", "smithy-rs#934"] +author = "rcoh" diff --git a/aws/rust-runtime/aws-config/Cargo.toml b/aws/rust-runtime/aws-config/Cargo.toml index 6413162e0..96edf3ae0 100644 --- a/aws/rust-runtime/aws-config/Cargo.toml +++ b/aws/rust-runtime/aws-config/Cargo.toml @@ -14,9 +14,9 @@ profile = ["sts", "web-identity-token", "meta", "environment", "imds", "http-pro meta = ["tokio/sync"] imds = ["profile", "aws-smithy-http/rt-tokio", "aws-smithy-http-tower", "aws-smithy-json", "tower", "aws-http", "meta"] environment = ["meta"] -sts = ["aws-sdk-sts", "aws-hyper"] +sts = ["aws-sdk-sts"] web-identity-token = ["sts", "profile"] -http-provider = ["aws-hyper", "aws-smithy-json", "aws-smithy-http/rt-tokio", "tower", "tokio/sync"] +http-provider = ["aws-smithy-json", "aws-smithy-http/rt-tokio", "tower", "tokio/sync"] tcp-connector = ["tokio/net", "tower"] # SSO is not supported @@ -40,9 +40,6 @@ aws-types = { path = "../../sdk/build/aws-sdk/sdk/aws-types" } tokio = { version = "1", features = ["sync"], optional = true } tracing = { version = "0.1" } -# TODO: remove when middleware stacks are moved inside of clients directly -aws-hyper = { path = "../../sdk/build/aws-sdk/sdk/aws-hyper", optional = true } - # imds aws-http = { path = "../../sdk/build/aws-sdk/sdk/aws-http", optional = true } aws-smithy-http = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http", optional = true } diff --git a/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs b/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs index b4ffc7fb2..b65b11c3e 100644 --- a/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs +++ b/aws/rust-runtime/aws-config/src/profile/credentials/exec.rs @@ -15,7 +15,7 @@ use crate::profile::credentials::ProfileFileError; use crate::provider_config::ProviderConfig; use crate::sts; use crate::web_identity_token::{StaticConfiguration, WebIdentityTokenCredentialsProvider}; -use aws_hyper::AwsMiddleware; +use aws_sdk_sts::middleware::DefaultMiddleware; use aws_smithy_client::erase::DynConnector; use aws_types::credentials::{self, CredentialsError, ProvideCredentials}; use aws_types::os_shim_internal::Fs; @@ -30,7 +30,7 @@ pub struct AssumeRoleProvider { #[derive(Debug)] pub struct ClientConfiguration { - pub(crate) core_client: aws_smithy_client::Client, + pub(crate) core_client: aws_smithy_client::Client, pub(crate) region: Option, } diff --git a/aws/rust-runtime/aws-config/src/sts.rs b/aws/rust-runtime/aws-config/src/sts.rs index 31218576f..e10d0c6e3 100644 --- a/aws/rust-runtime/aws-config/src/sts.rs +++ b/aws/rust-runtime/aws-config/src/sts.rs @@ -10,12 +10,12 @@ mod assume_role; use crate::connector::expect_connector; use crate::provider_config::{HttpSettings, ProviderConfig}; pub use assume_role::{AssumeRoleProvider, AssumeRoleProviderBuilder}; -use aws_hyper::AwsMiddleware; +use aws_sdk_sts::middleware::DefaultMiddleware; use aws_smithy_client::erase::DynConnector; impl ProviderConfig { - pub(crate) fn sdk_client(&self) -> aws_smithy_client::Client { - aws_smithy_client::Builder::<(), AwsMiddleware>::new() + pub(crate) fn sdk_client(&self) -> aws_smithy_client::Client { + aws_smithy_client::Builder::<(), DefaultMiddleware>::new() .connector(expect_connector(self.connector(&HttpSettings::default()))) .sleep_impl(self.sleep()) .build() diff --git a/aws/rust-runtime/aws-config/src/sts/assume_role.rs b/aws/rust-runtime/aws-config/src/sts/assume_role.rs index c981e007d..c65930ff3 100644 --- a/aws/rust-runtime/aws-config/src/sts/assume_role.rs +++ b/aws/rust-runtime/aws-config/src/sts/assume_role.rs @@ -5,8 +5,8 @@ //! Assume credentials for a role through the AWS Security Token Service (STS). -use aws_hyper::AwsMiddleware; use aws_sdk_sts::error::AssumeRoleErrorKind; +use aws_sdk_sts::middleware::DefaultMiddleware; use aws_sdk_sts::operation::AssumeRole; use aws_types::credentials::{ self, future, CredentialsError, ProvideCredentials, SharedCredentialsProvider, @@ -41,7 +41,7 @@ use tracing::Instrument; /// ``` #[derive(Debug)] pub struct AssumeRoleProvider { - sts: aws_smithy_client::Client, + sts: aws_smithy_client::Client, conf: aws_sdk_sts::Config, op: aws_sdk_sts::input::AssumeRoleInput, } @@ -141,7 +141,7 @@ impl AssumeRoleProviderBuilder { }); let client = aws_smithy_client::Builder::new() .connector(conn) - .middleware(AwsMiddleware::new()) + .middleware(DefaultMiddleware::new()) .sleep_impl(default_async_sleep()) .build(); diff --git a/aws/rust-runtime/aws-config/src/web_identity_token.rs b/aws/rust-runtime/aws-config/src/web_identity_token.rs index eb49855db..5cf0fd13a 100644 --- a/aws/rust-runtime/aws-config/src/web_identity_token.rs +++ b/aws/rust-runtime/aws-config/src/web_identity_token.rs @@ -65,7 +65,7 @@ use aws_types::os_shim_internal::{Env, Fs}; use crate::provider_config::ProviderConfig; use crate::sts; -use aws_hyper::AwsMiddleware; +use aws_sdk_sts::middleware::DefaultMiddleware; use aws_smithy_client::erase::DynConnector; use aws_types::credentials::{self, future, CredentialsError, ProvideCredentials}; use std::borrow::Cow; @@ -83,7 +83,7 @@ const ENV_VAR_SESSION_NAME: &str = "AWS_ROLE_SESSION_NAME"; pub struct WebIdentityTokenCredentialsProvider { source: Source, fs: Fs, - client: aws_smithy_client::Client, + client: aws_smithy_client::Client, region: Option, } @@ -223,7 +223,7 @@ impl Builder { async fn load_credentials( fs: &Fs, - client: &aws_smithy_client::Client, + client: &aws_smithy_client::Client, region: &Region, token_file: impl AsRef, role_arn: &str, diff --git a/aws/rust-runtime/aws-hyper/Cargo.toml b/aws/rust-runtime/aws-hyper/Cargo.toml index 1832e8bae..e8ce2bfad 100644 --- a/aws/rust-runtime/aws-hyper/Cargo.toml +++ b/aws/rust-runtime/aws-hyper/Cargo.toml @@ -2,32 +2,11 @@ name = "aws-hyper" version = "0.0.0-smithy-rs-head" authors = ["AWS Rust SDK Team ", "Russell Cohen "] -description = "AWS SDK Tower middleware stack." +description = "This crate has been removed and is deprecated." edition = "2018" license = "Apache-2.0" repository = "https://github.com/awslabs/smithy-rs" -[dependencies] -aws-endpoint = { path = "../aws-endpoint" } -aws-http = { path = "../aws-http" } -aws-sig-auth = { path = "../aws-sig-auth" } -aws-smithy-client = { path = "../../../rust-runtime/aws-smithy-client" } -aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" } -aws-smithy-http-tower = { path = "../../../rust-runtime/aws-smithy-http-tower" } -tower = { version = "0.4.6" } - -[dev-dependencies] -tokio = { version = "1", features = ["full", "test-util"] } -tower-test = "0.4.0" -aws-types = { path = "../aws-types" } -aws-smithy-client = { path = "../../../rust-runtime/aws-smithy-client", features = ["test-util"] } -http = "0.2.5" -bytes = "1.1.0" -aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" } - -[[test]] -name = "e2e_test" - [package.metadata.docs.rs] all-features = true targets = ["x86_64-unknown-linux-gnu"] diff --git a/aws/rust-runtime/aws-hyper/README.md b/aws/rust-runtime/aws-hyper/README.md index c199e404b..ace56e160 100644 --- a/aws/rust-runtime/aws-hyper/README.md +++ b/aws/rust-runtime/aws-hyper/README.md @@ -1,9 +1,6 @@ # AWS Default Middleware -This crate defines the default middleware stack used by AWS services. It also provides a re-export -of `aws_smithy_client::Client` with the middleware type preset. - -_Note:_ this crate will be removed in the future in favor of defining the middlewares directly in the service clients. +This crate has been removed. Middleware is now defined on a per-service basis. This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/awslabs/smithy-rs) code generator. In most cases, it should not be used directly. diff --git a/aws/rust-runtime/aws-hyper/src/lib.rs b/aws/rust-runtime/aws-hyper/src/lib.rs index 1ae70da9f..1b1316221 100644 --- a/aws/rust-runtime/aws-hyper/src/lib.rs +++ b/aws/rust-runtime/aws-hyper/src/lib.rs @@ -3,66 +3,8 @@ * SPDX-License-Identifier: Apache-2.0. */ -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; -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, - Stack< - AsyncMapRequestLayer, - Stack, MapRequestLayer>, - >, ->; - -/// AWS Middleware Stack -/// -/// This implements the default middleware stack used with AWS Services -/// # Examples -/// **Construct a Smithy Client with HTTPS and the AWS Middleware stack**: -/// ```no_run -/// use aws_hyper::AwsMiddleware; -/// use aws_smithy_client::erase::DynConnector; -/// let client = aws_smithy_client::Builder::::dyn_https() -/// .default_async_sleep() -/// .build(); -/// ``` -#[derive(Debug, Default)] -#[non_exhaustive] -pub struct AwsMiddleware; - -impl AwsMiddleware { - pub fn new() -> Self { - AwsMiddleware::default() - } -} -impl tower::Layer for AwsMiddleware { - type Service = >::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()); - // These layers can be considered as occurring in order, that is: - // 1. Resolve an endpoint - // 2. Add a user agent - // 3. Acquire credentials - // 4. Sign with credentials - // (5. Dispatch over the wire) - ServiceBuilder::new() - .layer(endpoint_resolver) - .layer(user_agent) - .layer(credential_provider) - .layer(signer) - .service(inner) - } -} +#![deprecated( + since = "0.3.0", + note = "The functionality of this crate is included in individual AWS services." +)] +//! This crate has been removed. Its functionality has be merged into aws-smithy-client and individual AWS services. diff --git a/aws/rust-runtime/aws-inlineable/Cargo.toml b/aws/rust-runtime/aws-inlineable/Cargo.toml index ee24c69f1..15144abd7 100644 --- a/aws/rust-runtime/aws-inlineable/Cargo.toml +++ b/aws/rust-runtime/aws-inlineable/Cargo.toml @@ -13,7 +13,11 @@ repository = "https://github.com/awslabs/smithy-rs" [dependencies] aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" } +aws-smithy-client = { path = "../../../rust-runtime/aws-smithy-client" } +aws-http = { path = "../aws-http" } +aws-endpoint = { path = "../aws-endpoint" } aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" } +aws-smithy-http-tower= { path = "../../../rust-runtime/aws-smithy-http-tower" } aws-types = { path = "../../rust-runtime/aws-types" } aws-sig-auth = { path = "../../rust-runtime/aws-sig-auth" } http = "0.2.4" @@ -29,6 +33,8 @@ hex = "0.4.3" [dev-dependencies] temp-file = "0.1.6" +aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http", features = ["rt-tokio"] } +aws-smithy-client = { path = "../../../rust-runtime/aws-smithy-client", features = ["test-util"] } [package.metadata.docs.rs] all-features = true diff --git a/aws/rust-runtime/aws-inlineable/src/lib.rs b/aws/rust-runtime/aws-inlineable/src/lib.rs index 439a6dea6..c5b2d26f0 100644 --- a/aws/rust-runtime/aws-inlineable/src/lib.rs +++ b/aws/rust-runtime/aws-inlineable/src/lib.rs @@ -29,3 +29,6 @@ pub mod s3_errors; /// Glacier-specific checksumming behavior pub mod glacier_checksums; + +/// Default middleware stack for AWS services +pub mod middleware; diff --git a/aws/rust-runtime/aws-inlineable/src/middleware.rs b/aws/rust-runtime/aws-inlineable/src/middleware.rs new file mode 100644 index 000000000..ec8b883cf --- /dev/null +++ b/aws/rust-runtime/aws-inlineable/src/middleware.rs @@ -0,0 +1,73 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +//! Base Middleware Stack + +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; +use aws_smithy_http_tower::map_request::{AsyncMapRequestLayer, MapRequestLayer}; +use std::fmt::Debug; +use tower::layer::util::{Identity, Stack}; +use tower::ServiceBuilder; + +type DefaultMiddlewareStack = Stack< + MapRequestLayer, + Stack< + AsyncMapRequestLayer, + Stack, Stack, Identity>>, + >, +>; + +/// AWS Middleware Stack +/// +/// This implements the middleware stack for this service. It will: +/// 1. Load credentials asynchronously into the property bag +/// 2. Sign the request with SigV4 +/// 3. Resolve an Endpoint for the request +/// 4. Add a user agent to the request +#[derive(Debug, Default)] +#[non_exhaustive] +pub struct DefaultMiddleware; + +impl DefaultMiddleware { + /// Create a new `DefaultMiddleware` stack + /// + /// Note: `DefaultMiddleware` holds no state. + pub fn new() -> Self { + DefaultMiddleware::default() + } +} + +// define the middleware stack in a non-generic location to reduce code bloat. +fn base() -> ServiceBuilder { + 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()); + // These layers can be considered as occurring in order, that is: + // 1. Resolve an endpoint + // 2. Add a user agent + // 3. Acquire credentials + // 4. Sign with credentials + // (5. Dispatch over the wire) + ServiceBuilder::new() + .layer(endpoint_resolver) + .layer(user_agent) + .layer(credential_provider) + .layer(signer) +} + +impl tower::Layer for DefaultMiddleware { + type Service = >::Service; + + fn layer(&self, inner: S) -> Self::Service { + base().service(inner) + } +} diff --git a/aws/rust-runtime/aws-hyper/tests/e2e_test.rs b/aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs similarity index 97% rename from aws/rust-runtime/aws-hyper/tests/e2e_test.rs rename to aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs index cec7dafd6..c0f99639a 100644 --- a/aws/rust-runtime/aws-hyper/tests/e2e_test.rs +++ b/aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs @@ -18,8 +18,8 @@ use aws_endpoint::partition::endpoint::{Protocol, SignatureVersion}; use aws_endpoint::set_endpoint_resolver; use aws_http::user_agent::AwsUserAgent; use aws_http::AwsErrorRetryPolicy; -use aws_hyper::AwsMiddleware; use aws_sig_auth::signer::OperationSigningConfig; +use inlineable_aws::middleware::DefaultMiddleware; use aws_smithy_client::test_connection::TestConnection; use aws_smithy_http::body::SdkBody; @@ -33,7 +33,7 @@ use aws_types::region::Region; use aws_types::Credentials; use aws_types::SigningService; -type Client = aws_smithy_client::Client; +type Client = aws_smithy_client::Client; #[derive(Clone)] struct TestOperationParser; diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt index 52fe3005c..eb4d6149c 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt @@ -71,7 +71,7 @@ class AwsEndpointDecorator : RustCodegenDecorator { class EndpointConfigCustomization(private val codegenContext: CodegenContext, private val endpointData: ObjectNode) : ConfigCustomization() { private val runtimeConfig = codegenContext.runtimeConfig - private val resolveAwsEndpoint = runtimeConfig.awsEndpointDependency().asType().copy(name = "ResolveAwsEndpoint") + private val resolveAwsEndpoint = runtimeConfig.awsEndpoint().asType().copy(name = "ResolveAwsEndpoint") override fun section(section: ServiceConfig): Writable = writable { when (section) { is ServiceConfig.ConfigStruct -> rust( @@ -109,7 +109,6 @@ class EndpointConfigCustomization(private val codegenContext: CodegenContext, pr } // This is an experiment in a slightly different way to create runtime types. All code MAY be refactored to use this pattern -fun RuntimeConfig.awsEndpointDependency() = awsRuntimeDependency("aws-endpoint") class EndpointResolverFeature(private val runtimeConfig: RuntimeConfig, private val operationShape: OperationShape) : OperationCustomization() { @@ -120,7 +119,7 @@ class EndpointResolverFeature(private val runtimeConfig: RuntimeConfig, private """ #T::set_endpoint_resolver(&mut ${section.request}.properties_mut(), ${section.config}.endpoint_resolver.clone()); """, - runtimeConfig.awsEndpointDependency().asType() + runtimeConfig.awsEndpoint().asType() ) } else -> emptySection @@ -145,7 +144,7 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat class EndpointResolverGenerator(codegenContext: CodegenContext, private val endpointData: ObjectNode) { private val runtimeConfig = codegenContext.runtimeConfig private val endpointPrefix = codegenContext.serviceShape.expectTrait().endpointPrefix - private val awsEndpoint = runtimeConfig.awsEndpointDependency().asType() + private val awsEndpoint = runtimeConfig.awsEndpoint().asType() private val codegenScope = arrayOf( "Partition" to awsEndpoint.member("Partition"), diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt index 59003b1f6..096f030d3 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt @@ -16,7 +16,7 @@ import software.amazon.smithy.rust.codegen.rustlang.RustWriter import software.amazon.smithy.rust.codegen.rustlang.Writable import software.amazon.smithy.rust.codegen.rustlang.asType import software.amazon.smithy.rust.codegen.rustlang.rust -import software.amazon.smithy.rust.codegen.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.rustlang.writable import software.amazon.smithy.rust.codegen.smithy.CodegenContext @@ -31,17 +31,16 @@ import software.amazon.smithy.rust.codegen.smithy.generators.FluentClientSection import software.amazon.smithy.rust.codegen.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.util.expectTrait +import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware private class Types(runtimeConfig: RuntimeConfig) { private val smithyClientDep = CargoDependency.SmithyClient(runtimeConfig).copy(optional = true) - private val awsHyperDep = runtimeConfig.awsRuntimeDependency("aws-hyper") val awsTypes = awsTypes(runtimeConfig).asType() - val awsHyper = awsHyperDep.asType() val smithyClientRetry = RuntimeType("retry", smithyClientDep, "aws_smithy_client") val awsSmithyClient = smithyClientDep.asType() - val awsMiddleware = RuntimeType("AwsMiddleware", awsHyperDep, "aws_hyper") + val defaultMiddleware = runtimeConfig.defaultMiddleware() val dynConnector = RuntimeType("DynConnector", smithyClientDep, "aws_smithy_client::erase") } @@ -63,16 +62,11 @@ class AwsFluentClientDecorator : RustCodegenDecorator { ) { writer -> FluentClientGenerator( codegenContext, - includeSmithyGenericClientDocs = false, generics = ClientGenerics( - connectorDefault = "#{AwsFluentClient_DynConnector}", - middlewareDefault = "#{AwsFluentClient_AwsMiddleware}", - retryDefault = "#{AwsFluentClient_retry}::Standard", - codegenScope = listOf( - "AwsFluentClient_AwsMiddleware" to types.awsMiddleware, - "AwsFluentClient_DynConnector" to types.dynConnector, - "AwsFluentClient_retry" to types.smithyClientRetry, - ) + connectorDefault = types.dynConnector, + middlewareDefault = types.defaultMiddleware, + retryDefault = types.smithyClientRetry.member("Standard"), + client = types.awsSmithyClient ), customizations = listOf( AwsPresignedFluentBuilderMethod(codegenContext.runtimeConfig), @@ -102,8 +96,22 @@ class AwsFluentClientDecorator : RustCodegenDecorator { } private class AwsFluentClientExtensions(private val types: Types) { + val clientGenerics = ClientGenerics( + connectorDefault = types.dynConnector, + middlewareDefault = types.defaultMiddleware, + retryDefault = types.smithyClientRetry.member("Standard"), + client = types.awsSmithyClient + ) + + private val codegenScope = arrayOf( + "Middleware" to types.defaultMiddleware, + "retry" to types.smithyClientRetry, + "DynConnector" to types.dynConnector, + "aws_smithy_client" to types.awsSmithyClient + ) + fun render(writer: RustWriter) { - writer.rustBlock("impl Client") { + writer.rustBlockTemplate("impl Client", *codegenScope) { rustTemplate( """ /// Creates a client with the given service config and connector override. @@ -113,7 +121,7 @@ private class AwsFluentClientExtensions(private val types: Types) { let sleep_impl = conf.sleep_impl.clone(); let mut builder = #{aws_smithy_client}::Builder::new() .connector(conn) - .middleware(#{aws_hyper}::AwsMiddleware::new()); + .middleware(#{Middleware}::new()); builder.set_retry_config(retry_config.into()); builder.set_timeout_config(timeout_config); if let Some(sleep_impl) = sleep_impl { @@ -123,11 +131,10 @@ private class AwsFluentClientExtensions(private val types: Types) { Self { handle: std::sync::Arc::new(Handle { client, conf }) } } """, - "aws_hyper" to types.awsHyper, - "aws_smithy_client" to types.awsSmithyClient + *codegenScope ) } - writer.rustBlock("impl Client") { + writer.rustBlockTemplate("impl Client<#{DynConnector}, #{Middleware}, #{retry}::Standard>", *codegenScope) { rustTemplate( """ /// Creates a new client from a shared config. @@ -143,7 +150,7 @@ private class AwsFluentClientExtensions(private val types: Types) { let timeout_config = conf.timeout_config.as_ref().cloned().unwrap_or_default(); let sleep_impl = conf.sleep_impl.clone(); let mut builder = #{aws_smithy_client}::Builder::dyn_https() - .middleware(#{aws_hyper}::AwsMiddleware::default()); + .middleware(#{Middleware}::new()); builder.set_retry_config(retry_config.into()); builder.set_timeout_config(timeout_config); // the builder maintains a try-state. To avoid suppressing the warning when sleep is unset, @@ -156,9 +163,9 @@ private class AwsFluentClientExtensions(private val types: Types) { Self { handle: std::sync::Arc::new(Handle { client, conf }) } } """, - "aws_hyper" to types.awsHyper, "aws_smithy_client" to types.awsSmithyClient, - "aws_types" to types.awsTypes + "aws_types" to types.awsTypes, + "Middleware" to types.defaultMiddleware ) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt index f46d5e43e..634066521 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt @@ -40,6 +40,7 @@ import software.amazon.smithy.rust.codegen.smithy.protocols.HttpBoundProtocolBod import software.amazon.smithy.rust.codegen.util.cloneOperation import software.amazon.smithy.rust.codegen.util.expectTrait import software.amazon.smithy.rust.codegen.util.hasTrait +import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware import software.amazon.smithy.rustsdk.traits.PresignableTrait import kotlin.streams.toList @@ -132,7 +133,6 @@ class AwsInputPresignedMethod( private val symbolProvider = codegenContext.symbolProvider private val codegenScope = arrayOf( - "aws_hyper" to runtimeConfig.awsRuntimeDependency("aws-hyper").copy(optional = true).asType(), "Error" to AwsRuntimeType.Presigning.member("config::Error"), "PresignedRequest" to AwsRuntimeType.Presigning.member("request::PresignedRequest"), "PresignedRequestService" to AwsRuntimeType.Presigning.member("service::PresignedRequestService"), @@ -141,6 +141,7 @@ class AwsInputPresignedMethod( "aws_sigv4" to runtimeConfig.awsRuntimeDependency("aws-sigv4").asType(), "sig_auth" to runtimeConfig.sigAuth().asType(), "tower" to CargoDependency.Tower.asType(), + "Middleware" to runtimeConfig.defaultMiddleware() ) override fun section(section: OperationSection): Writable = writable { @@ -221,7 +222,7 @@ class AwsInputPresignedMethod( } rustTemplate( """ - let middleware = #{aws_hyper}::AwsMiddleware::default(); + let middleware = #{Middleware}::default(); let mut svc = #{tower}::builder::ServiceBuilder::new() .layer(&middleware) .service(#{PresignedRequestService}::new()); diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt index 7fbc969ab..e79971ec0 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt @@ -45,6 +45,17 @@ object AwsRuntimeType { val Presigning by lazy { RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("presigning", public = true)) } + + fun RuntimeConfig.defaultMiddleware() = RuntimeType.forInlineDependency( + InlineAwsDependency.forRustFile( + "middleware", public = true, + CargoDependency.SmithyHttp(this), + CargoDependency.SmithyHttpTower(this), + CargoDependency.Tower, + awsHttp(), + awsEndpoint(), + ) + ).member("DefaultMiddleware") } fun RuntimeConfig.awsRuntimeDependency(name: String, features: Set = setOf()): CargoDependency = @@ -53,3 +64,4 @@ fun RuntimeConfig.awsRuntimeDependency(name: String, features: Set = set fun RuntimeConfig.awsHttp(): CargoDependency = awsRuntimeDependency("aws-http") fun RuntimeConfig.awsTypes(): CargoDependency = awsRuntimeDependency("aws-types") fun RuntimeConfig.awsConfig(): CargoDependency = awsRuntimeDependency("aws-config") +fun RuntimeConfig.awsEndpoint() = awsRuntimeDependency("aws-endpoint") diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineDependency.kt index 61479849e..2f0a1b1e2 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineDependency.kt @@ -6,8 +6,9 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.rust.codegen.rustlang.InlineDependency +import software.amazon.smithy.rust.codegen.rustlang.RustDependency object InlineAwsDependency { - fun forRustFile(file: String, public: Boolean = false): InlineDependency = - InlineDependency.Companion.forRustFile(file, "aws-inlineable", public) + fun forRustFile(file: String, public: Boolean = false, vararg additionalDependency: RustDependency): InlineDependency = + InlineDependency.Companion.forRustFile(file, "aws-inlineable", public, *additionalDependency) } diff --git a/aws/sdk/examples/dynamodb/Cargo.toml b/aws/sdk/examples/dynamodb/Cargo.toml index 291e2d316..1a973da34 100644 --- a/aws/sdk/examples/dynamodb/Cargo.toml +++ b/aws/sdk/examples/dynamodb/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dependencies] aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-dynamodb = { path = "../../build/aws-sdk/sdk/dynamodb" } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client" } diff --git a/aws/sdk/examples/dynamodb/src/bin/crud.rs b/aws/sdk/examples/dynamodb/src/bin/crud.rs index 92439bc2a..56310a875 100644 --- a/aws/sdk/examples/dynamodb/src/bin/crud.rs +++ b/aws/sdk/examples/dynamodb/src/bin/crud.rs @@ -5,9 +5,9 @@ use aws_config::meta::region::RegionProviderChain; use aws_http::AwsErrorRetryPolicy; -use aws_hyper::AwsMiddleware; use aws_sdk_dynamodb::error::DescribeTableError; use aws_sdk_dynamodb::input::DescribeTableInput; +use aws_sdk_dynamodb::middleware::DefaultMiddleware; use aws_sdk_dynamodb::model::{ AttributeDefinition, AttributeValue, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType, Select, TableStatus, @@ -284,7 +284,7 @@ async fn main() -> Result<(), Error> { println!("Waiting for table to be ready."); - let raw_client = aws_smithy_client::Client::::dyn_https(); + let raw_client = aws_smithy_client::Client::::dyn_https(); raw_client .call(wait_for_ready_table(&table, client.conf()).await) diff --git a/aws/sdk/examples/dynamodb/src/bin/movies.rs b/aws/sdk/examples/dynamodb/src/bin/movies.rs index abd3ae3d9..49bd6a426 100644 --- a/aws/sdk/examples/dynamodb/src/bin/movies.rs +++ b/aws/sdk/examples/dynamodb/src/bin/movies.rs @@ -8,10 +8,10 @@ use std::time::Duration; use aws_config::meta::region::RegionProviderChain; use aws_http::AwsErrorRetryPolicy; -use aws_hyper::AwsMiddleware; use aws_sdk_dynamodb::client::fluent_builders::Query; use aws_sdk_dynamodb::error::DescribeTableError; use aws_sdk_dynamodb::input::DescribeTableInput; +use aws_sdk_dynamodb::middleware::DefaultMiddleware; use aws_sdk_dynamodb::model::{ AttributeDefinition, AttributeValue, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType, TableStatus, @@ -79,7 +79,7 @@ async fn main() -> Result<(), Error> { let client = Client::new(&shared_config); - let raw_client = aws_smithy_client::Client::::dyn_https(); + let raw_client = aws_smithy_client::Client::::dyn_https(); let table_exists = client .list_tables() diff --git a/aws/sdk/examples/kms/Cargo.toml b/aws/sdk/examples/kms/Cargo.toml index 453853a5a..6a38648c9 100644 --- a/aws/sdk/examples/kms/Cargo.toml +++ b/aws/sdk/examples/kms/Cargo.toml @@ -8,7 +8,6 @@ description = "Example usage of the KMS service" [dependencies] aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } kms = { package = "aws-sdk-kms", path = "../../build/aws-sdk/sdk/kms" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } tokio = { version = "1", features = ["full"]} structopt = { version = "0.3", default-features = false } diff --git a/aws/sdk/examples/secretsmanager/Cargo.toml b/aws/sdk/examples/secretsmanager/Cargo.toml index fd6af70d4..ed1c74671 100644 --- a/aws/sdk/examples/secretsmanager/Cargo.toml +++ b/aws/sdk/examples/secretsmanager/Cargo.toml @@ -8,7 +8,6 @@ description = "Example usage of the SecretManager service" [dependencies] aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } secretsmanager = { package = "aws-sdk-secretsmanager", path = "../../build/aws-sdk/sdk/secretsmanager" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } diff --git a/aws/sdk/integration-tests/dynamodb/Cargo.toml b/aws/sdk/integration-tests/dynamodb/Cargo.toml index b24ed193c..8084e8cc3 100644 --- a/aws/sdk/integration-tests/dynamodb/Cargo.toml +++ b/aws/sdk/integration-tests/dynamodb/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dependencies] aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-dynamodb = { path = "../../build/aws-sdk/sdk/dynamodb" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/dynamodb/tests/movies.rs b/aws/sdk/integration-tests/dynamodb/tests/movies.rs index 72f105243..0d8d7a029 100644 --- a/aws/sdk/integration-tests/dynamodb/tests/movies.rs +++ b/aws/sdk/integration-tests/dynamodb/tests/movies.rs @@ -29,9 +29,9 @@ use std::collections::HashMap; use std::time::Duration; use tokio::time::Instant; -use aws_hyper::AwsMiddleware; +use aws_sdk_dynamodb::middleware::DefaultMiddleware; use aws_smithy_client::Client as CoreClient; -pub type Client = CoreClient; +pub type Client = CoreClient; fn create_table(table_name: &str) -> CreateTableInput { CreateTable::builder() diff --git a/aws/sdk/integration-tests/glacier/Cargo.toml b/aws/sdk/integration-tests/glacier/Cargo.toml index 12546fd39..e49916412 100644 --- a/aws/sdk/integration-tests/glacier/Cargo.toml +++ b/aws/sdk/integration-tests/glacier/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dev-dependencies] aws-http = { path = "../../build/aws-sdk/sdk/aws-http"} -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-glacier = { path = "../../build/aws-sdk/sdk/glacier" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-protocol-test = { path = "../../build/aws-sdk/sdk/aws-smithy-protocol-test"} diff --git a/aws/sdk/integration-tests/iam/Cargo.toml b/aws/sdk/integration-tests/iam/Cargo.toml index 1919ac9d7..55b454194 100644 --- a/aws/sdk/integration-tests/iam/Cargo.toml +++ b/aws/sdk/integration-tests/iam/Cargo.toml @@ -10,7 +10,6 @@ edition = "2018" [dev-dependencies] aws-endpoint = { path = "../../build/aws-sdk/sdk/aws-endpoint" } aws-http = { path = "../../build/aws-sdk/sdk/aws-http"} -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-iam = { path = "../../build/aws-sdk/sdk/iam" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/kms/Cargo.toml b/aws/sdk/integration-tests/kms/Cargo.toml index 74db583e3..1f0eec43b 100644 --- a/aws/sdk/integration-tests/kms/Cargo.toml +++ b/aws/sdk/integration-tests/kms/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dev-dependencies] aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-kms = { path = "../../build/aws-sdk/sdk/kms" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/kms/tests/integration.rs b/aws/sdk/integration-tests/kms/tests/integration.rs index bd7eb8d80..204b0ae0b 100644 --- a/aws/sdk/integration-tests/kms/tests/integration.rs +++ b/aws/sdk/integration-tests/kms/tests/integration.rs @@ -4,8 +4,8 @@ */ use aws_http::user_agent::AwsUserAgent; -use aws_hyper::AwsMiddleware; use aws_sdk_kms as kms; +use aws_sdk_kms::middleware::DefaultMiddleware; use aws_smithy_client::test_connection::TestConnection; use aws_smithy_client::{Client as CoreClient, SdkError}; use aws_smithy_http::body::SdkBody; @@ -16,7 +16,7 @@ use kms::Credentials; use kms::{Config, Region}; use std::time::{Duration, UNIX_EPOCH}; -type Client = CoreClient; +type Client = CoreClient; // TODO: having the full HTTP requests right in the code is a bit gross, consider something // like https://github.com/davidbarsky/sigv4/blob/master/aws-sigv4/src/lib.rs#L283-L315 to store diff --git a/aws/sdk/integration-tests/lambda/Cargo.toml b/aws/sdk/integration-tests/lambda/Cargo.toml index 18af437f3..bf3c9d31c 100644 --- a/aws/sdk/integration-tests/lambda/Cargo.toml +++ b/aws/sdk/integration-tests/lambda/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" [dev-dependencies] async-stream = "0.3" aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-lambda = { path = "../../build/aws-sdk/sdk/lambda" } base64 = "0.13" bytes = "1" diff --git a/aws/sdk/integration-tests/polly/Cargo.toml b/aws/sdk/integration-tests/polly/Cargo.toml index a894f60e1..74a8090b1 100644 --- a/aws/sdk/integration-tests/polly/Cargo.toml +++ b/aws/sdk/integration-tests/polly/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dev-dependencies] aws-http = { path = "../../build/aws-sdk/sdk/aws-http"} -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-polly = { path = "../../build/aws-sdk/sdk/polly" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/qldbsession/Cargo.toml b/aws/sdk/integration-tests/qldbsession/Cargo.toml index 2105a9578..136998a36 100644 --- a/aws/sdk/integration-tests/qldbsession/Cargo.toml +++ b/aws/sdk/integration-tests/qldbsession/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dev-dependencies] aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-qldbsession = { path = "../../build/aws-sdk/sdk/qldbsession" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/qldbsession/tests/integration.rs b/aws/sdk/integration-tests/qldbsession/tests/integration.rs index 3343be644..0bc7be8eb 100644 --- a/aws/sdk/integration-tests/qldbsession/tests/integration.rs +++ b/aws/sdk/integration-tests/qldbsession/tests/integration.rs @@ -4,18 +4,18 @@ */ use aws_http::user_agent::AwsUserAgent; -use aws_hyper::AwsMiddleware; use aws_sdk_qldbsession as qldbsession; use aws_smithy_client::test_connection::TestConnection; use aws_smithy_client::Client as CoreClient; use aws_smithy_http::body::SdkBody; use http::Uri; +use qldbsession::middleware::DefaultMiddleware; use qldbsession::model::StartSessionRequest; use qldbsession::operation::SendCommand; use qldbsession::Credentials; use qldbsession::{Config, Region}; use std::time::{Duration, UNIX_EPOCH}; -pub type Client = CoreClient; +pub type Client = CoreClient; // TODO: having the full HTTP requests right in the code is a bit gross, consider something // like https://github.com/davidbarsky/sigv4/blob/master/aws-sigv4/src/lib.rs#L283-L315 to store diff --git a/aws/sdk/integration-tests/s3/Cargo.toml b/aws/sdk/integration-tests/s3/Cargo.toml index 8cc12ab14..818ec3a24 100644 --- a/aws/sdk/integration-tests/s3/Cargo.toml +++ b/aws/sdk/integration-tests/s3/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dev-dependencies] aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3" } aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async", features = ["rt-tokio"] } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } diff --git a/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs b/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs index 2f3518c32..6cfc9f8ce 100644 --- a/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs +++ b/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs @@ -4,14 +4,14 @@ */ use aws_http::user_agent::AwsUserAgent; -use aws_hyper::AwsMiddleware; +use aws_sdk_s3::middleware::DefaultMiddleware; use aws_sdk_s3::{operation::PutObject, Credentials, Region}; use aws_smithy_client::test_connection::capture_request; use aws_smithy_client::Client as CoreClient; use http::HeaderValue; use std::time::UNIX_EPOCH; use tokio::time::Duration; -pub type Client = CoreClient; +pub type Client = CoreClient; const NAUGHTY_STRINGS: &str = include_str!("blns/blns.txt"); diff --git a/aws/sdk/integration-tests/s3/tests/signing-it.rs b/aws/sdk/integration-tests/s3/tests/signing-it.rs index 59c2dca2e..d597d95e9 100644 --- a/aws/sdk/integration-tests/s3/tests/signing-it.rs +++ b/aws/sdk/integration-tests/s3/tests/signing-it.rs @@ -4,14 +4,14 @@ */ use aws_http::user_agent::AwsUserAgent; -use aws_hyper::AwsMiddleware; +use aws_sdk_s3::middleware::DefaultMiddleware; use aws_sdk_s3::operation::ListObjectsV2; use aws_sdk_s3::{Credentials, Region}; use aws_smithy_client::test_connection::TestConnection; use aws_smithy_client::Client as CoreClient; use aws_smithy_http::body::SdkBody; use std::time::{Duration, UNIX_EPOCH}; -pub type Client = CoreClient; +pub type Client = CoreClient; #[tokio::test] async fn test_signer() -> Result<(), aws_sdk_s3::Error> { diff --git a/aws/sdk/integration-tests/s3control/Cargo.toml b/aws/sdk/integration-tests/s3control/Cargo.toml index 0d3f04255..d326ce201 100644 --- a/aws/sdk/integration-tests/s3control/Cargo.toml +++ b/aws/sdk/integration-tests/s3control/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dev-dependencies] aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-s3control = { path = "../../build/aws-sdk/sdk/s3control" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/s3control/tests/signing-it.rs b/aws/sdk/integration-tests/s3control/tests/signing-it.rs index 579232cfb..cc344803f 100644 --- a/aws/sdk/integration-tests/s3control/tests/signing-it.rs +++ b/aws/sdk/integration-tests/s3control/tests/signing-it.rs @@ -10,9 +10,9 @@ use aws_smithy_client::test_connection::TestConnection; use aws_smithy_http::body::SdkBody; use std::time::{Duration, UNIX_EPOCH}; -use aws_hyper::AwsMiddleware; +use aws_sdk_s3control::middleware::DefaultMiddleware; use aws_smithy_client::Client as CoreClient; -pub type Client = CoreClient; +pub type Client = CoreClient; #[tokio::test] async fn test_signer() -> Result<(), aws_sdk_s3control::Error> { diff --git a/aws/sdk/integration-tests/sts/Cargo.toml b/aws/sdk/integration-tests/sts/Cargo.toml index e20dce17f..12edf7292 100644 --- a/aws/sdk/integration-tests/sts/Cargo.toml +++ b/aws/sdk/integration-tests/sts/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dev-dependencies] -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-sts = { path = "../../build/aws-sdk/sdk/sts" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/transcribestreaming/Cargo.toml b/aws/sdk/integration-tests/transcribestreaming/Cargo.toml index a32bdf79e..c916b607a 100644 --- a/aws/sdk/integration-tests/transcribestreaming/Cargo.toml +++ b/aws/sdk/integration-tests/transcribestreaming/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" [dev-dependencies] async-stream = "0.3" aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-hyper = { path = "../../build/aws-sdk/sdk/aws-hyper" } aws-sdk-transcribestreaming = { path = "../../build/aws-sdk/sdk/transcribestreaming" } aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } aws-smithy-eventstream = { path = "../../build/aws-sdk/sdk/aws-smithy-eventstream" } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt index 545bae79b..ba0f42782 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt @@ -212,6 +212,7 @@ data class CargoDependency( fun SmithyClient(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("client") fun SmithyEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("eventstream") fun SmithyHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http") + fun SmithyHttpTower(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-tower") fun SmithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-server") fun SmithyProtocolTestHelpers(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("protocol-test").copy(scope = DependencyScope.Dev) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/FluentClientDecorator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/FluentClientDecorator.kt index db59124eb..d35183c99 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/FluentClientDecorator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/FluentClientDecorator.kt @@ -64,7 +64,6 @@ class FluentClientDecorator : RustCodegenDecorator { ) { writer -> FluentClientGenerator( codegenContext, - includeSmithyGenericClientDocs = true, customizations = listOf(GenericFluentClient(codegenContext)) ).render(writer) } @@ -105,31 +104,38 @@ sealed class FluentClientSection(name: String) : Section(name) { abstract class FluentClientCustomization : NamedSectionGenerator() data class ClientGenerics( - val connectorDefault: String? = null, - val middlewareDefault: String? = null, - val retryDefault: String? = "#{client}::retry::Standard", - val codegenScope: List> = emptyList(), + val connectorDefault: RuntimeType?, + val middlewareDefault: RuntimeType?, + val retryDefault: RuntimeType?, + val client: RuntimeType ) { /** Declaration with defaults set */ - val decl: String by lazy { - "" + val decl = writable { + rustTemplate( + "", + "c" to defaultType(connectorDefault), + "m" to defaultType(middlewareDefault), + "r" to defaultType(retryDefault) + ) } /** Instantiation */ val inst: String = "" /** Trait bounds */ - val bounds: String = """ - C: #{client}::bounds::SmithyConnector, - M: #{client}::bounds::SmithyMiddleware, - R: #{client}::retry::NewRequestPolicy, - """.trimIndent() + val bounds = writable { + rustTemplate( + """ + C: #{client}::bounds::SmithyConnector, + M: #{client}::bounds::SmithyMiddleware, + R: #{client}::retry::NewRequestPolicy, + """, + "client" to client + ) + } - private fun fmtDefault(default: String?): String { - return when (default) { - null -> "" - else -> "= $default" - } + private fun defaultType(default: RuntimeType?) = writable { + default?.also { rust("= #T", default) } } } @@ -266,10 +272,12 @@ class GenericFluentClient(codegenContext: CodegenContext) : FluentClientCustomiz class FluentClientGenerator( codegenContext: CodegenContext, - // Whether to include Client construction details that are relevant to generic Smithy generated clients, - // but not necessarily relevant to customized clients, such as the ones with the AWS SDK. - private val includeSmithyGenericClientDocs: Boolean, - private val generics: ClientGenerics = ClientGenerics(), + private val generics: ClientGenerics = ClientGenerics( + connectorDefault = null, + middlewareDefault = null, + retryDefault = CargoDependency.SmithyClient(codegenContext.runtimeConfig).asType().member("retry::Standard"), + client = CargoDependency.SmithyClient(codegenContext.runtimeConfig).asType() + ), private val customizations: List = emptyList(), ) { companion object { @@ -284,22 +292,20 @@ class FluentClientGenerator( private val model = codegenContext.model private val clientDep = CargoDependency.SmithyClient(codegenContext.runtimeConfig).copy(optional = true) private val runtimeConfig = codegenContext.runtimeConfig - private val moduleUseName = codegenContext.moduleUseName() - private val humanName = serviceShape.id.name private val core = FluentClientCore(model) fun render(writer: RustWriter) { writer.rustTemplate( """ ##[derive(Debug)] - pub(crate) struct Handle${generics.decl} { + pub(crate) struct Handle#{generics_decl:W} { client: #{client}::Client${generics.inst}, conf: crate::Config, } #{client_docs:W} ##[derive(std::fmt::Debug)] - pub struct Client${generics.decl} { + pub struct Client#{generics_decl:W} { handle: std::sync::Arc } @@ -335,6 +341,7 @@ class FluentClientGenerator( } } """, + "generics_decl" to generics.decl, "client" to clientDep.asType(), "client_docs" to writable { customizations.forEach { @@ -345,11 +352,11 @@ class FluentClientGenerator( )(this) } }, - *generics.codegenScope.toTypedArray() ) writer.rustBlockTemplate( - "impl${generics.inst} Client${generics.inst} where ${generics.bounds}", + "impl${generics.inst} Client${generics.inst} where #{bounds:W}", "client" to clientDep.asType(), + "bounds" to generics.bounds ) { operations.forEach { operation -> val name = symbolProvider.toSymbol(operation).name @@ -397,20 +404,21 @@ class FluentClientGenerator( rustTemplate( """ ##[derive(std::fmt::Debug)] - pub struct ${operationSymbol.name}${generics.decl} { + pub struct ${operationSymbol.name}#{generics:W} { handle: std::sync::Arc, inner: #{Inner} } """, "Inner" to input.builderSymbol(symbolProvider), - *generics.codegenScope.toTypedArray(), "client" to clientDep.asType(), + "generics" to generics.decl, "operation" to operationSymbol ) rustBlockTemplate( - "impl${generics.inst} ${operationSymbol.name}${generics.inst} where ${generics.bounds}", + "impl${generics.inst} ${operationSymbol.name}${generics.inst} where #{bounds:W}", "client" to clientDep.asType(), + "bounds" to generics.bounds ) { rustTemplate( """ diff --git a/design/src/rfcs/rfc0006_service_specific_middleware.md b/design/src/rfcs/rfc0006_service_specific_middleware.md index 44573dc5a..a9c2a98c4 100644 --- a/design/src/rfcs/rfc0006_service_specific_middleware.md +++ b/design/src/rfcs/rfc0006_service_specific_middleware.md @@ -1,7 +1,7 @@ RFC: Service-specific middleware ================================ -> Status: RFC +> Status: [Implemented](https://github.com/awslabs/smithy-rs/pull/959) For a summarized list of proposed changes, see the [Changes Checklist](#changes-checklist) section. @@ -50,7 +50,7 @@ can easily configure `AwsFluentClientGenerator` to insert different types based # Changes Checklist -- [ ] Move aws-hyper into aws-inlineable. Update comments as needed including with a usage example about how customers can augment it. -- [ ] Refactor `ClientGenerics` to contain a RuntimeType instead of a string and configure. Update `AwsFluentClientDecorator`. -- [ ] Update all code and examples that use `aws-hyper` to use service-specific middleware. -- [ ] Push an updated README to aws-hyper deprecating the package, explaining what happened. Do _not_ yank previous versions since those will be relied on by older SDK versions. +- [x] Move aws-hyper into aws-inlineable. Update comments as needed including with a usage example about how customers can augment it. +- [x] Refactor `ClientGenerics` to contain a RuntimeType instead of a string and configure. Update `AwsFluentClientDecorator`. +- [x] Update all code and examples that use `aws-hyper` to use service-specific middleware. +- [x] Push an updated README to aws-hyper deprecating the package, explaining what happened. Do _not_ yank previous versions since those will be relied on by older SDK versions. -- GitLab