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

HTTP Connectors Refactor pt.1 - Laying the groundwork #1144

Merged
merged 13 commits into from
Feb 4, 2022
Merged
97 changes: 97 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,103 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"

[[aws-sdk-rust]]
message = "Several modules defined in the `aws_config` crate that used to be declared within another module's file have been moved to their own files. The moved modules are `sts`, `connector`, and `default_providers`. They still have the exact same import paths."
references = ["smithy-rs#1144"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "Velfi"

[[aws-sdk-rust]]
message = "The `aws_config::http_provider` module has been renamed to `aws_config::http_credential_provider` to better reflect its purpose."
references = ["smithy-rs#1144"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "Velfi"

[[aws-sdk-rust]]
message = """
Some APIs required that timeout configuration be specified with an `aws_smithy_client::timeout::Settings` struct while
others required an `aws_smithy_types::timeout::TimeoutConfig` struct. Both were equivalent. Now `aws_smithy_types::timeout::TimeoutConfig`
is used everywhere and `aws_smithy_client::timeout::Settings` has been removed. Here's how to migrate code your code that
depended on `timeout::Settings`:

The old way:
```rust
let timeout = timeout::Settings::new()
.with_connect_timeout(Duration::from_secs(1))
.with_read_timeout(Duration::from_secs(2));
```

The new way:
```rust
// This example is passing values, so they're wrapped in `Option::Some`. You can disable a timeout by passing `None`.
let timeout = TimeoutConfig::new()
.with_connect_timeout(Some(Duration::from_secs(1)))
.with_read_timeout(Some(Duration::from_secs(2)));
```
"""
references = ["smithy-rs#1144"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "Velfi"

[[smithy-rs]]
message = """
Some APIs required that timeout configuration be specified with an `aws_smithy_client::timeout::Settings` struct while
others required an `aws_smithy_types::timeout::TimeoutConfig` struct. Both were equivalent. Now `aws_smithy_types::timeout::TimeoutConfig`
is used everywhere and `aws_smithy_client::timeout::Settings` has been removed. Here's how to migrate code your code that
depended on `timeout::Settings`:

The old way:
```rust
let timeout = timeout::Settings::new()
.with_connect_timeout(Duration::from_secs(1))
.with_read_timeout(Duration::from_secs(2));
```

The new way:
```rust
// This example is passing values, so they're wrapped in `Option::Some`. You can disable a timeout by passing `None`.
let timeout = TimeoutConfig::new()
.with_connect_timeout(Some(Duration::from_secs(1)))
.with_read_timeout(Some(Duration::from_secs(2)));
```
"""
references = ["smithy-rs#1144"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "Velfi"

[[aws-sdk-rust]]
message = """
`MakeConnectorFn`, `HttpConnector`, and `HttpSettings` have been moved from `aws_config::provider_config` to
`aws_smithy_client::http_connector`. This is in preparation for a later update that will change how connectors are
created and configured.

If you were using these structs/enums, you can migrate your old code by importing them from their new location.
"""
references = ["smithy-rs#1144"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "Velfi"

[[smithy-rs]]
message = """
`MakeConnectorFn`, `HttpConnector`, and `HttpSettings` have been moved from `aws_config::provider_config` to
`aws_smithy_client::http_connector`. This is in preparation for a later update that will change how connectors are
created and configured.
"""
references = ["smithy-rs#1144"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "Velfi"

[[aws-sdk-rust]]
message = """
Along with moving `HttpConnector` to `aws_smithy_client`, the `HttpConnector::make_connector` method has been renamed to
`HttpConnector::connector`.

If you were using this method, you can migrate your old code by calling `connector` instead of `make_connector`.
"""
references = ["smithy-rs#1144"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "Velfi"

[[smithy-rs]]
message = "Refactor `Document` shape parser generation"
references = ["smithy-rs#1123"]
Expand Down
60 changes: 60 additions & 0 deletions aws/rust-runtime/aws-config/src/connector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

//! Functionality related to creating new HTTP Connectors

use std::sync::Arc;

use aws_smithy_async::rt::sleep::AsyncSleep;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::http_connector::HttpSettings;

// unused when all crate features are disabled
/// 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(connector: Option<DynConnector>) -> DynConnector {
connector.expect("A connector was not available. Either set a custom connector or enable the `rustls` and `native-tls` crate features.")
}

#[cfg(any(feature = "rustls", feature = "native-tls"))]
fn base(
settings: &HttpSettings,
sleep: Option<Arc<dyn AsyncSleep>>,
) -> aws_smithy_client::hyper_ext::Builder {
let mut hyper =
aws_smithy_client::hyper_ext::Adapter::builder().timeout(&settings.timeout_config);
if let Some(sleep) = sleep {
hyper = hyper.sleep_impl(sleep);
}
hyper
}

/// Given `HttpSettings` and an `AsyncSleep`, create a `DynConnector` from defaults depending on what cargo features are activated.
#[cfg(feature = "rustls")]
pub fn default_connector(
settings: &HttpSettings,
sleep: Option<Arc<dyn AsyncSleep>>,
) -> Option<DynConnector> {
let hyper = base(settings, sleep).build(aws_smithy_client::conns::https());
Some(DynConnector::new(hyper))
}

/// Given `HttpSettings` and an `AsyncSleep`, create a `DynConnector` from defaults depending on what cargo features are activated.
#[cfg(all(not(feature = "rustls"), feature = "native-tls"))]
pub fn default_connector(
settings: &HttpSettings,
sleep: Option<Arc<dyn AsyncSleep>>,
) -> Option<DynConnector> {
let hyper = base(settings, sleep).build(aws_smithy_client::conns::native_tls());
Some(DynConnector::new(hyper))
}

/// Given `HttpSettings` and an `AsyncSleep`, create a `DynConnector` from defaults depending on what cargo features are activated.
#[cfg(not(any(feature = "rustls", feature = "native-tls")))]
pub fn default_connector(
_settings: &HttpSettings,
_sleep: Option<Arc<dyn AsyncSleep>>,
) -> Option<DynConnector> {
None
}
Loading