aboutsummaryrefslogtreecommitdiff
path: root/src/api/signature/streaming.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2024-02-07 14:59:40 +0000
committerAlex <alex@adnab.me>2024-02-07 14:59:40 +0000
commit5d941e0100489fff552b59f0679a2a010403a21c (patch)
tree5c5cef9af72d48dd7347922341e43f0013380c60 /src/api/signature/streaming.rs
parentfeeb076b7f5db7fe6fdbe3d2903fae054cde6219 (diff)
parente011941964b1c1e0b90f85014d166d64a83ae8e2 (diff)
downloadgarage-5d941e0100489fff552b59f0679a2a010403a21c.tar.gz
garage-5d941e0100489fff552b59f0679a2a010403a21c.zip
Merge pull request 'Dependency upgrades: http, hyper, aws-sdk, smaller deps' (#703) from dep-upgrade-202402 into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/703
Diffstat (limited to 'src/api/signature/streaming.rs')
-rw-r--r--src/api/signature/streaming.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/api/signature/streaming.rs b/src/api/signature/streaming.rs
index c8358c4f..39147ca0 100644
--- a/src/api/signature/streaming.rs
+++ b/src/api/signature/streaming.rs
@@ -1,26 +1,30 @@
use std::pin::Pin;
-use chrono::{DateTime, NaiveDateTime, Utc};
+use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use futures::prelude::*;
use futures::task;
use garage_model::key_table::Key;
use hmac::Mac;
-use hyper::body::Bytes;
-use hyper::{Body, Request};
+use http_body_util::StreamBody;
+use hyper::body::{Bytes, Incoming as IncomingBody};
+use hyper::Request;
use garage_util::data::Hash;
use super::{compute_scope, sha256sum, HmacSha256, LONG_DATETIME};
+use crate::helpers::*;
use crate::signature::error::*;
+pub type ReqBody = BoxBody<Error>;
+
pub fn parse_streaming_body(
api_key: &Key,
- req: Request<Body>,
+ req: Request<IncomingBody>,
content_sha256: &mut Option<Hash>,
region: &str,
service: &str,
-) -> Result<Request<Body>, Error> {
+) -> Result<Request<ReqBody>, Error> {
match req.headers().get("x-amz-content-sha256") {
Some(header) if header == "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" => {
let signature = content_sha256
@@ -40,26 +44,22 @@ pub fn parse_streaming_body(
.to_str()?;
let date: NaiveDateTime = NaiveDateTime::parse_from_str(date, LONG_DATETIME)
.ok_or_bad_request("Invalid date")?;
- let date: DateTime<Utc> = DateTime::from_utc(date, Utc);
+ let date: DateTime<Utc> = Utc.from_utc_datetime(&date);
let scope = compute_scope(&date, region, service);
let signing_hmac = crate::signature::signing_hmac(&date, secret_key, region, service)
.ok_or_internal_error("Unable to build signing HMAC")?;
Ok(req.map(move |body| {
- Body::wrap_stream(
- SignedPayloadStream::new(
- body.map_err(Error::from),
- signing_hmac,
- date,
- &scope,
- signature,
- )
- .map_err(Error::from),
- )
+ let stream = body_stream::<_, Error>(body);
+ let signed_payload_stream =
+ SignedPayloadStream::new(stream, signing_hmac, date, &scope, signature)
+ .map(|x| x.map(hyper::body::Frame::data))
+ .map_err(Error::from);
+ ReqBody::new(StreamBody::new(signed_payload_stream))
}))
}
- _ => Ok(req),
+ _ => Ok(req.map(|body| ReqBody::new(http_body_util::BodyExt::map_err(body, Error::from)))),
}
}