From edc2999ae084ca4371f7267032936f994763e629 Mon Sep 17 00:00:00 2001 From: David Souther Date: Tue, 28 Nov 2023 22:28:37 -0500 Subject: [PATCH] Rust: Update custom-root-certificates example. Closes #5668 --- rustv1/examples/Cargo.toml | 1 + .../custom-root-certificates/Cargo.toml | 5 ++-- .../custom-root-certificates/src/main.rs | 24 +++++-------------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/rustv1/examples/Cargo.toml b/rustv1/examples/Cargo.toml index bab032a57bf..b9fdf16a236 100644 --- a/rustv1/examples/Cargo.toml +++ b/rustv1/examples/Cargo.toml @@ -18,6 +18,7 @@ members = [ "cognitosync", "concurrency", "config", + "custom-root-certificates", "dynamodb", "ebs", "ec2", diff --git a/rustv1/examples/custom-root-certificates/Cargo.toml b/rustv1/examples/custom-root-certificates/Cargo.toml index c242a9c2f49..93c4215df8e 100644 --- a/rustv1/examples/custom-root-certificates/Cargo.toml +++ b/rustv1/examples/custom-root-certificates/Cargo.toml @@ -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"] } diff --git a/rustv1/examples/custom-root-certificates/src/main.rs b/rustv1/examples/custom-root-certificates/src/main.rs index c762f6600ec..162c26af567 100644 --- a/rustv1/examples/custom-root-certificates/src/main.rs +++ b/rustv1/examples/custom-root-certificates/src/main.rs @@ -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() { @@ -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)