Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable hyper1 as default http client #3939

Merged
merged 17 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 85 additions & 90 deletions aws/rust-runtime/Cargo.lock

Large diffs are not rendered by default.

469 changes: 326 additions & 143 deletions aws/rust-runtime/aws-config/Cargo.lock

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions aws/rust-runtime/aws-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ repository = "https://github.com/smithy-lang/smithy-rs"

[features]
behavior-version-latest = []
client-hyper = ["aws-smithy-runtime/connector-hyper-0-14-x"]
credentials-process = ["tokio/process"]
default = ["client-hyper", "rustls", "rt-tokio", "credentials-process", "sso"]
default = ["default-http-connector", "rt-tokio", "credentials-process", "sso"]
rt-tokio = ["aws-smithy-async/rt-tokio", "aws-smithy-runtime/rt-tokio", "tokio/rt"]
rustls = ["aws-smithy-runtime/tls-rustls", "client-hyper"]
# NOTE: `client-hyper` and `rustls` were proxies for enabling the default HTTP client plugin of `aws-smithy-runtime`
# there is no direct usage otherwise on hyper or rustls in this crate. These are superceded by the more appropriately
# named `default-http-connector` feature and `client-hyper` and `rustls` are now synonyms for the same
client-hyper = ["aws-smithy-runtime/default-http-connector"]
rustls = ["client-hyper"]
default-http-connector = ["aws-smithy-runtime/default-http-connector"]
sso = ["dep:aws-sdk-sso", "dep:aws-sdk-ssooidc", "dep:ring", "dep:hex", "dep:zeroize", "aws-smithy-runtime-api/http-auth"]

# deprecated: this feature does nothing
Expand Down Expand Up @@ -53,9 +57,13 @@ zeroize = { version = "1", optional = true }
# implementation detail of SSO OIDC `CreateToken` for SSO token providers
aws-sdk-ssooidc = { path = "../../sdk/build/aws-sdk/sdk/ssooidc", default-features = false, optional = true }

# FIXME - workaround minimal-versions check issue with proc-macro < 1.0.60
proc-macro2 = {version = "1.0.92", optional = true }

