Skip to content

Commit

Permalink
[smithy-rs] Move using-native-tls-instead-of-rustls to smithy-rs (#2423)
Browse files Browse the repository at this point in the history
* Move using-native-tls-instead-of-rustls to smithy-rs

This commit adds the test `using-native-tls-instead-of-rustls` to
`smithy-rs` that was originally in the `aws-doc-sdk-examples`.
The test is more useful to be in `smithy-rs` because it can catch
a test failure early prior to cutting a release.

* Fix Copyright header

* Update aws/sdk/integration-tests/using-native-tls-instead-of-rustls/tests/no-rustls-in-dependency.rs

Co-authored-by: Zelda Hessler <zhessler@amazon.com>

* Update aws/sdk/integration-tests/using-native-tls-instead-of-rustls/tests/no-rustls-in-dependency.rs

Co-authored-by: Zelda Hessler <zhessler@amazon.com>

* Update Cargo.toml

This commit addresses
smithy-lang/smithy-rs#2423 (comment)
smithy-lang/smithy-rs#2423 (comment)

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
Co-authored-by: Zelda Hessler <zhessler@amazon.com>
  • Loading branch information
3 people authored and aws-sdk-rust-ci committed Mar 30, 2023
1 parent 2132228 commit a1b8e36
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
exclude = [
"tests/no-default-features"
"tests/no-default-features",
"tests/using-native-tls-instead-of-rustls"
]
members = [
"examples/apigateway",
Expand Down
4 changes: 2 additions & 2 deletions sdk/kinesis/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ impl DeregisterStreamConsumerInput {
.set_endpoint(_config.endpoint_url
.clone())
.set_operation_type(Some("control".to_string()))
.set_stream_arn(self.stream_arn.clone())
.set_consumer_arn(self.consumer_arn.clone()).build()
.set_consumer_arn(self.consumer_arn.clone())
.set_stream_arn(self.stream_arn.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down
60 changes: 30 additions & 30 deletions sdk/s3control/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ impl CreateAccessPointInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -179,8 +179,8 @@ impl CreateBucketInput {
.set_endpoint(_config.endpoint_url
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_bucket(self.bucket.clone())
.set_outpost_id(self.outpost_id.clone()).build()
.set_outpost_id(self.outpost_id.clone())
.set_bucket(self.bucket.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -447,8 +447,8 @@ impl DeleteAccessPointInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_account_id(self.account_id.clone())
.set_access_point_name(self.name.clone()).build()
.set_access_point_name(self.name.clone())
.set_account_id(self.account_id.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -606,8 +606,8 @@ impl DeleteAccessPointPolicyInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_access_point_name(self.name.clone())
.set_account_id(self.account_id.clone()).build()
.set_account_id(self.account_id.clone())
.set_access_point_name(self.name.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -765,8 +765,8 @@ impl DeleteBucketInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -925,8 +925,8 @@ impl DeleteBucketPolicyInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -1005,8 +1005,8 @@ impl DeleteBucketTaggingInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -1895,8 +1895,8 @@ impl GetAccessPointPolicyInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_access_point_name(self.name.clone())
.set_account_id(self.account_id.clone()).build()
.set_account_id(self.account_id.clone())
.set_access_point_name(self.name.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -2213,8 +2213,8 @@ impl GetBucketInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -2293,8 +2293,8 @@ impl GetBucketLifecycleConfigurationInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -3284,8 +3284,8 @@ impl ListAccessPointsInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -3655,8 +3655,8 @@ impl ListRegionalBucketsInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_account_id(self.account_id.clone())
.set_outpost_id(self.outpost_id.clone()).build()
.set_outpost_id(self.outpost_id.clone())
.set_account_id(self.account_id.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -3908,8 +3908,8 @@ impl PutAccessPointPolicyInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_access_point_name(self.name.clone())
.set_account_id(self.account_id.clone()).build()
.set_account_id(self.account_id.clone())
.set_access_point_name(self.name.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -4075,8 +4075,8 @@ impl PutBucketLifecycleConfigurationInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down Expand Up @@ -4171,8 +4171,8 @@ impl PutBucketPolicyInput {
.clone())
.set_use_arn_region(_config.use_arn_region)
.set_requires_account_id(Some(true))
.set_account_id(self.account_id.clone())
.set_bucket(self.bucket.clone()).build()
.set_bucket(self.bucket.clone())
.set_account_id(self.account_id.clone()).build()
.map_err(|err|aws_smithy_http::endpoint::ResolveEndpointError::from_source("could not construct endpoint parameters", err));
let (endpoint_result, params) = match params_result {
Ok(params) => (_config.endpoint_resolver.resolve_endpoint(&params), Some(params)),
Expand Down
21 changes: 21 additions & 0 deletions tests/using-native-tls-instead-of-rustls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
[package]
name = "using-native-tls-instead-of-rustls"
version = "0.1.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
edition = "2021"
[dev-dependencies.aws-config]
path = "../../sdk/aws-config"
default-features = false
features = ["native-tls", "rt-tokio"]
version = "0.0.0-smithy-rs-head"

[dev-dependencies.aws-sdk-s3]
path = "../../sdk/s3"
default-features = false
features = ["native-tls"]
version = "0.25.0"

[dev-dependencies.tokio]
version = "1.20.1"
features = ["rt", "macros"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/// The SDK defaults to using RusTLS by default but you can also use [`native_tls`](https://github.com/sfackler/rust-native-tls)
/// which will choose a TLS implementation appropriate for your platform. This test looks much like
/// any other. Activating and deactivating `features` in your app's `Cargo.toml` is all that's needed.
async fn list_buckets() -> Result<(), aws_sdk_s3::Error> {
let sdk_config = aws_config::load_from_env().await;
let client = aws_sdk_s3::Client::new(&sdk_config);

let _resp = client.list_buckets().send().await?;

Ok(())
}

/// You can run this test to ensure that it is only using `native-tls` and
/// that nothing is pulling in `rustls` as a dependency
#[test]
#[should_panic = "error: package ID specification `rustls` did not match any packages"]
fn test_rustls_is_not_in_dependency_tree() {
let cargo_location = std::env::var("CARGO").unwrap();
let cargo_command = std::process::Command::new(&cargo_location)
.arg("tree")
.arg("--invert")
.arg("rustls")
.output()
.expect("failed to run 'cargo tree'");

let stderr = String::from_utf8_lossy(&cargo_command.stderr);

// We expect the call to `cargo tree` to error out. If it did, we panic with the resulting
// message here. In the case that no error message is set, that's bad.
if !stderr.is_empty() {
panic!("{}", stderr);
}

// Uh oh. We expected an error message but got none, likely because `cargo tree` found
// `rustls` in our dependencies. We'll print out the message we got to see what went wrong.
let stdout = String::from_utf8_lossy(&cargo_command.stdout);

println!("{}", stdout)
}

// NOTE: not currently run in CI, separate PR will set up a with-creds CI runner
#[tokio::test]
#[ignore]
async fn needs_creds_native_tls_works() {
list_buckets().await.expect("should succeed")
}
6 changes: 3 additions & 3 deletions versions.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
smithy_rs_revision = '049287db3c9b12510f42e7dd16cd08f69ab91b9d'
smithy_rs_revision = '7ebfbccfd7e3931c8a4a286e64b98c7894f278ea'
aws_doc_sdk_examples_revision = '97a177aab8c3d2fef97416cb66e4b4d0da840138'

[manual_interventions]
Expand Down Expand Up @@ -1057,7 +1057,7 @@ model_hash = '9ec8a92782fbef7e2cf07fc9b5e656aa37b59668baff33acae10f270cfff4193'
[crates.aws-sdk-kinesis]
category = 'AwsSdk'
version = '0.25.0'
source_hash = 'd8a54f1d6a69b5c264b7e463a03b61b2b102de92c5d77e0f3329043cbe3a6cd5'
source_hash = '325793b25c5ea997207a938da73195aa8f4a50ad977c1cb022e06aaaee2ea6e2'
model_hash = '5eaef8321cea414140d87258e714988d88f3e41d9cdf4b83a1417027cb702cb9'

[crates.aws-sdk-kinesisanalytics]
Expand Down Expand Up @@ -1669,7 +1669,7 @@ model_hash = 'fb47cfd49cf2d9250063914599f703ed365b51be373988dc3f2cd64321c9583b'
[crates.aws-sdk-s3control]
category = 'AwsSdk'
version = '0.25.0'
source_hash = 'c8afde98bc87009f3f7f26fb7025a989ad0c57e0dd4383594374a0e423f18a27'
source_hash = '404259e73d56d443dfad7941181e4eb5bdf2d483abda2c28356783b4fb1d197c'
model_hash = '930bd33c05c393293591ae01cbdb6637fb5062ed3a3ad5e2dadddd8108cc8478'

[crates.aws-sdk-s3outposts]
Expand Down

0 comments on commit a1b8e36

Please sign in to comment.