Skip to content

Commit

Permalink
Cleanup (#56)
Browse files Browse the repository at this point in the history
* Remove unneeded TryFrom imports

* Fixup README

* Split multipart into separate modules

* Split out resumable to module

Also adds a newtype wrapper around the resumable session so that we have
a bit of type safety.

* Add tests

* Update CHANGELOG
  • Loading branch information
Jake-Shadle authored Feb 24, 2022
1 parent 85dc378 commit 235dbed
Show file tree
Hide file tree
Showing 19 changed files with 700 additions and 574 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Added
- [PR#54](https://github.com/EmbarkStudios/tame-gcs/pull/54) added support for [resumable uploads](https://cloud.google.com/storage/docs/resumable-uploads). Thanks [@yottabytt](https://github.com/yottabytt)!

## [0.11.2] - 2022-02-09
### Fixed
- [PR#55](https://github.com/EmbarkStudios/tame-gcs/pull/55) fixed a bug in signed url creation caused by a stray character in the timestamp string.
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# 📂 tame-gcs
<div align="center">

# `📂 tame-gcs`

[![Embark](https://img.shields.io/badge/embark-open%20source-blueviolet.svg)](https://embark.dev)
[![Embark](https://img.shields.io/badge/discord-ark-%237289da.svg?logo=discord)](https://discord.gg/dAuKfZS)
Expand All @@ -9,10 +11,12 @@

`tame-gcs` is a crate with a limited set of [Google Cloud Storage(GCS)](https://cloud.google.com/storage/) operations that follows the [sans-io](https://sans-io.readthedocs.io/) approach.

</div>

## Why?

* You want to control how you actually make HTTP requests against GCS.
* You want to have more control over your dependencies, and not be bottlenecked for sticking to a particular version, or quickly upgrading, your HTTP related crates.
* You want to have more control over your dependencies, and not be bottlenecked by sticking to a particular version, or quickly upgrading, your HTTP related crates.

## Why not?

Expand All @@ -26,7 +30,7 @@ For example usage, see the [gsutil](https://github.com/EmbarkStudios/gsutil) cra

## Contributing

[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4-ff69b4.svg)](../CODE_OF_CONDUCT.md)
[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4-ff69b4.svg)](CODE_OF_CONDUCT.md)

We welcome community contributions to this project.

Expand All @@ -36,8 +40,8 @@ Please read our [Contributor Guide](CONTRIBUTING.md) for more information on how

Licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)

at your option.

Expand Down
25 changes: 25 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum Error {
InvalidPrefix(&'static str),
#[error("Sequence {0} is not allowed")]
InvalidSequence(&'static str),
#[error("Failed to parse URI")]
InvalidUri(UriError),
#[error("HTTP error")]
Http(#[source] HttpError),
#[error("HTTP status")]
Expand Down Expand Up @@ -136,6 +138,29 @@ impl From<serde_urlencoded::ser::Error> for Error {
}
}

#[derive(Debug, thiserror::Error)]
pub struct UriError(#[source] http::uri::InvalidUri);

impl fmt::Display for UriError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

impl PartialEq for UriError {
fn eq(&self, other: &Self) -> bool {
// This is **TERRIBLE** but all of the error details are unnecessarily
// private and it doesn't implement PartialEq ARGH
self.0.to_string() == other.0.to_string()
}
}

impl From<http::uri::InvalidUri> for Error {
fn from(e: http::uri::InvalidUri) -> Self {
Error::InvalidUri(UriError(e))
}
}

#[derive(Debug, PartialEq, Deserialize)]
pub struct ApiErrorInner {
pub domain: Option<String>,
Expand Down
1 change: 0 additions & 1 deletion src/response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::error::{self, Error};
use std::convert::TryFrom;

pub trait ApiResponse<B>: Sized + TryFrom<http::Response<B>, Error = Error>
where
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Helper types for working with GCS
use crate::error::Error;
use std::{borrow::Cow, convert::TryFrom};
use std::borrow::Cow;

/// A wrapper around strings meant to be used as bucket names,
/// to validate they conform to [Bucket Name Requirements](https://cloud.google.com/storage/docs/naming#requirements)
Expand Down
1 change: 0 additions & 1 deletion src/v1/objects/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
response::ApiResponse,
types::ObjectIdentifier,
};
use std::convert::TryFrom;

#[derive(Default, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down
2 changes: 1 addition & 1 deletion src/v1/objects/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
response::ApiResponse,
types::ObjectIdentifier,
};
use std::{convert::TryFrom, io};
use std::io;

#[derive(Default, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down
1 change: 0 additions & 1 deletion src/v1/objects/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
response::ApiResponse,
types::ObjectIdentifier,
};
use std::convert::TryFrom;

#[derive(Default, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down
Loading

0 comments on commit 235dbed

Please sign in to comment.