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

VTX-3411: fix serialisation for multi part struct #48

Merged
merged 14 commits into from
Dec 12, 2023
2 changes: 1 addition & 1 deletion object_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ walkdir = "2"
# Cloud storage support
base64 = { version = "0.21", default-features = false, features = ["std"], optional = true }
hyper = { version = "0.14", default-features = false, optional = true }
quick-xml = { version = "0.30.0", features = ["serialize", "overlapped-lists"], optional = true }
quick-xml = { git = "https://github.com/tafia/quick-xml.git", rev="db8546a", features = ["serialize", "overlapped-lists"], optional = true }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the latest version of the library (not released yet) escape level was decreased to Partial, meaning it would not escape " by default

serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
serde_json = { version = "1.0", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
Expand Down
50 changes: 46 additions & 4 deletions object_store/src/aws/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use crate::aws::checksum::Checksum;
use crate::aws::credential::{AwsCredential, CredentialExt};
use crate::aws::{
AwsCredentialProvider, S3CopyIfNotExists, STORE, STRICT_ENCODE_SET, STRICT_PATH_ENCODE_SET,
AwsCredentialProvider, S3CopyIfNotExists, STORE, STRICT_ENCODE_SET,
STRICT_PATH_ENCODE_SET,
};
use crate::client::get::GetClient;
use crate::client::list::ListClient;
Expand Down Expand Up @@ -152,14 +153,24 @@ struct CompleteMultipart {
part: Vec<MultipartPart>,
}

#[derive(Debug, Serialize)]
#[derive(Debug)]
struct MultipartPart {
#[serde(rename = "ETag")]
e_tag: String,
#[serde(rename = "PartNumber")]
part_number: usize,
}

impl Serialize for MultipartPart {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut s = serializer.serialize_struct("MultipartPart", 2)?;
s.serialize_field("ETag", format!("\"{}\"", &self.e_tag).as_str())?;
s.serialize_field("PartNumber", &self.part_number)?;
s.end()
}
}

#[derive(Deserialize)]
#[serde(rename_all = "PascalCase", rename = "DeleteResult")]
struct BatchDeleteResponse {
Expand Down Expand Up @@ -668,3 +679,34 @@ impl ListClient for S3Client {
fn encode_path(path: &Path) -> PercentEncode<'_> {
utf8_percent_encode(path.as_ref(), &STRICT_PATH_ENCODE_SET)
}

#[cfg(test)]
mod tests {

#[test]
fn test_multipart_serializrtion() {
let request = CompleteMultipart {
part: vec![
MultipartPart {
e_tag: "1".to_string(),
part_number: 1,
},
MultipartPart {
e_tag: "2".to_string(),
part_number: 2,
},
MultipartPart {
e_tag: "3".to_string(),
part_number: 3,
},
],
};

let body = quick_xml::se::to_string(&request).unwrap();

assert_eq!(
body,
r#"<CompleteMultipartUpload><Part><ETag>"1"</ETag><PartNumber>1</PartNumber></Part><Part><ETag>"2"</ETag><PartNumber>2</PartNumber></Part><Part><ETag>"3"</ETag><PartNumber>3</PartNumber></Part></CompleteMultipartUpload>"#
)
}
}
Loading