Skip to content

Commit

Permalink
Update to GA release of Rust SDK
Browse files Browse the repository at this point in the history
Signed-off-by: James Bornholt <jamesbornholt@gmail.com>
Signed-off-by: James Bornholt <bornholt@amazon.com>
  • Loading branch information
jamesbornholt committed Feb 5, 2024
1 parent dea8a68 commit bb7e5bf
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 244 deletions.
494 changes: 296 additions & 198 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions mountpoint-s3-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ rand_chacha = { version = "0.3.1", optional = true }

[dev-dependencies]
anyhow = { version = "1.0.64", features = ["backtrace"] }
aws-config = "0.56.0"
aws-credential-types = "0.56.0"
aws-sdk-s3 = "0.30.0"
aws-sdk-sts = "0.30.0"
aws-smithy-runtime-api = "0.56.1"
aws-config = "1.1.4"
aws-credential-types = "1.1.4"
aws-sdk-s3 = "1.14.0"
aws-sdk-sts = "1.12.0"
aws-smithy-runtime-api = "1.1.4"
bytes = "1.2.1"
clap = { version = "4.1.9", features = ["derive"] }
ctor = "0.2.6"
Expand Down
10 changes: 6 additions & 4 deletions mountpoint-s3-client/tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::io::Write;
use std::option::Option::None;

use aws_config::default_provider::credentials::DefaultCredentialsChain;
#[cfg(not(feature = "s3express_tests"))]
use aws_config::BehaviorVersion;
use aws_credential_types::provider::ProvideCredentials;
use aws_sdk_s3::config::Region;
use aws_sdk_s3::primitives::ByteStream;
Expand Down Expand Up @@ -220,7 +222,7 @@ async fn test_scoped_credentials() {
.unwrap();
}

let config = aws_config::from_env()
let config = aws_config::defaults(BehaviorVersion::latest())
.region(Region::new(get_test_region()))
.load()
.await;
Expand All @@ -246,9 +248,9 @@ async fn test_scoped_credentials() {

// Build a S3CrtClient that uses a static credentials provider with the creds we just got
let config = CredentialsProviderStaticOptions {
access_key_id: credentials.access_key_id().unwrap(),
secret_access_key: credentials.secret_access_key().unwrap(),
session_token: credentials.session_token(),
access_key_id: credentials.access_key_id(),
secret_access_key: credentials.secret_access_key(),
session_token: Some(credentials.session_token()),
};
let provider = CredentialsProvider::new_static(&Allocator::default(), config).unwrap();
let config = S3ClientConfig::new()
Expand Down
8 changes: 5 additions & 3 deletions mountpoint-s3-client/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(feature = "s3_tests")]

use aws_config::BehaviorVersion;
use aws_sdk_s3 as s3;
use aws_sdk_s3::config::Region;
use aws_sdk_s3::error::SdkError;
Expand Down Expand Up @@ -114,7 +115,7 @@ pub fn get_s3express_endpoint() -> String {
}

