Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7e5ecb7
Author: durch <durch@users.noreply.github.com>
Date:   Fri Mar 4 10:02:37 2022 +0100

    cargo fmt

commit d7f3ee7
Author: castaneai <castaneai@castaneai.net>
Date:   Fri Mar 4 17:57:31 2022 +0900

    Providing more detailed error when the put API fails (#257)

    * s3 0.29.0 (#253)

    * cargo: Move `tokio-stream` create behind the `with-tokio` feature (#248)

    `tokio-stream` has a dependency on `tokio` and is only used within the
    `request` module, which depends on the `with-tokio` feature.  As such,
    in order to completely prevent `tokio` from appearing in the crate
    graph, this crate must be marked optional and enabled when `with-tokio`
    is requested, omitted otherwise.

    Also includes two drive-by typo-fixes in the features section of the
    readme.

    * Fixup #248

    * Migrate from `chrono` to `time` to solve RUSTSEC-2020-0159 (#250)

    `chrono` still hasn't found a solution to [RUSTSEC-2020-0159] whereas
    `time` already solved its vulnerability to [RUSTSEC-2020-0071] by hiding
    the affected functionality behind a cfg flag (not to be confused with a
    `feature`, such `cfg`s can only be enabled through `RUSTFLAGS`).  At the
    same time `chrono` is a superset of `time` even though this crate hardly
    uses any functionality of it: only UTC time is needed which does not
    suffer from aforementioned local time vulnerabilities.

    [RUSTSEC-2020-0071]: https://rustsec.org/advisories/RUSTSEC-2020-0071
    [RUSTSEC-2020-0159]: https://rustsec.org/advisories/RUSTSEC-2020-0159

    Co-authored-by: Drazen Urch <drazen@urch.eu>

    * Update Makefile

    * Closes #245

    * Bump aws-region

    * s3 0.29.0

    Co-authored-by: Marijn Suijten <marijns95@gmail.com>

    * Provide better error information

    Co-authored-by: Drazen Urch <drazen@urch.eu>
    Co-authored-by: Marijn Suijten <marijns95@gmail.com>

commit 1259d34
Author: Marijn Suijten <marijn@traverseresearch.nl>
Date:   Fri Mar 4 09:56:18 2022 +0100

    aws-creds: Bump rust-ini to 0.18 (#256)

    Bumping rust-ini gets rid of a duplicate ordered-multimap for us.

commit c381ebf
Author: durch <durch@users.noreply.github.com>
Date:   Sat Feb 12 23:04:35 2022 +0100

    s3 0.29.0

commit ba783d2
Author: durch <durch@users.noreply.github.com>
Date:   Sat Feb 12 23:03:50 2022 +0100

    Bump aws-region

commit 8263e96
Author: durch <durch@users.noreply.github.com>
Date:   Sat Feb 12 22:47:17 2022 +0100

    Closes #245

commit c5a822c
Author: durch <durch@users.noreply.github.com>
Date:   Sat Feb 12 22:42:27 2022 +0100

    Update Makefile

commit a917f78
Author: Marijn Suijten <marijns95@gmail.com>
Date:   Sat Feb 12 22:38:54 2022 +0100

    Migrate from `chrono` to `time` to solve RUSTSEC-2020-0159 (#250)

    `chrono` still hasn't found a solution to [RUSTSEC-2020-0159] whereas
    `time` already solved its vulnerability to [RUSTSEC-2020-0071] by hiding
    the affected functionality behind a cfg flag (not to be confused with a
    `feature`, such `cfg`s can only be enabled through `RUSTFLAGS`).  At the
    same time `chrono` is a superset of `time` even though this crate hardly
    uses any functionality of it: only UTC time is needed which does not
    suffer from aforementioned local time vulnerabilities.

    [RUSTSEC-2020-0071]: https://rustsec.org/advisories/RUSTSEC-2020-0071
    [RUSTSEC-2020-0159]: https://rustsec.org/advisories/RUSTSEC-2020-0159

    Co-authored-by: Drazen Urch <drazen@urch.eu>

commit 10cf754
Author: durch <durch@users.noreply.github.com>
Date:   Sat Feb 12 22:37:42 2022 +0100

    Fixup #248

commit c1a174d
Author: Marijn Suijten <marijns95@gmail.com>
Date:   Sat Feb 12 22:07:58 2022 +0100

    cargo: Move `tokio-stream` create behind the `with-tokio` feature (#248)

    `tokio-stream` has a dependency on `tokio` and is only used within the
    `request` module, which depends on the `with-tokio` feature.  As such,
    in order to completely prevent `tokio` from appearing in the crate
    graph, this crate must be marked optional and enabled when `with-tokio`
    is requested, omitted otherwise.

    Also includes two drive-by typo-fixes in the features section of the
    readme.
  • Loading branch information
durch committed Mar 4, 2022
1 parent a2ac79c commit 8053540
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aws-creds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
dirs = "4"
rust-ini = "0.17"
rust-ini = "0.18"
attohttpc = { version = "0.18", default-features = false, features = ["json"], optional = true }
url = "2"
serde-xml-rs = "0.5"
Expand Down
12 changes: 11 additions & 1 deletion s3/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::serde_types::{
BucketLocationResult, CompleteMultipartUploadData, HeadObjectResult,
InitiateMultipartUploadResponse, ListBucketResult, ListMultipartUploadsResult, Part,
};
use crate::utils::error_from_response_data;
use anyhow::anyhow;
use anyhow::Result;
use http::header::HeaderName;
Expand Down Expand Up @@ -755,13 +756,19 @@ impl Bucket {
// Otherwise perform a multi-part upload.
let first_chunk = crate::utils::read_chunk(reader).await?;
if first_chunk.len() < CHUNK_SIZE {
let (_, code) = self.put_object(s3_path, first_chunk.as_slice()).await?;
let (data, code) = self.put_object(s3_path, first_chunk.as_slice()).await?;
if code >= 300 {
return Err(error_from_response_data(data, code));
}
return Ok(code);
}

let command = Command::InitiateMultipartUpload;
let request = RequestImpl::new(self, s3_path, command);
let (data, code) = request.response_data(false).await?;
if code >= 300 {
return Err(error_from_response_data(data, code));
}

let msg: InitiateMultipartUploadResponse =
serde_xml::from_str(std::str::from_utf8(data.as_slice())?)?;
Expand Down Expand Up @@ -820,6 +827,9 @@ impl Bucket {
let command = Command::InitiateMultipartUpload;
let request = RequestImpl::new(self, s3_path, command);
let (data, code) = request.response_data(false)?;
if code >= 300 {
return Err(error_from_response_data(data, code));
}
let msg: InitiateMultipartUploadResponse =
serde_xml::from_str(std::str::from_utf8(data.as_slice())?)?;

Expand Down
16 changes: 16 additions & 0 deletions s3/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ impl From<&http::HeaderMap> for HeadObjectResult {
}
}

pub(crate) fn error_from_response_data(data: Vec<u8>, code: u16) -> anyhow::Error {
let utf8_content = String::from_utf8(data);
let err = if let Ok(utf8_content) = utf8_content {
format!(
"Invalid return code: got HTTP {} with content '{}'",
code, utf8_content
)
} else {
format!(
"Invalid return code: got HTTP {} with invalid UTF8 content",
code
)
};
anyhow::Error::new(std::io::Error::new(std::io::ErrorKind::InvalidData, err))
}

#[cfg(test)]
mod test {
use crate::utils::etag_for_path;
Expand Down

0 comments on commit 8053540

Please sign in to comment.