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

refactor(services/s3): Migrate to async reqsign #1909

Merged
merged 7 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ extern crate napi_derive;

use std::collections::HashMap;
use std::str::FromStr;
use std::time::Duration;

use futures::TryStreamExt;
use napi::bindgen_prelude::*;
use time::format_description::well_known::Rfc3339;
use time::Duration;

fn build_operator(
scheme: opendal::Scheme,
Expand Down Expand Up @@ -487,7 +487,7 @@ impl Operator {
pub async fn presign_read(&self, path: String, expires: u32) -> Result<PresignedRequest> {
let res = self
.0
.presign_read(&path, Duration::seconds(expires as i64))
.presign_read(&path, Duration::from_secs(expires as u64))
.await
.map_err(format_napi_error)?;
Ok(PresignedRequest::new(res))
Expand All @@ -510,7 +510,7 @@ impl Operator {
pub async fn presign_write(&self, path: String, expires: u32) -> Result<PresignedRequest> {
let res = self
.0
.presign_write(&path, Duration::seconds(expires as i64))
.presign_write(&path, Duration::from_secs(expires as u64))
.await
.map_err(format_napi_error)?;
Ok(PresignedRequest::new(res))
Expand All @@ -533,7 +533,7 @@ impl Operator {
pub async fn presign_stat(&self, path: String, expires: u32) -> Result<PresignedRequest> {
let res = self
.0
.presign_stat(&path, Duration::seconds(expires as i64))
.presign_stat(&path, Duration::from_secs(expires as u64))
.await
.map_err(format_napi_error)?;
Ok(PresignedRequest::new(res))
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ redis = { version = "0.22", features = [
], optional = true }
# NOTE: we keep this for service migration one by one. And finally we will replace reqsign by v0.9.
reqsign = "0.8.5"
reqsign_0_9 = { package = "reqsign", git = "https://github.com/Xuanwo/reqsign", rev = "877292a171bfec9593df27cb4ec94676e77a9d57" }
reqsign_0_9 = { package = "reqsign", git = "https://github.com/Xuanwo/reqsign", rev = "686d2971e6fc0f6a56467fbb52e660164d761be2" }
reqwest = { version = "0.11.13", features = [
"multipart",
"stream",
Expand Down
13 changes: 13 additions & 0 deletions core/src/raw/http_util/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use http::header::ETAG;
use http::header::LAST_MODIFIED;
use http::header::LOCATION;
use http::HeaderMap;
use http::HeaderValue;
use md5::Digest;
use time::format_description::well_known::Rfc2822;
use time::OffsetDateTime;
Expand Down Expand Up @@ -273,6 +274,18 @@ pub fn format_authorization_by_bearer(token: &str) -> Result<String> {
Ok(format!("Bearer {token}"))
}

/// Build header value from given string.
pub fn build_header_value(v: &str) -> Result<HeaderValue> {
HeaderValue::from_str(v).map_err(|e| {
Error::new(
ErrorKind::ConfigInvalid,
"header value contains invalid characters",
)
.with_operation("http_util::build_header_value")
.set_source(e)
})
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions core/src/raw/http_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use body::AsyncBody;
pub use body::IncomingAsyncBody;

mod header;
pub use header::build_header_value;
pub use header::format_authorization_by_basic;
pub use header::format_authorization_by_bearer;
pub use header::format_content_md5;
Expand Down
6 changes: 5 additions & 1 deletion core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,11 @@ impl Accessor for OssBackend {
};

self.signer
.sign_query(&mut req, args.expire())
.sign_query(
&mut req,
// TODO: convert to std::time::Duration
time::Duration::seconds_f64(args.expire().as_secs_f64()),
)
.map_err(new_request_sign_error)?;

// We don't need this request anymore, consume it directly.
Expand Down
Loading