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

Rust: Update custom-root-certificates example. #5717

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions rustv1/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"cognitosync",
"concurrency",
"config",
"custom-root-certificates",
"dynamodb",
"ebs",
"ec2",
Expand Down
5 changes: 3 additions & 2 deletions rustv1/examples/custom-root-certificates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ aws-config = { features = ["behavior-version-latest"], version = "1.0.1"}
# bringing our own HTTPs so no need for the default features
aws-sdk-s3 = "1.2.0"
tokio = { version = "1.21.2", features = ["full"] }
rustls = "0.20.7"
hyper-rustls = { version = "0.23.0", features = ["http2"] }
rustls = "0.21.9"
hyper-rustls = { version = "0.24.2", features = ["http2"] }
aws-smithy-runtime = { version = "1.0.2", features = ["tls-rustls"] }
24 changes: 6 additions & 18 deletions rustv1/examples/custom-root-certificates/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* SPDX-License-Identifier: Apache-2.0.
*/

use aws_config::provider_config::ProviderConfig;
use aws_config::BehaviorVersion;
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
use rustls::RootCertStore;
use std::sync::Arc;

#[tokio::main]
async fn main() {
Expand All @@ -16,36 +15,25 @@ async fn main() {
.with_safe_defaults()
.with_root_certificates(root_store)
.with_no_client_auth();
let rustls_connector = hyper_rustls::HttpsConnectorBuilder::new()
let tls_connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_tls_config(config)
.https_only()
.enable_http1()
.enable_http2()
.build();

// Currently, aws_config connectors are buildable directly from something that implements `hyper::Connect`.
// This enables different providers to construct clients with different timeouts.
let provider_config = ProviderConfig::default().with_tcp_connector(rustls_connector.clone());
let hyper_client = HyperClientBuilder::new().build(tls_connector);
let sdk_config = aws_config::defaults(BehaviorVersion::latest())
.configure(provider_config)
.http_connector(HttpConnector::ConnectorFn(Arc::new(
move |connector_settings, sleep_impl| {
let mut builder =
hyper_ext::Adapter::builder().connector_settings(connector_settings.clone());
builder.set_sleep_impl(sleep_impl);
let conn = builder.build(rustls_connector.clone());

Some(DynConnector::new(conn))
},
)))
.http_client(hyper_client)
.load()
.await;

// however, for generated clients, they are constructed from a Hyper adapter directly:
let s3_client = aws_sdk_s3::Client::new(&sdk_config);

match s3_client.list_buckets().send().await {
Ok(res) => {
println!("Your buckets: {:?}", res.buckets().unwrap_or_default())
println!("Your buckets: {:?}", res.buckets())
}
Err(err) => {
println!("an error occurred when trying to list buckets: {}", err)
Expand Down
Loading