mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-09 22:19:23 +00:00
model: store x-amz-checksum-type (full_object | composite)
This commit is contained in:
+23
-3
@@ -78,8 +78,23 @@ pub async fn handle_copy(
|
||||
},
|
||||
)?;
|
||||
|
||||
let was_multipart = source_version_meta.etag.contains('-'); // HACK
|
||||
|
||||
// Extract source checksum info before source_object_meta_inner is consumed
|
||||
let source_checksum = source_object_meta_inner.checksum;
|
||||
let source_checksum_type = match (source_object_meta_inner.checksum_type, source_checksum) {
|
||||
(Some(ct), _) => Some(ct),
|
||||
(None, Some(_)) => {
|
||||
// Migrated object from garage v1.x or older
|
||||
// determine checksum type depending if this is a multipart upload or not
|
||||
if was_multipart {
|
||||
Some(ChecksumType::Composite)
|
||||
} else {
|
||||
Some(ChecksumType::FullObject)
|
||||
}
|
||||
}
|
||||
(None, None) => None,
|
||||
};
|
||||
let source_checksum_algorithm = source_checksum.map(|x| x.algorithm());
|
||||
|
||||
// If source object has a checksum, the destination object must as well.
|
||||
@@ -88,7 +103,6 @@ pub async fn handle_copy(
|
||||
let checksum_algorithm = checksum_algorithm.or(source_checksum_algorithm);
|
||||
|
||||
// Determine metadata of destination object
|
||||
let was_multipart = source_version_meta.etag.contains('-');
|
||||
let dest_object_meta = ObjectVersionMetaInner {
|
||||
headers: match req.headers().get("x-amz-metadata-directive") {
|
||||
Some(v) if v == hyper::header::HeaderValue::from_static("REPLACE") => {
|
||||
@@ -97,6 +111,7 @@ pub async fn handle_copy(
|
||||
_ => source_object_meta_inner.into_owned().headers,
|
||||
},
|
||||
checksum: source_checksum,
|
||||
checksum_type: source_checksum_type,
|
||||
};
|
||||
|
||||
// Do actual object copying
|
||||
@@ -144,8 +159,12 @@ pub async fn handle_copy(
|
||||
} else {
|
||||
ChecksumMode::Verify(&expected_checksum)
|
||||
};
|
||||
// If source and dest encryption use different keys,
|
||||
// we must decrypt content and re-encrypt, so rewrite all data blocks.
|
||||
// For multipart uploads that had a composite checksum, set checksum type
|
||||
// to full object as it will be recalculated.
|
||||
let dest_object_meta = ObjectVersionMetaInner {
|
||||
checksum_type: checksum_algorithm.map(|_| ChecksumType::FullObject),
|
||||
..dest_object_meta
|
||||
};
|
||||
handle_copy_reencrypt(
|
||||
ctx,
|
||||
dest_key,
|
||||
@@ -247,6 +266,7 @@ async fn handle_copy_metaonly(
|
||||
state: ObjectVersionState::Uploading {
|
||||
encryption: new_meta.encryption.clone(),
|
||||
checksum_algorithm: None,
|
||||
checksum_type: None,
|
||||
multipart: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -54,6 +54,7 @@ pub async fn handle_create_multipart_upload(
|
||||
let meta = ObjectVersionMetaInner {
|
||||
headers,
|
||||
checksum: None,
|
||||
checksum_type: None,
|
||||
};
|
||||
|
||||
// Determine whether object should be encrypted, and if so the key
|
||||
@@ -78,6 +79,8 @@ pub async fn handle_create_multipart_upload(
|
||||
multipart: true,
|
||||
encryption: object_encryption,
|
||||
checksum_algorithm,
|
||||
// TODO: add support for full-object checksums
|
||||
checksum_type: checksum_algorithm.map(|_| ChecksumType::Composite),
|
||||
},
|
||||
};
|
||||
let object = Object::new(*bucket_id, key.to_string(), vec![object_version]);
|
||||
@@ -440,6 +443,8 @@ pub async fn handle_complete_multipart_upload(
|
||||
let new_meta = ObjectVersionMetaInner {
|
||||
headers: meta.into_owned().headers,
|
||||
checksum: checksum_extra,
|
||||
// TODO: add support for full-object checksums
|
||||
checksum_type: checksum_extra.map(|_| ChecksumType::Composite),
|
||||
};
|
||||
encryption.encrypt_meta(new_meta)?
|
||||
}
|
||||
|
||||
@@ -233,6 +233,7 @@ pub async fn handle_post_object(
|
||||
let meta = ObjectVersionMetaInner {
|
||||
headers,
|
||||
checksum: expected_checksums.extra,
|
||||
checksum_type: expected_checksums.extra.map(|_| ChecksumType::FullObject),
|
||||
};
|
||||
|
||||
let encryption = EncryptionParams::new_from_headers(
|
||||
|
||||
@@ -83,6 +83,7 @@ pub async fn handle_put(
|
||||
let meta = ObjectVersionMetaInner {
|
||||
headers,
|
||||
checksum: expected_checksums.extra,
|
||||
checksum_type: expected_checksums.extra.map(|_| ChecksumType::FullObject),
|
||||
};
|
||||
|
||||
// Determine whether object should be encrypted, and if so the key
|
||||
@@ -243,6 +244,7 @@ pub(crate) async fn save_stream<S: Stream<Item = Result<Bytes, Error>> + Unpin>(
|
||||
state: ObjectVersionState::Uploading {
|
||||
encryption: encryption.encrypt_meta(meta.clone())?,
|
||||
checksum_algorithm: None, // don't care; overwritten later
|
||||
checksum_type: None,
|
||||
multipart: false,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user