[dev-dependencies]
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "connector-hyper-0-14-x", "test-util"] }
aws-smithy-http-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http-client", features = ["test-util"] }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async", features = ["rt-tokio", "test-util"] }
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "test-util-latest"] }
aws-smithy-http-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http-client", features = ["hyper-1", "test-util"] }
aws-smithy-runtime-api = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["test-util"] }
futures-util = { version = "0.3.29", default-features = false }
tracing-test = "0.2.4"
Expand All @@ -66,11 +74,6 @@ tokio = { version = "1.23.1", features = ["full", "test-util"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

# used for a usage example
hyper-rustls = { version = "0.24", features = ["webpki-tokio", "http2", "http1"] }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async", features = ["rt-tokio", "test-util"] }


[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::meta::credentials::CredentialsProviderChain;
use crate::meta::region::ProvideRegion;
use crate::provider_config::ProviderConfig;

#[cfg(feature = "rustls")]
#[cfg(any(feature = "default-http-connector", feature = "rustls"))]
/// Default Credentials Provider chain
///
/// The region from the default region provider will be used
Expand Down Expand Up @@ -170,7 +170,7 @@ impl Builder {
/// Creates a `DefaultCredentialsChain`
///
/// ## Panics
/// This function will panic if no connector has been set or the `rustls`
/// This function will panic if no connector has been set or the `default-http-connector`
/// feature has been disabled.
pub async fn build(self) -> DefaultCredentialsChain {
let region = match self.region_override {
Expand Down Expand Up @@ -347,17 +347,15 @@ mod test {
}

#[tokio::test]
#[cfg(feature = "client-hyper")]
async fn no_providers_configured_err() {
use crate::provider_config::ProviderConfig;
use aws_credential_types::provider::error::CredentialsError;
use aws_smithy_async::rt::sleep::TokioSleep;
use aws_smithy_http_client::test_util::NeverTcpConnector;
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;

tokio::time::pause();
let conf = ProviderConfig::no_configuration()
.with_http_client(HyperClientBuilder::new().build(NeverTcpConnector::new()))
.with_http_client(NeverTcpConnector::new().into_client())
.with_time_source(StaticTimeSource::new(UNIX_EPOCH))
.with_sleep_impl(TokioSleep::new());
let provider = DefaultCredentialsChain::builder()
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/imds/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ pub(crate) mod test {
#[cfg_attr(windows, ignore)]
/// Verify that the end-to-end real client has a 1-second connect timeout
#[tokio::test]
#[cfg(feature = "rustls")]
#[cfg(feature = "default-http-connector")]
ysaito1001 marked this conversation as resolved.
Show resolved Hide resolved
async fn one_second_connect_timeout() {
use crate::imds::client::ImdsError;
use aws_smithy_types::error::display::DisplayErrorContext;
Expand Down
6 changes: 3 additions & 3 deletions aws/rust-runtime/aws-config/src/imds/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ mod test {
}

#[tokio::test]
#[cfg(feature = "rustls")]
#[cfg(feature = "default-http-connector")]
async fn read_timeout_during_credentials_refresh_should_yield_last_retrieved_credentials() {
let client = crate::imds::Client::builder()
// 240.* can never be resolved
Expand All @@ -436,7 +436,7 @@ mod test {
}

#[tokio::test]
#[cfg(feature = "rustls")]
#[cfg(feature = "default-http-connector")]
async fn read_timeout_during_credentials_refresh_should_error_without_last_retrieved_credentials(
) {
let client = crate::imds::Client::builder()
Expand All @@ -458,7 +458,7 @@ mod test {
// TODO(https://github.com/awslabs/aws-sdk-rust/issues/1117) This test is ignored on Windows because it uses Unix-style paths
#[cfg_attr(windows, ignore)]
#[tokio::test]
#[cfg(feature = "rustls")]
#[cfg(feature = "default-http-connector")]
async fn external_timeout_during_credentials_refresh_should_yield_last_retrieved_credentials() {
use aws_smithy_async::rt::sleep::AsyncSleep;
let client = crate::imds::Client::builder()
Expand Down
31 changes: 3 additions & 28 deletions aws/rust-runtime/aws-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,31 +391,6 @@ mod loader {
///
/// If you wish to use a separate HTTP client for credentials providers when creating clients,
/// then override the HTTP client set with this function on the client-specific `Config`s.
///
/// ## Examples
///
/// ```no_run
/// # use aws_smithy_async::rt::sleep::SharedAsyncSleep;
/// #[cfg(feature = "client-hyper")]
/// # async fn create_config() {
/// use std::time::Duration;
/// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
///
/// let tls_connector = hyper_rustls::HttpsConnectorBuilder::new()
/// .with_webpki_roots()
/// // NOTE: setting `https_only()` will not allow this connector to work with IMDS.
/// .https_only()
/// .enable_http1()
/// .enable_http2()
/// .build();
///
/// let hyper_client = HyperClientBuilder::new().build(tls_connector);
/// let sdk_config = aws_config::from_env()
/// .http_client(hyper_client)
/// .load()
/// .await;
/// # }
/// ```
pub fn http_client(mut self, http_client: impl HttpClient + 'static) -> Self {
self.http_client = Some(http_client.into_shared());
self
Expand Down Expand Up @@ -1128,7 +1103,7 @@ mod loader {
assert_eq!(Some(&app_name), conf.app_name());
}

#[cfg(feature = "rustls")]
#[cfg(feature = "default-http-connector")]
#[tokio::test]
async fn disable_default_credentials() {
let config = defaults(BehaviorVersion::latest())
Expand All @@ -1138,15 +1113,15 @@ mod loader {
assert!(config.credentials_provider().is_none());
}

#[cfg(feature = "rustls")]
#[cfg(feature = "default-http-connector")]
#[tokio::test]
async fn identity_cache_defaulted() {
let config = defaults(BehaviorVersion::latest()).load().await;

assert!(config.identity_cache().is_some());
}

#[cfg(feature = "rustls")]
#[cfg(feature = "default-http-connector")]
#[allow(deprecated)]
#[tokio::test]
async fn identity_cache_old_behavior_version() {
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-config/src/meta/credentials/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl CredentialsProviderChain {
}

/// Add a fallback to the default provider chain
#[cfg(feature = "rustls")]
#[cfg(any(feature = "default-http-connector", feature = "rustls"))]
pub async fn or_default_provider(self) -> Self {
self.or_else(
"DefaultProviderChain",
Expand All @@ -82,7 +82,7 @@ impl CredentialsProviderChain {
}

/// Creates a credential provider chain that starts with the default provider
#[cfg(feature = "rustls")]
#[cfg(any(feature = "default-http-connector", feature = "rustls"))]
pub async fn default_provider() -> Self {
Self::first_try(
"DefaultProviderChain",
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/profile/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(crate) mod repr;
/// future::ProvideCredentials::new(self.load_credentials())
/// }
/// }
/// # if cfg!(feature = "rustls") {
/// # if cfg!(feature = "default-http-connector") {
/// let provider = ProfileFileCredentialsProvider::builder()
/// .with_custom_provider("Custom", MyCustomProvider)
/// .build();
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/provider_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ProviderConfig {
///
/// # Examples
/// ```no_run
/// # #[cfg(feature = "rustls")]
/// # #[cfg(feature = "default-http-connector")]
/// # fn example() {
/// use aws_config::provider_config::ProviderConfig;
/// use aws_sdk_sts::config::Region;
Expand Down
5 changes: 3 additions & 2 deletions aws/rust-runtime/aws-config/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,21 @@ where
O: for<'a> Deserialize<'a> + Secrets + PartialEq + Debug,
E: Error,
{
#[cfg(feature = "default-http-connector")]
#[allow(unused)]
#[cfg(all(feature = "client-hyper", feature = "rustls"))]
/// Record a test case from live (remote) HTTPS traffic
///
/// The `default_connector()` from the crate will be used
pub(crate) async fn execute_from_live_traffic(&self) {
// swap out the connector generated from `http-traffic.json` for a real connector:

use std::error::Error;
let live_connector = aws_smithy_runtime::client::http::hyper_014::default_connector(
let live_connector = aws_smithy_http_client::default_connector(
&Default::default(),
self.provider_config.sleep_impl(),
)
.expect("feature gate on this function makes this always return Some");

let live_client = RecordingClient::new(live_connector);
let config = self
.provider_config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AwsFluentClientDecorator : ClientCodegenDecorator {
rustCrate.withModule(ClientRustModule.client) {
AwsFluentClientExtensions(codegenContext, types).render(this)
}
rustCrate.mergeFeature(Feature("rustls", default = true, listOf("aws-smithy-runtime/tls-rustls")))
rustCrate.mergeFeature(Feature("rustls", default = true, listOf("aws-smithy-runtime/default-http-connector")))
}

override fun libRsCustomizations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class IntegrationTestDependencies(
addDependency(SerdeJson)
addDependency(smithyAsync)
addDependency(smithyProtocolTestHelpers(codegenContext.runtimeConfig))
addDependency(smithyRuntime(runtimeConfig).copy(features = setOf("test-util", "wire-mock"), scope = DependencyScope.Dev))
addDependency(smithyRuntime(runtimeConfig).copy(features = setOf("test-util-latest"), scope = DependencyScope.Dev))
addDependency(smithyRuntimeApiTestUtil(runtimeConfig))
addDependency(smithyTypes)
addDependency(Tokio)
Expand Down
Loading
Loading