Unverified Commit 26a914ec authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Replace `DynConnector` and `HttpConnector` with `HttpClient` (#3011)

This PR removes the last usages of `DynConnector` and `HttpConnector`
from the `aws_smithy_client` crate with their counterparts in
aws-smithy-runtime-api and aws-smithy-runtime. It also introduces
`HttpClient` to make HTTP connector selection a smoother process, and
adds a runtime plugin that configures a default `HttpClient` so that
`Config` doesn't have to do that.

The `DnsService` from aws-config is also moved into aws-smithy-runtime
and refactored to be consistent with the other configurable traits in
the orchestrator since it will likely be used in the future for more
than just the ECS credentials provider.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent f70ae9bf
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -11,6 +11,18 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"

[[smithy-rs]]
message = "HTTP connector configuration has changed significantly. See the [upgrade guidance](https://github.com/awslabs/smithy-rs/discussions/3022) for details."
references = ["smithy-rs#3011"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"

[[aws-sdk-rust]]
message = "HTTP connector configuration has changed significantly. See the [upgrade guidance](https://github.com/awslabs/smithy-rs/discussions/3022) for details."
references = ["smithy-rs#3011"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = "It's now possible to nest runtime components with the `RuntimePlugin` trait. A `current_components` argument was added to the `runtime_components` method so that components configured from previous runtime plugins can be referenced in the current runtime plugin. Ordering of runtime plugins was also introduced via a new `RuntimePlugin::order` method."
references = ["smithy-rs#2909"]
+5 −10
Original line number Diff line number Diff line
@@ -9,11 +9,10 @@ license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"

[features]
client-hyper = ["aws-smithy-client/client-hyper", "aws-smithy-runtime/connector-hyper"]
rustls = ["aws-smithy-client/rustls", "client-hyper"]
native-tls = []
client-hyper = ["aws-smithy-runtime/connector-hyper-0-14-x"]
rustls = ["aws-smithy-runtime/tls-rustls", "client-hyper"]
allow-compilation = [] # our tests use `cargo test --all-features` and native-tls breaks CI
rt-tokio = ["aws-smithy-async/rt-tokio", "tokio/rt"]
rt-tokio = ["aws-smithy-async/rt-tokio", "aws-smithy-runtime/rt-tokio", "tokio/rt"]
credentials-sso = ["dep:aws-sdk-sso", "dep:ring", "dep:hex", "dep:zeroize"]

default = ["client-hyper", "rustls", "rt-tokio", "credentials-sso"]
@@ -23,9 +22,7 @@ aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-type
aws-http = { path = "../../sdk/build/aws-sdk/sdk/aws-http" }
aws-sdk-sts = { path = "../../sdk/build/aws-sdk/sdk/sts", default-features = false }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async" }
aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client", default-features = false }
aws-smithy-http = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http" }
aws-smithy-http-tower = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http-tower" }
aws-smithy-json = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-json" }
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client"] }
aws-smithy-runtime-api = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["client"] }
@@ -42,7 +39,6 @@ fastrand = "2.0.0"

bytes = "1.1.0"
http = "0.2.4"
tower = { version = "0.4.8" }

# implementation detail of SSO credential caching
aws-sdk-sso = { path = "../../sdk/build/aws-sdk/sdk/sso", default-features = false, optional = true }
@@ -51,7 +47,7 @@ hex = { version = "0.4.3", optional = true }
zeroize = { version = "1", optional = true }

[dev-dependencies]
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "test-util"] }
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "connector-hyper-0-14-x", "test-util"] }
futures-util = { version = "0.3.16", default-features = false }
tracing-test = "0.2.1"
tracing-subscriber = { version = "0.3.16", features = ["fmt", "json"] }
@@ -66,11 +62,10 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"

aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rt-tokio", "client-hyper"] }

# 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 = ["test-util"] }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async", features = ["rt-tokio", "test-util"] }

