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

Add rewrite #47

Merged
merged 5 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
73 changes: 13 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ on:
tags:
- "*"
pull_request:

name: CI
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -20,93 +21,45 @@ jobs:
# make sure all code has been formatted with rustfmt
- run: rustup component add rustfmt
- name: check rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check --color always
run: cargo fmt -- --check --color always

# run clippy to verify we have no warnings
- run: rustup component add clippy
- name: cargo fetch
uses: actions-rs/cargo@v1
with:
command: fetch
- run: cargo fetch
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features --all-targets -- -D warnings
run: cargo clippy --all-features --all-targets -- -D warnings

test:
name: Test
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: cargo fetch
uses: actions-rs/cargo@v1
with:
command: fetch
- run: cargo fetch
- name: cargo test build
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-run
run: cargo test --all-features --no-run
- name: cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
run: cargo test --all-features

deny-check:
name: cargo-deny check
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: EmbarkStudios/cargo-deny-action@v1

publish-check:
name: Publish Check
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: cargo fetch
uses: actions-rs/cargo@v1
with:
command: fetch
- run: cargo fetch
- name: cargo publish
uses: actions-rs/cargo@v1
with:
command: publish
args: --dry-run
# publish:
# name: Publish
# needs: [test, deny-check, publish-check]
# runs-on: ubuntu-latest
# if: startsWith(github.ref, 'refs/tags/')
# steps:
# - uses: actions/checkout@v2
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# override: true
# - name: cargo fetch
# uses: actions-rs/cargo@v1
# with:
# command: fetch
# - name: cargo publish
# uses: actions-rs/cargo@v1
# env:
# CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
# with:
# command: publish
run: cargo publish --dry-run
27 changes: 3 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,8 @@ thiserror = "1.0"
url = "2.2"

[dev-dependencies]
# COLORS! (follows version used by clap)
ansi_term = "0.11"
# Friendly error handling
anyhow = "1.0"
# Human friendly byte sizes
number_prefix = "0.4"
# Diff view of test failures
difference = "2.0"
# For futures helpers
futures-util = { version = "0.3", default-features = false }
# Futures testing utilities
futures-test = { version = "0.3" }
# Because it's good
structopt = "0.3"
# For doing actual authentication in examples
tame-oauth = { version = "0.4", features = ["gcp"] }

# For doing actual requests in examples
[dev-dependencies.reqwest]
version = "0.11"
default-features = false
features = ["rustls-tls", "stream"]

[dev-dependencies.tokio]
version = "1.0"
features = ["macros", "rt-multi-thread"]
futures-test = "0.3"
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
tokio = { version = "1.0", features = ["macros"] }
4 changes: 1 addition & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ impl<'a> ObjectName<'a> {
}

#[allow(clippy::match_same_arms)]
// Intentionally matching the same arms to make the code cleaner for reading
for (i, c) in name.chars().enumerate() {
match c {
// Object names cannot contain Carriage Return or Line Feed characters.
Expand All @@ -161,8 +160,7 @@ impl<'a> ObjectName<'a> {
'#' | '[' | ']' | '*' | '?' => {}
// Avoid using control characters that are illegal in XML 1.0 (#x7F–#x84 and #x86–#x9F):
// these characters will cause XML listing issues when you try to list your objects.
'\u{7F}'..='\u{84}' => {}
'\u{86}'..='\u{9F}' => {}
'\u{7F}'..='\u{84}' | '\u{86}'..='\u{9F}' => {}
_ => {
continue;
}
Expand Down
12 changes: 4 additions & 8 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
pub(crate) fn to_hex(input: &[u8]) -> String {
const CHARS: &[u8] = b"0123456789abcdef";

let mut ind = 0;

let mut result = Vec::new();
let mut result = String::with_capacity(input.len() * 2);
for &byte in input {
result[ind] = CHARS[(byte >> 4) as usize] as char;
result[ind + 1] = CHARS[(byte & 0xf) as usize] as char;

ind += 2;
result.push(CHARS[(byte >> 4) as usize] as char);
result.push(CHARS[(byte & 0xf) as usize] as char);
}

result.iter().collect()
result
}

pub fn get_content_length(headers: &http::HeaderMap) -> Option<usize> {
Expand Down
14 changes: 14 additions & 0 deletions src/v1/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ mod get;
mod insert;
mod list;
mod patch;
mod rewrite;

pub use delete::*;
pub use download::*;
pub use get::*;
pub use insert::*;
pub use list::*;
pub use patch::*;
pub use rewrite::*;

/// Helper struct used to collate all of the operations available for
/// [Objects](https://cloud.google.com/storage/docs/json_api/v1/objects)
Expand Down Expand Up @@ -119,3 +121,15 @@ where
let s: &str = Deserialize::deserialize(deserializer)?;
Ok(Some(T::from_str(s).map_err(serde::de::Error::custom)?))
}

fn from_str<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
T: std::str::FromStr,
T::Err: std::fmt::Display,
D: serde::de::Deserializer<'de>,
{
use serde::de::Deserialize;

let s: &str = Deserialize::deserialize(deserializer)?;
Ok(T::from_str(s).map_err(serde::de::Error::custom)?)
}
Loading