-
Notifications
You must be signed in to change notification settings - Fork 822
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
Consistently use GCP XML API #4207
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9dc1299
Consistently use GCP XML API
tustvold f64c35a
Use updated fake-gcs-server
tustvold f91e0df
Merge remote-tracking branch 'upstream/master' into gcp-xml-api
tustvold 46e5baf
Merge remote-tracking branch 'upstream/master' into gcp-xml-api
tustvold b0ef4fd
Review feedback
tustvold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,19 @@ | |
use crate::aws::checksum::Checksum; | ||
use crate::aws::credential::{AwsCredential, CredentialExt, CredentialProvider}; | ||
use crate::aws::STRICT_PATH_ENCODE_SET; | ||
use crate::client::list::ListResponse; | ||
use crate::client::pagination::stream_paginated; | ||
use crate::client::retry::RetryExt; | ||
use crate::multipart::UploadPart; | ||
use crate::path::DELIMITER; | ||
use crate::util::{format_http_range, format_prefix}; | ||
use crate::{ | ||
BoxStream, ClientOptions, ListResult, MultipartId, ObjectMeta, Path, Result, | ||
RetryConfig, StreamExt, | ||
BoxStream, ClientOptions, ListResult, MultipartId, Path, Result, RetryConfig, | ||
StreamExt, | ||
}; | ||
use base64::prelude::BASE64_STANDARD; | ||
use base64::Engine; | ||
use bytes::{Buf, Bytes}; | ||
use chrono::{DateTime, Utc}; | ||
use percent_encoding::{utf8_percent_encode, PercentEncode}; | ||
use reqwest::{ | ||
header::CONTENT_TYPE, Client as ReqwestClient, Method, Response, StatusCode, | ||
|
@@ -118,69 +118,6 @@ impl From<Error> for crate::Error { | |
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just moved into list.rs so it can be shared with the gcs implementation |
||
#[serde(rename_all = "PascalCase")] | ||
pub struct ListResponse { | ||
#[serde(default)] | ||
pub contents: Vec<ListContents>, | ||
#[serde(default)] | ||
pub common_prefixes: Vec<ListPrefix>, | ||
#[serde(default)] | ||
pub next_continuation_token: Option<String>, | ||
} | ||
|
||
impl TryFrom<ListResponse> for ListResult { | ||
type Error = crate::Error; | ||
|
||
fn try_from(value: ListResponse) -> Result<Self> { | ||
let common_prefixes = value | ||
.common_prefixes | ||
.into_iter() | ||
.map(|x| Ok(Path::parse(x.prefix)?)) | ||
.collect::<Result<_>>()?; | ||
|
||
let objects = value | ||
.contents | ||
.into_iter() | ||
.map(TryFrom::try_from) | ||
.collect::<Result<_>>()?; | ||
|
||
Ok(Self { | ||
common_prefixes, | ||
objects, | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct ListPrefix { | ||
pub prefix: String, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct ListContents { | ||
pub key: String, | ||
pub size: usize, | ||
pub last_modified: DateTime<Utc>, | ||
#[serde(rename = "ETag")] | ||
pub e_tag: Option<String>, | ||
} | ||
|
||
impl TryFrom<ListContents> for ObjectMeta { | ||
type Error = crate::Error; | ||
|
||
fn try_from(value: ListContents) -> Result<Self> { | ||
Ok(Self { | ||
location: Path::parse(value.key)?, | ||
last_modified: value.last_modified, | ||
size: value.size, | ||
e_tag: value.e_tag, | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
struct InitiateMultipart { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Logic for extracting ObjectMeta from headers used by AWS, GCP and Azure | ||
|
||
use crate::path::Path; | ||
use crate::ObjectMeta; | ||
use chrono::{DateTime, Utc}; | ||
use hyper::header::{CONTENT_LENGTH, ETAG, LAST_MODIFIED}; | ||
use hyper::HeaderMap; | ||
use snafu::{OptionExt, ResultExt, Snafu}; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub enum Error { | ||
#[snafu(display("ETag Header missing from response"))] | ||
MissingEtag, | ||
|
||
#[snafu(display("Received header containing non-ASCII data"))] | ||
BadHeader { source: reqwest::header::ToStrError }, | ||
|
||
#[snafu(display("Last-Modified Header missing from response"))] | ||
MissingLastModified, | ||
|
||
#[snafu(display("Content-Length Header missing from response"))] | ||
MissingContentLength, | ||
|
||
#[snafu(display("Invalid last modified '{}': {}", last_modified, source))] | ||
InvalidLastModified { | ||
last_modified: String, | ||
source: chrono::ParseError, | ||
}, | ||
|
||
#[snafu(display("Invalid content length '{}': {}", content_length, source))] | ||
InvalidContentLength { | ||
content_length: String, | ||
source: std::num::ParseIntError, | ||
}, | ||
} | ||
|
||
/// Extracts [`ObjectMeta`] from the provided [`HeaderMap`] | ||
pub fn header_meta(location: &Path, headers: &HeaderMap) -> Result<ObjectMeta, Error> { | ||
let last_modified = headers | ||
.get(LAST_MODIFIED) | ||
.context(MissingLastModifiedSnafu)?; | ||
|
||
let content_length = headers | ||
.get(CONTENT_LENGTH) | ||
.context(MissingContentLengthSnafu)?; | ||
|
||
let last_modified = last_modified.to_str().context(BadHeaderSnafu)?; | ||
let last_modified = DateTime::parse_from_rfc2822(last_modified) | ||
.context(InvalidLastModifiedSnafu { last_modified })? | ||
.with_timezone(&Utc); | ||
|
||
let content_length = content_length.to_str().context(BadHeaderSnafu)?; | ||
let content_length = content_length | ||
.parse() | ||
.context(InvalidContentLengthSnafu { content_length })?; | ||
|
||
let e_tag = headers.get(ETAG).context(MissingEtagSnafu)?; | ||
let e_tag = e_tag.to_str().context(BadHeaderSnafu)?; | ||
|
||
Ok(ObjectMeta { | ||
location: location.clone(), | ||
last_modified, | ||
size: content_length, | ||
e_tag: Some(e_tag.to_string()), | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fsouza/fake-gcs-server#1164
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please leave a link to that PR as a comment (so we now we can update it back when it is accepted upstream)?