[package.metadata.docs.rs]
all-features = true
+6 −6
Original line number Diff line number Diff line
@@ -9,17 +9,17 @@ allowed_external_types = [
   "aws_credential_types::provider::SharedCredentialsProvider",
   "aws_sdk_sts::types::_policy_descriptor_type::PolicyDescriptorType",
   "aws_smithy_async::rt::sleep::AsyncSleep",
   "aws_smithy_async::rt::sleep::SharedAsyncSleep",
   "aws_smithy_async::time::SharedTimeSource",
   "aws_smithy_async::time::TimeSource",
   "aws_smithy_client::bounds::SmithyConnector",
   "aws_smithy_client::conns::default_connector::default_connector",
   "aws_smithy_client::erase::DynConnector",
   "aws_smithy_client::erase::boxclone::BoxCloneService",
   "aws_smithy_client::http_connector::ConnectorSettings",
   "aws_smithy_client::http_connector::HttpConnector",
   "aws_smithy_http::body::SdkBody",
   "aws_smithy_http::endpoint",
   "aws_smithy_http::endpoint::error::InvalidEndpointError",
   "aws_smithy_http::result::SdkError",
   "aws_smithy_runtime_api::client::dns::DnsResolver",
   "aws_smithy_runtime_api::client::dns::SharedDnsResolver",
   "aws_smithy_runtime_api::client::http::HttpClient",
   "aws_smithy_runtime_api::client::http::SharedHttpClient",
   "aws_smithy_types::retry",
   "aws_smithy_types::retry::*",
   "aws_smithy_types::timeout",
+0 −32
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

//! Functionality related to creating new HTTP Connectors

use aws_smithy_client::erase::DynConnector;

/// Unwrap an [`Option<DynConnector>`](aws_smithy_client::erase::DynConnector), and panic with a helpful error message if it's `None`
pub(crate) fn expect_connector(for_what: &str, connector: Option<DynConnector>) -> DynConnector {
    if let Some(conn) = connector {
        conn
    } else {
        panic!("{for_what} require(s) a HTTP connector, but none was available. Enable the `rustls` crate feature or set a connector to fix this.")
    }
}

#[cfg(feature = "client-hyper")]
pub use aws_smithy_client::conns::default_connector;

#[cfg(all(feature = "native-tls", not(feature = "allow-compilation")))]
compile_error!("Feature native-tls has been removed. For upgrade instructions, see: https://awslabs.github.io/smithy-rs/design/transport/connector.html");

/// Given `ConnectorSettings` and a [`SharedAsyncSleep`](aws_smithy_async::rt::sleep::SharedAsyncSleep), create a `DynConnector` from defaults depending on what cargo features are activated.
#[cfg(not(feature = "client-hyper"))]
pub fn default_connector(
    _settings: &aws_smithy_client::http_connector::ConnectorSettings,
    _sleep: Option<aws_smithy_async::rt::sleep::SharedAsyncSleep>,
) -> Option<DynConnector> {
    None
}
+5 −5
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ mod tests {
    use super::*;
    use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
    use crate::provider_config::ProviderConfig;
    use crate::test_case::{no_traffic_connector, InstantSleep};
    use crate::test_case::{no_traffic_client, InstantSleep};
    use aws_types::os_shim_internal::{Env, Fs};

    #[tokio::test]
@@ -105,7 +105,7 @@ mod tests {
                &ProviderConfig::no_configuration()
                    .with_fs(fs)
                    .with_env(env)
                    .with_http_connector(no_traffic_connector()),
                    .with_http_client(no_traffic_client()),
            )
            .app_name()
            .await;
@@ -120,7 +120,7 @@ mod tests {
        let conf = crate::from_env()
            .sleep_impl(InstantSleep)
            .fs(fs)
            .http_connector(no_traffic_connector())
            .http_client(no_traffic_client())
            .profile_name("custom")
            .profile_files(
                ProfileFiles::builder()
@@ -141,7 +141,7 @@ mod tests {
                &ProviderConfig::empty()
                    .with_fs(fs)
                    .with_env(env)
                    .with_http_connector(no_traffic_connector()),
                    .with_http_client(no_traffic_client()),
            )
            .app_name()
            .await;
@@ -158,7 +158,7 @@ mod tests {
                &ProviderConfig::empty()
                    .with_fs(fs)
                    .with_env(env)
                    .with_http_connector(no_traffic_connector()),
                    .with_http_client(no_traffic_client()),
            )
            .app_name()
            .await;
Loading