pub async fn get_test_sdk_client() -> s3::Client {
let mut config = aws_config::from_env().region(Region::new(get_test_region()));
let mut config = aws_config::defaults(BehaviorVersion::latest()).region(Region::new(get_test_region()));
if cfg!(feature = "s3express_tests") {
config = config.endpoint_url(get_s3express_endpoint());
}
Expand Down Expand Up @@ -157,8 +158,9 @@ pub async fn get_mpu_count_for_key(
.send()
.await?
.uploads()
.map(|upload| upload.iter().filter(|&u| u.key() == Some(key)).collect::<Vec<_>>())
.map_or(0, |u| u.len());
.iter()
.filter(|&u| u.key() == Some(key))
.count();

Ok(upload_count)
}
Expand Down
5 changes: 4 additions & 1 deletion mountpoint-s3-client/tests/head_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ async fn test_head_object_restored() {
RestoreRequest::builder()
.set_days(Some(1))
.set_glacier_job_parameters(Some(
GlacierJobParameters::builder().set_tier(Some(Tier::Expedited)).build(),
GlacierJobParameters::builder()
.set_tier(Some(Tier::Expedited))
.build()
.unwrap(),
))
.build(),
)
Expand Down
4 changes: 2 additions & 2 deletions mountpoint-s3-client/tests/imds_crt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use serde_json::Value;

#[tokio::test]
async fn test_get_identity_document() {
let sdk_client = Client::builder().build().await.unwrap();
let sdk_client = Client::builder().build();
match sdk_client.get("/latest/dynamic/instance-identity/document").await {
Ok(expected_json) => {
let expected_doc: Value = serde_json::from_str(&expected_json).unwrap();
let expected_doc: Value = serde_json::from_str(expected_json.as_ref()).unwrap();
let expected_region = expected_doc.get("region").unwrap().as_str().unwrap();
let expected_instance_type = expected_doc.get("instanceType").unwrap().as_str().unwrap();

Expand Down
2 changes: 1 addition & 1 deletion mountpoint-s3-client/tests/put_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async fn test_put_checksums() {
.send()
.await
.unwrap();
let parts = attributes.object_parts().unwrap().parts().unwrap();
let parts = attributes.object_parts().unwrap().parts();
let checksums: Vec<_> = parts.iter().map(|p| p.checksum_crc32_c().unwrap()).collect();
let expected_checksums: Vec<_> = contents.chunks(PART_SIZE).map(crc32c::checksum).collect();

Expand Down
6 changes: 3 additions & 3 deletions mountpoint-s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ mountpoint-s3-client = { path = "../mountpoint-s3-client", features = ["mock"] }

assert_cmd = "2.0.6"
assert_fs = "1.1.1"
aws-config = "0.56.0"
aws-sdk-s3 = "0.30.0"
aws-sdk-sts = "0.30.0"
aws-config = "1.1.4"
aws-sdk-s3 = "1.14.0"
aws-sdk-sts = "1.12.0"
base16ct = { version = "0.1.1", features = ["alloc"] }
ctor = "0.2.6"
filetime = "0.2.21"
Expand Down
24 changes: 5 additions & 19 deletions mountpoint-s3/tests/common/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ pub mod mock_session {
pub mod s3_session {
use super::*;

use aws_config::BehaviorVersion;
use aws_sdk_s3::config::Region;
use aws_sdk_s3::operation::head_object::HeadObjectError;
use aws_sdk_s3::primitives::ByteStream;
Expand Down Expand Up @@ -325,7 +326,7 @@ pub mod s3_session {
}

async fn get_test_sdk_client(region: &str) -> aws_sdk_s3::Client {
let mut config = aws_config::from_env().region(Region::new(region.to_owned()));
let mut config = aws_config::defaults(BehaviorVersion::latest()).region(Region::new(region.to_owned()));
if cfg!(feature = "s3express_tests") {
config = config.endpoint_url(get_s3express_endpoint());
}
Expand Down Expand Up @@ -388,11 +389,7 @@ pub mod s3_session {
}

tokio_block_on(request.delimiter('/').prefix(full_key_suffixed).send())
.map(|output| {
let len = output.contents().map(|c| c.len()).unwrap_or_default()
+ output.common_prefixes().map(|c| c.len()).unwrap_or_default();
len > 0
})
.map(|output| !(output.contents().is_empty() && output.common_prefixes().is_empty()))
.map_err(|e| Box::new(e) as Box<dyn std::error::Error>)
}

Expand Down Expand Up @@ -420,18 +417,7 @@ pub mod s3_session {
}

tokio_block_on(request.prefix(self.prefix.clone()).send())
.map(|output| {
output
.uploads()
.map(|upload| {
upload
.iter()
.filter(|&u| u.key().unwrap().ends_with(key))
.collect::<Vec<_>>()
})
.map_or(0, |u| u.len())
> 0
})
.map(|output| output.uploads().iter().any(|u| u.key().unwrap().ends_with(key)))
.map_err(|e| Box::new(e) as Box<dyn std::error::Error>)
}

Expand Down Expand Up @@ -466,7 +452,7 @@ pub mod s3_session {
RestoreRequest::builder()
.set_days(Some(1))
.set_glacier_job_parameters(Some(
GlacierJobParameters::builder().set_tier(Some(tier)).build(),
GlacierJobParameters::builder().set_tier(Some(tier)).build()?,
))
.build(),
))
Expand Down
3 changes: 2 additions & 1 deletion mountpoint-s3/tests/common/s3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aws_config::BehaviorVersion;
use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_sts::config::Region;
use futures::Future;
Expand Down Expand Up @@ -41,7 +42,7 @@ pub fn get_s3express_endpoint() -> String {
}

pub fn create_objects(bucket: &str, prefix: &str, region: &str, key: &str, value: &[u8]) {
let mut config = aws_config::from_env().region(Region::new(region.to_string()));
let mut config = aws_config::defaults(BehaviorVersion::latest()).region(Region::new(region.to_string()));
if cfg!(feature = "s3express_tests") {
config = config.endpoint_url(get_s3express_endpoint());
}
Expand Down
20 changes: 13 additions & 7 deletions mountpoint-s3/tests/fuse_tests/fork_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use assert_cmd::prelude::*;
#[cfg(not(feature = "s3express_tests"))]
use aws_config::BehaviorVersion;
#[cfg(not(feature = "s3express_tests"))]
use aws_sdk_sts::config::Region;
use std::fs;
use std::io::{BufRead, BufReader};
Expand Down Expand Up @@ -320,7 +322,11 @@ fn mount_scoped_credentials() -> Result<(), Box<dyn std::error::Error>> {
{"Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::__BUCKET__", "Condition": {"StringLike": {"s3:prefix": "__PREFIX__*"}}}
]}"#;
let policy = policy.replace("__BUCKET__", &bucket).replace("__PREFIX__", &subprefix);
let config = tokio_block_on(aws_config::from_env().region(Region::new(get_test_region())).load());
let config = tokio_block_on(
aws_config::defaults(BehaviorVersion::latest())
.region(Region::new(get_test_region()))
.load(),
);
let sts_client = aws_sdk_sts::Client::new(&config);
let credentials = tokio_block_on(
sts_client
Expand All @@ -341,9 +347,9 @@ fn mount_scoped_credentials() -> Result<(), Box<dyn std::error::Error>> {
.arg(format!("--prefix={prefix}"))
.arg("--auto-unmount")
.arg(format!("--region={region}"))
.env("AWS_ACCESS_KEY_ID", credentials.access_key_id().unwrap())
.env("AWS_SECRET_ACCESS_KEY", credentials.secret_access_key().unwrap())
.env("AWS_SESSION_TOKEN", credentials.session_token().unwrap())
.env("AWS_ACCESS_KEY_ID", credentials.access_key_id())
.env("AWS_SECRET_ACCESS_KEY", credentials.secret_access_key())
.env("AWS_SESSION_TOKEN", credentials.session_token())
.spawn()
.expect("unable to spawn child");

Expand All @@ -361,9 +367,9 @@ fn mount_scoped_credentials() -> Result<(), Box<dyn std::error::Error>> {
.arg(format!("--prefix={subprefix}"))
.arg("--auto-unmount")
.arg(format!("--region={region}"))
.env("AWS_ACCESS_KEY_ID", credentials.access_key_id().unwrap())
.env("AWS_SECRET_ACCESS_KEY", credentials.secret_access_key().unwrap())
.env("AWS_SESSION_TOKEN", credentials.session_token().unwrap())
.env("AWS_ACCESS_KEY_ID", credentials.access_key_id())
.env("AWS_SECRET_ACCESS_KEY", credentials.secret_access_key())
.env("AWS_SESSION_TOKEN", credentials.session_token())
.spawn()
.expect("unable to spawn child");

Expand Down

0 comments on commit bb7e5bf

Please sign in to comment.