Skip to content

Commit

Permalink
deps: bump reqwest, chrone, rust-ini (#430)
Browse files Browse the repository at this point in the history
This PR bumps reqwest (and by extension the rest of the hyper / http
ecosustem to 1.0).

Note that I have also moved construction of the request out of the
signing benchmark since the new API requires that we convert all the
headers to strings which impacts the results. So now the bench is only
the actual signing itself plus a clone of the processed headers.

---------

Signed-off-by: Xuanwo <[email protected]>
Co-authored-by: Xuanwo <[email protected]>
  • Loading branch information
arlyon and Xuanwo authored Mar 26, 2024
1 parent 3f825ee commit 79437aa
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 292 deletions.
57 changes: 30 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ reqwest_request = ["dep:reqwest"]

# services that reqsign supports
services-all = [
"services-aliyun",
"services-aws",
"services-azblob",
"services-google",
"services-huaweicloud",
"services-oracle",
"services-tencent",
"services-aliyun",
"services-aws",
"services-azblob",
"services-google",
"services-huaweicloud",
"services-oracle",
"services-tencent",
]

services-aliyun = [
"dep:reqwest",
"dep:serde",
"dep:serde_json",
"dep:once_cell",
"dep:reqwest",
"dep:serde",
"dep:serde_json",
"dep:once_cell",
]
services-aws = [
"dep:reqwest",
"dep:serde",
"dep:serde_json",
"dep:quick-xml",
"dep:rust-ini",
"dep:reqwest",
"dep:serde",
"dep:serde_json",
"dep:quick-xml",
"dep:rust-ini",
]
services-azblob = ["dep:serde", "dep:serde_json", "dep:reqwest"]
services-google = [
"dep:reqwest",
"dep:serde",
"dep:serde_json",
"dep:jsonwebtoken",
"dep:rsa",
"dep:reqwest",
"dep:serde",
"dep:serde_json",
"dep:jsonwebtoken",
"dep:rsa",
]
services-huaweicloud = ["dep:serde", "dep:serde_json", "dep:once_cell"]
services-oracle = ["dep:reqwest", "dep:rsa", "dep:toml", "dep:serde"]
Expand All @@ -66,20 +66,20 @@ name = "aws"
anyhow = "1"
async-trait = "0.1"
base64 = "0.22"
chrono = "0.4.24"
chrono = "0.4.35"
form_urlencoded = "1"
hex = "0.4"
hmac = "0.12"
http = "0.2"
http = "1.1"
jsonwebtoken = { version = "9.2", optional = true }
log = "0.4"
once_cell = { version = "1", optional = true }
percent-encoding = "2"
quick-xml = { version = "0.31", features = ["serialize"], optional = true }
rand = "0.8.5"
reqwest = { version = "0.11", default-features = false, optional = true }
reqwest = { version = "0.12", default-features = false, optional = true }
rsa = { version = "0.9.2", features = ["pkcs5", "sha2"], optional = true }
rust-ini = { version = "0.20", optional = true }
rust-ini = { version = "0.21", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
sha1 = "0.10"
Expand All @@ -95,13 +95,16 @@ getrandom = { version = "0.2", features = ["js"] }
tokio = { version = "1", optional = true }

[dev-dependencies]
aws-sigv4 = "0.56"
aws-credential-types = "1.1.8"
aws-sigv4 = "1.2.0"
criterion = { version = "0.5", features = ["async_tokio", "html_reports"] }
dotenv = "0.15"
env_logger = "0.11"
macro_rules_attribute = "0.2.0"
once_cell = "1"
pretty_assertions = "1.3"
reqwest = { version = "0.11", features = ["blocking", "json"] }
reqwest = { version = "0.12", features = ["blocking", "json"] }
temp-env = "0.3"
tempfile = "3.8"
test-case = "3.3.1"
tokio = { version = "1", features = ["full"] }
47 changes: 32 additions & 15 deletions benches/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use aws_sigv4::http_request::PercentEncodingMode;
use aws_sigv4::http_request::SignableBody;
use aws_sigv4::http_request::SignableRequest;
use aws_sigv4::http_request::SigningSettings;
use aws_sigv4::SigningParams;
use aws_sigv4::sign::v4::SigningParams;
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
Expand Down Expand Up @@ -43,30 +43,47 @@ pub fn bench(c: &mut Criterion) {
ss.percent_encoding_mode = PercentEncodingMode::Single;
ss.payload_checksum_kind = PayloadChecksumKind::XAmzSha256;

let credentials = aws_credential_types::Credentials::new(
"access_key_id".to_string(),
"secret_access_key".to_string(),
None,
None,
"test",
)
.into();

let sp = SigningParams::builder()
.access_key("access_key_id")
.secret_key("secret_access_key")
.identity(&credentials)
.region("test")
.service_name("s3")
.name("s3")
.time(SystemTime::now())
.settings(ss)
.build()
.expect("signing params must be valid");
.expect("signing params must be valid")
.into();

b.iter(|| {
let mut req = http::Request::new("");
*req.method_mut() = http::Method::GET;
*req.uri_mut() = "http://127.0.0.1:9000/hello"
.parse()
.expect("url must be valid");
let mut req = http::Request::new("");
*req.method_mut() = http::Method::GET;
*req.uri_mut() = "http://127.0.0.1:9000/hello"
.parse()
.expect("url must be valid");
let method = req.method().as_str();
let uri = req.uri().to_string();
let headers = req
.headers()
.iter()
.map(|(k, v)| (k.as_str(), std::str::from_utf8(v.as_bytes()).unwrap()))
.collect::<Vec<_>>();

b.iter(|| {
let _ = aws_sigv4::http_request::sign(
SignableRequest::new(
req.method(),
req.uri(),
req.headers(),
method,
uri.as_str(),
headers.clone().into_iter(),
SignableBody::UnsignedPayload,
),
)
.unwrap(),
&sp,
)
.expect("signing must succeed");
Expand Down
4 changes: 2 additions & 2 deletions src/aliyun/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Credential {
// Take 120s as buffer to avoid edge cases.
if let Some(valid) = self
.expires_in
.map(|v| v > now() + chrono::Duration::minutes(2))
.map(|v| v > now() + chrono::TimeDelta::try_minutes(2).expect("in bounds"))
{
return valid;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ impl Loader {
security_token: self.config.security_token.clone(),
// Set expires_in to 10 minutes to enforce re-read
// from file.
expires_in: Some(now() + chrono::Duration::minutes(10)),
expires_in: Some(now() + chrono::TimeDelta::try_minutes(10).expect("in bounds")),
}))
} else {
Ok(None)
Expand Down
4 changes: 2 additions & 2 deletions src/aliyun/oss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Signer {
ctx.query_push("OSSAccessKeyId", &cred.access_key_id);
ctx.query_push(
"Expires",
(now + chrono::Duration::from_std(expire).unwrap())
(now + chrono::TimeDelta::from_std(expire).unwrap())
.timestamp()
.to_string(),
);
Expand Down Expand Up @@ -135,7 +135,7 @@ fn string_to_sign(
writeln!(
&mut s,
"{}",
(now + chrono::Duration::from_std(expires).unwrap()).timestamp()
(now + chrono::TimeDelta::from_std(expires).unwrap()).timestamp()
)?;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/aws/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Credential {
// Take 120s as buffer to avoid edge cases.
if let Some(valid) = self
.expires_in
.map(|v| v > now() + chrono::Duration::minutes(2))
.map(|v| v > now() + chrono::TimeDelta::try_minutes(2).expect("in bounds"))
{
return valid;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ impl DefaultLoader {
session_token: self.config.session_token.clone(),
// Set expires_in to 10 minutes to enforce re-read
// from file.
expires_in: Some(now() + chrono::Duration::minutes(10)),
expires_in: Some(now() + chrono::TimeDelta::try_minutes(10).expect("in bounds")),
}))
} else {
Ok(None)
Expand Down Expand Up @@ -356,7 +356,8 @@ impl IMDSv2Loader {
}
let ec2_token = resp.text().await?;
// Set expires_in to 10 minutes to enforce re-read.
let expires_in = now() + chrono::Duration::seconds(21600) - chrono::Duration::seconds(600);
let expires_in = now() + chrono::TimeDelta::try_seconds(21600).expect("in bounds")
- chrono::TimeDelta::try_seconds(600).expect("in bounds");

{
*self.token.lock().expect("lock poisoned") = (ec2_token.clone(), expires_in);
Expand Down
Loading

0 comments on commit 79437aa

Please sign in to comment.