Skip to content

Commit

Permalink
feat: Add FileRead and HttpSend (#484)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Sep 19, 2024
1 parent 148dd1f commit e56eecb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repository = "https://github.com/Xuanwo/reqsign"
anyhow = "1"
async-trait = "0.1"
base64 = "0.22"
bytes = "1"
chrono = "0.4.35"
criterion = { version = "0.5", features = ["async_tokio", "html_reports"] }
dotenv = "0.15"
Expand Down
1 change: 1 addition & 0 deletions crates/reqsign/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repository.workspace = true
anyhow.workspace = true
async-trait.workspace = true
base64.workspace = true
bytes.workspace = true
chrono.workspace = true
form_urlencoded.workspace = true
hex.workspace = true
Expand Down
10 changes: 10 additions & 0 deletions crates/reqsign/src/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use anyhow::Result;

/// FileRead is used to read the file content entirely in `Vec<u8>`.
///
/// This could be used by `Load` to load the credential from the file.
#[async_trait::async_trait]
pub trait FileRead {
/// Read the file content entirely in `Vec<u8>`.
async fn file_read(&self, path: &str) -> Result<Vec<u8>>;
}
12 changes: 12 additions & 0 deletions crates/reqsign/src/http.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use anyhow::Result;
use bytes::Bytes;

/// HttpSend is used to send http request during the signing process.
///
/// For example, fetch IMDS token from AWS or OAuth2 refresh token. This trait is designed
/// especially for the signer, please don't use it as a general http client.
#[async_trait::async_trait]
pub trait HttpSend {
/// Send http request and return the response.
async fn http_send(&self, req: http::Request<Bytes>) -> Result<http::Response<Bytes>>;
}
5 changes: 5 additions & 0 deletions crates/reqsign/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ pub use sign::*;
pub mod dirs;
pub mod hash;
pub mod time;

mod fs;
pub use fs::FileRead;
mod http;
pub use http::HttpSend;

0 comments on commit e56eecb

Please sign in to comment.