mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-16 21:14:45 +00:00
refactor(protocol): dispatch CopyObject through the owned usecase
Replace the protocol client compatibility dispatch with owned request and
response projections while preserving source validation, conditions, dates,
ETags, error answers, bound storage, fallback behavior, and operation counts.
Validated against the existing client and library behavior on f68ef7d5.
Final gateway-feature tests passed 11/11, including existing PutObject
regressions; default-mode tests passed 6/6. Both all-target Clippy modes,
script tests, wiring checks, and static preflight passed.
Twenty-two effective mutations covered observation controls, operation
counts, context selection, storage effects, source and condition parsing,
optional fields, dates, output fields, error facts, and request credentials.
Restored sources were rebuilt before the final passing controls.
This does not register UploadPartCopy or change the default S3 stack.
External migration lanes and release-reference testing remain outstanding.
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[cfg(test)]
|
||||
mod copy_test;
|
||||
mod multipart;
|
||||
mod owned;
|
||||
|
||||
@@ -25,9 +27,9 @@ use crate::storage_api::protocols::client::{FS, MultipartStagingOperation, ReqIn
|
||||
use http::{HeaderMap, Method};
|
||||
use percent_encoding::{AsciiSet, CONTROLS, utf8_percent_encode};
|
||||
use rustfs_credentials;
|
||||
use rustfs_gateway_types::compat::s3s_5761ddfe::{
|
||||
self as gateway_s3s_compat, leaf::RequestWire, request_context::GatewayRequestContext,
|
||||
};
|
||||
use rustfs_gateway_types::compat::s3s_5761ddfe as gateway_s3s_compat;
|
||||
#[cfg(test)]
|
||||
use rustfs_gateway_types::compat::s3s_5761ddfe::{leaf::RequestWire, request_context::GatewayRequestContext};
|
||||
use rustfs_gateway_types::dto as gateway_dto;
|
||||
#[cfg(test)]
|
||||
use rustfs_gateway_types::{BucketName, OpaqueString};
|
||||
@@ -175,6 +177,7 @@ fn list_buckets_output_from_s3s(output: s3s::dto::ListBucketsOutput) -> Result<g
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn gateway_request_context(method: Method, uri: &http::Uri, headers: HeaderMap) -> GatewayRequestContext {
|
||||
GatewayRequestContext {
|
||||
method,
|
||||
@@ -860,15 +863,8 @@ impl rustfs_protocols::common::client::s3::StorageBackend for ProtocolStorageCli
|
||||
let bucket = input.bucket.as_str().to_owned();
|
||||
let key = input.key.as_str().to_owned();
|
||||
let uri = build_object_uri(&bucket, &key, &[])?;
|
||||
let copy_source =
|
||||
legacy_copy_source(input.copy_source.clone()).map_err(|e| conversion_error("CopyObject copy_source", e))?;
|
||||
let context = gateway_request_context(Method::PUT, &uri, HeaderMap::new());
|
||||
let wire = RequestWire::of(&context);
|
||||
let input = gateway_s3s_compat::generated::ops::copy_object::input_to_s3s(input, copy_source, &wire)
|
||||
.map_err(|e| conversion_error("CopyObject input", e))?;
|
||||
|
||||
let req = Self::create_request(
|
||||
input,
|
||||
let input = owned::copy_input(input)?;
|
||||
let envelope = Self::create_envelope(
|
||||
Method::PUT,
|
||||
uri,
|
||||
RequestParams {
|
||||
@@ -876,13 +872,13 @@ impl rustfs_protocols::common::client::s3::StorageBackend for ProtocolStorageCli
|
||||
object: Some(key),
|
||||
credentials,
|
||||
},
|
||||
)?;
|
||||
|
||||
match self.fs.copy_object(req).await {
|
||||
Ok(response) => gateway_s3s_compat::generated::ops::copy_object::output_from_s3s(response.output)
|
||||
.map_err(|e| conversion_error("CopyObject output", e)),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
);
|
||||
rustfs_io_metrics::record_s3_op(rustfs_s3_ops::S3Operation::CopyObject);
|
||||
self.owned_usecase()
|
||||
.execute_copy_object_owned(envelope, input)
|
||||
.await
|
||||
.map_err(owned::copy_error)
|
||||
.and_then(owned::copy_output)
|
||||
}
|
||||
|
||||
async fn delete_bucket(
|
||||
|
||||
@@ -0,0 +1,674 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
//! CopyObject compatibility at the protocol storage boundary.
|
||||
|
||||
use super::*;
|
||||
use crate::storage_api::protocols::client::{
|
||||
BucketOperations, MakeBucketOptions, ObjectIO, StorageObjectOptions, StoragePutObjReader,
|
||||
};
|
||||
use http_body_util::BodyExt;
|
||||
use rustfs_protocols::common::client::s3::StorageBackend;
|
||||
|
||||
fn input() -> gateway_dto::CopyObjectInput {
|
||||
gateway_dto::CopyObjectInput::builder(rustfs_gateway_types::CopySourceValue::Bucket {
|
||||
bucket: "copy-source".into(),
|
||||
key: "a ?&/%é".into(),
|
||||
version_id: None,
|
||||
})
|
||||
.bucket(BucketName::new("copy-target".to_owned()).expect("bucket"))
|
||||
.key(rustfs_gateway_types::ObjectKey::new("destination".to_owned()).expect("key"))
|
||||
.build()
|
||||
}
|
||||
|
||||
fn count() -> u64 {
|
||||
rustfs_io_metrics::s3_op_metrics_snapshot()
|
||||
.into_iter()
|
||||
.find(|row| row.op == rustfs_s3_ops::S3Operation::CopyObject.as_str())
|
||||
.map_or(0, |row| row.total)
|
||||
}
|
||||
|
||||
fn outcome(result: rustfs_s3_types::S3Result<gateway_dto::CopyObjectOutput>) -> serde_json::Value {
|
||||
match result {
|
||||
Ok(output) => {
|
||||
serde_json::json!({"etag":output.e_tag.map(|tag|format!("{tag:?}")),"nanos":output.last_modified.map(|at|at.subsec_nanos()%1_000_000),"version":output.version_id,"source_version":output.copy_source_version_id})
|
||||
}
|
||||
Err(error) => {
|
||||
serde_json::json!({"code":format!("{:?}",error.code()),"message":error.message(),"status":error.status_code().map(|status|status.as_u16()),"headers":format!("{:?}",error.headers())})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn protocol_copy_runtime_contract() {
|
||||
crate::app::gating_test_env::run_large_stack_test("protocol-copy", || async {
|
||||
let root = rustfs_credentials::Credentials {
|
||||
access_key: "copy-root".into(),
|
||||
secret_key: "copy-secret".into(),
|
||||
status: "on".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let (_foreign_temp, foreign, _foreign_iam) = crate::protocols::policy_test::protocol_test_context(root.clone()).await;
|
||||
let ambient = crate::runtime_sources::publish_test_app_context(foreign.clone());
|
||||
assert!(std::sync::Arc::ptr_eq(&ambient, &foreign));
|
||||
let (_temp, target, _iam) = crate::protocols::policy_test::protocol_test_context(root.clone()).await;
|
||||
for context in [&target, &ambient] {
|
||||
for bucket in ["copy-source", "copy-target"] {
|
||||
context
|
||||
.object_store()
|
||||
.make_bucket(bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("bucket");
|
||||
}
|
||||
context
|
||||
.object_store()
|
||||
.put_object(
|
||||
"copy-source",
|
||||
"a ?&/%é",
|
||||
&mut StoragePutObjReader::from_vec(if std::sync::Arc::ptr_eq(context, &target) {
|
||||
b"bound".to_vec()
|
||||
} else {
|
||||
b"ambient".to_vec()
|
||||
}),
|
||||
&StorageObjectOptions::default(),
|
||||
)
|
||||
.await
|
||||
.expect("source");
|
||||
}
|
||||
let slot = crate::runtime_sources::ServerContextSlot::new();
|
||||
assert!(slot.install(target.clone()));
|
||||
let client = ProtocolStorageClient::new(FS::with_server_ctx(slot));
|
||||
// Prove that the observer can distinguish zero, one and an edge increment.
|
||||
assert_eq!(count(), 0);
|
||||
rustfs_io_metrics::record_s3_op(rustfs_s3_ops::S3Operation::CopyObject);
|
||||
assert_eq!(count(), 1);
|
||||
let mut old_input = input();
|
||||
old_input.key = rustfs_gateway_types::ObjectKey::new("legacy-control".to_owned()).expect("legacy control key");
|
||||
let old_input = legacy_input(old_input).expect("legacy input");
|
||||
let before = count();
|
||||
client
|
||||
.fs
|
||||
.copy_object(
|
||||
ProtocolStorageClient::create_request(
|
||||
old_input,
|
||||
Method::PUT,
|
||||
build_object_uri("copy-target", "legacy-control", &[]).expect("legacy URI"),
|
||||
RequestParams {
|
||||
bucket: Some("copy-target".into()),
|
||||
object: Some("legacy-control".into()),
|
||||
credentials: &root,
|
||||
},
|
||||
)
|
||||
.expect("legacy request"),
|
||||
)
|
||||
.await
|
||||
.expect("legacy copy control");
|
||||
assert_eq!(count() - before, 1);
|
||||
|
||||
let mut rows = Vec::new();
|
||||
for case in [
|
||||
"normal",
|
||||
"missing-source",
|
||||
"bad-version",
|
||||
"invalid-class",
|
||||
"specific-none",
|
||||
"weak-match",
|
||||
"strong-match",
|
||||
"invalid-match",
|
||||
"empty-match",
|
||||
"bad-source-bucket",
|
||||
"bad-source-key",
|
||||
"bad-destination",
|
||||
"tagging",
|
||||
"same-source",
|
||||
] {
|
||||
let mut request = input();
|
||||
match case {
|
||||
"missing-source" => {
|
||||
request.copy_source = rustfs_gateway_types::CopySourceValue::Bucket {
|
||||
bucket: "copy-source".into(),
|
||||
key: "missing".into(),
|
||||
version_id: None,
|
||||
}
|
||||
}
|
||||
"bad-version" => {
|
||||
request.copy_source = rustfs_gateway_types::CopySourceValue::Bucket {
|
||||
bucket: "copy-source".into(),
|
||||
key: "a ?&/%é".into(),
|
||||
version_id: Some("bad".into()),
|
||||
}
|
||||
}
|
||||
"invalid-class" => request.storage_class = Some(gateway_dto::StorageClass::custom("BAD".to_owned())),
|
||||
"specific-none" => request.if_none_match = Some("abc".into()),
|
||||
"weak-match" => request.copy_source_if_match = Some("W/\"abc\"".into()),
|
||||
"strong-match" => request.copy_source_if_match = Some("\"abc\"".into()),
|
||||
"invalid-match" => request.copy_source_if_match = Some("\"abc".into()),
|
||||
"empty-match" => request.copy_source_if_match = Some("".into()),
|
||||
"bad-source-bucket" => {
|
||||
request.copy_source = rustfs_gateway_types::CopySourceValue::Bucket {
|
||||
bucket: "x".into(),
|
||||
key: "key".into(),
|
||||
version_id: None,
|
||||
}
|
||||
}
|
||||
"bad-source-key" => {
|
||||
request.copy_source = rustfs_gateway_types::CopySourceValue::Bucket {
|
||||
bucket: "copy-source".into(),
|
||||
key: "".into(),
|
||||
version_id: None,
|
||||
}
|
||||
}
|
||||
"bad-destination" => {
|
||||
request.bucket = crate::app::dto_values::stored_bucket_name("a-s3alias").expect("stored reserved name")
|
||||
}
|
||||
"tagging" => request.tagging = Some("bad=%FF".into()),
|
||||
"same-source" => {
|
||||
request.bucket = BucketName::new("copy-source".to_owned()).expect("source");
|
||||
request.key = rustfs_gateway_types::ObjectKey::new("a ?&/%é".to_owned()).expect("source key");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let before = count();
|
||||
let result = outcome(client.copy_object(request, &root).await);
|
||||
rows.push(serde_json::json!({"case":case,"result":result,"count":count()-before}));
|
||||
}
|
||||
let before = count();
|
||||
let fallback = ProtocolStorageClient::new(FS::with_server_ctx(crate::runtime_sources::ServerContextSlot::new()));
|
||||
let fallback = outcome(fallback.copy_object(input(), &root).await);
|
||||
let present = |context: std::sync::Arc<crate::runtime_sources::AppContext>| {
|
||||
let root = root.clone();
|
||||
async move {
|
||||
let slot = crate::runtime_sources::ServerContextSlot::new();
|
||||
assert!(slot.install(context));
|
||||
let client = ProtocolStorageClient::new(FS::with_server_ctx(slot));
|
||||
match client.get_object("copy-target", "destination", &root, None).await {
|
||||
Ok(output) => Ok(output
|
||||
.body
|
||||
.expect("copied body")
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.expect("copied bytes")
|
||||
.to_bytes()
|
||||
.to_vec()),
|
||||
Err(error) => Err(error.to_string()),
|
||||
}
|
||||
}
|
||||
};
|
||||
let actual = serde_json::json!({"rows":rows,"fallback":fallback,"fallback_count":count()-before,"bound":present(target).await,"ambient":present(ambient).await});
|
||||
println!("COPY_OBSERVATIONS={actual}");
|
||||
assert_eq!(
|
||||
actual,
|
||||
serde_json::json!({"ambient": {"Ok": [97, 109, 98, 105, 101, 110, 116]}, "bound": {"Ok": [98, 111, 117, 110, 100]}, "fallback": {"etag": "ETag { weak: false, any: false, stored: false, tag: \"fff66a4d00c8ed7bb7814ff29d0faca2\" }", "nanos": 0, "source_version": null, "version": null}, "fallback_count": 1, "rows": [{"case": "normal", "count": 1, "result": {"etag": "ETag { weak: false, any: false, stored: false, tag: \"b9f2b582ee75a7259c62ce162cebe368\" }", "nanos": 0, "source_version": null, "version": null}}, {"case": "missing-source", "count": 1, "result": {"code": "NoSuchKey", "headers": "None", "message": "The specified key does not exist.", "status": 404}}, {"case": "bad-version", "count": 1, "result": {"code": "InvalidArgument", "headers": "None", "message": "Invalid version id specified in copy source", "status": 400}}, {"case": "invalid-class", "count": 1, "result": {"code": "InvalidStorageClass", "headers": "None", "message": "The storage class you specified is not valid.", "status": 400}}, {"case": "specific-none", "count": 1, "result": {"code": "NotImplemented", "headers": "None", "message": "A header you provided implies functionality that is not implemented.", "status": 501}}, {"case": "weak-match", "count": 1, "result": {"code": "PreconditionFailed", "headers": "None", "message": "At least one of the preconditions you specified did not hold.", "status": 412}}, {"case": "strong-match", "count": 1, "result": {"code": "PreconditionFailed", "headers": "None", "message": "At least one of the preconditions you specified did not hold.", "status": 412}}, {"case": "invalid-match", "count": 0, "result": {"code": "InternalError", "headers": "None", "message": "failed to convert CopyObject input through the gateway compatibility seam: copy_source_if_match: not an entity-tag condition the s3s input can hold", "status": 500}}, {"case": "empty-match", "count": 1, "result": {"etag": "ETag { weak: false, any: false, stored: false, tag: \"b9f2b582ee75a7259c62ce162cebe368\" }", "nanos": 0, "source_version": null, "version": null}}, {"case": "bad-source-bucket", "count": 0, "result": {"code": "InternalError", "headers": "None", "message": "failed to convert CopyObject copy_source through the gateway compatibility seam: ParseAmzCopySourceError: InvalidBucketName", "status": 500}}, {"case": "bad-source-key", "count": 1, "result": {"code": "InvalidArgument", "headers": "None", "message": "Invalid object key", "status": 400}}, {"case": "bad-destination", "count": 1, "result": {"code": "InternalError", "headers": "None", "message": "We encountered an internal error, please try again.", "status": 500}}, {"case": "tagging", "count": 1, "result": {"code": "InvalidRequest", "headers": "None", "message": "The Tagging header requires the REPLACE tagging directive", "status": 400}}, {"case": "same-source", "count": 1, "result": {"code": "InvalidRequest", "headers": "None", "message": "Cannot copy an object to itself. Source and destination must be different.", "status": 400}}]})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn legacy_input(input: gateway_dto::CopyObjectInput) -> rustfs_s3_types::S3Result<CopyObjectInput> {
|
||||
let source =
|
||||
legacy_copy_source(input.copy_source.clone()).map_err(|error| conversion_error("CopyObject copy_source", error))?;
|
||||
let context = gateway_request_context(
|
||||
Method::PUT,
|
||||
&build_object_uri(input.bucket.as_str(), input.key.as_str(), &[])?,
|
||||
HeaderMap::new(),
|
||||
);
|
||||
gateway_s3s_compat::generated::ops::copy_object::input_to_s3s(input, source, &RequestWire::of(&context))
|
||||
.map_err(|error| conversion_error("CopyObject input", error))
|
||||
}
|
||||
|
||||
use crate::app::object_usecase::{CopyObjectWriteInput, CopyObjectWriteOutput, CopySourceCondition};
|
||||
|
||||
macro_rules! optional_input_facts {
|
||||
($input:expr) => {
|
||||
serde_json::json!({
|
||||
"bucket": $input.bucket,
|
||||
"key": $input.key,
|
||||
"version_id": $input.version_id,
|
||||
"cache_control": $input.cache_control,
|
||||
"content_disposition": $input.content_disposition,
|
||||
"content_encoding": $input.content_encoding,
|
||||
"content_language": $input.content_language,
|
||||
"content_type": $input.content_type,
|
||||
"expires": $input.expires,
|
||||
"metadata": $input.metadata,
|
||||
"tagging": $input.tagging,
|
||||
"website_redirect_location": $input.website_redirect_location,
|
||||
"ssekms_key_id": $input.ssekms_key_id,
|
||||
"sse_customer_algorithm": $input.sse_customer_algorithm,
|
||||
"sse_customer_key": $input.sse_customer_key,
|
||||
"sse_customer_key_md5": $input.sse_customer_key_md5,
|
||||
"copy_source_sse_customer_algorithm": $input.copy_source_sse_customer_algorithm,
|
||||
"copy_source_sse_customer_key": $input.copy_source_sse_customer_key,
|
||||
"copy_source_sse_customer_key_md5": $input.copy_source_sse_customer_key_md5,
|
||||
"metadata_directive": $input.metadata_directive.as_ref().map(|value|value.as_str()),
|
||||
"tagging_directive": $input.tagging_directive.as_ref().map(|value|value.as_str()),
|
||||
"object_lock_mode": $input.object_lock_mode.as_ref().map(|value|value.as_str()),
|
||||
"object_lock_legal_hold_status": $input.object_lock_legal_hold_status.as_ref().map(|value|value.as_str()),
|
||||
"server_side_encryption": $input.server_side_encryption.as_ref().map(|value|value.as_str()),
|
||||
"storage_class": $input.storage_class.as_ref().map(|value|value.as_str()),
|
||||
"checksum_algorithm": $input.checksum_algorithm.as_ref().map(|value|value.as_str()),
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
fn owned_condition(value: Option<CopySourceCondition>) -> serde_json::Value {
|
||||
match value {
|
||||
None => serde_json::Value::Null,
|
||||
Some(CopySourceCondition::Any) => serde_json::json!(["any"]),
|
||||
Some(CopySourceCondition::Weak) => serde_json::json!(["weak"]),
|
||||
Some(CopySourceCondition::Strong(value)) => serde_json::json!(["strong", value]),
|
||||
}
|
||||
}
|
||||
|
||||
fn legacy_condition(value: Option<ETagCondition>) -> serde_json::Value {
|
||||
match value {
|
||||
None => serde_json::Value::Null,
|
||||
Some(ETagCondition::Any) => serde_json::json!(["any"]),
|
||||
Some(ETagCondition::ETag(ETag::Weak(_))) => serde_json::json!(["weak"]),
|
||||
Some(ETagCondition::ETag(ETag::Strong(value))) => serde_json::json!(["strong", value]),
|
||||
}
|
||||
}
|
||||
|
||||
fn source_facts(source: Option<rustfs_gateway_types::CopySourceValue>) -> serde_json::Value {
|
||||
match source {
|
||||
Some(rustfs_gateway_types::CopySourceValue::Bucket { bucket, key, version_id }) => {
|
||||
serde_json::json!([bucket, key, version_id])
|
||||
}
|
||||
_ => serde_json::Value::Null,
|
||||
}
|
||||
}
|
||||
|
||||
fn legacy_source_facts(source: CopySource) -> serde_json::Value {
|
||||
match source {
|
||||
CopySource::Bucket { bucket, key, version_id } => serde_json::json!([bucket, key, version_id]),
|
||||
_ => serde_json::Value::Null,
|
||||
}
|
||||
}
|
||||
|
||||
fn owned_input_facts(input: CopyObjectWriteInput) -> serde_json::Value {
|
||||
let fields = optional_input_facts!(input);
|
||||
serde_json::json!({"fields":fields,"source":source_facts(input.copy_source),"none":input.specific_if_none_match,
|
||||
"match":owned_condition(input.copy_source_if_match),"not_match":owned_condition(input.copy_source_if_none_match),
|
||||
"retain":input.object_lock_retain_until_date.map(|value|value.unix_timestamp_nanos().to_string())})
|
||||
}
|
||||
|
||||
fn legacy_input_facts(input: CopyObjectInput) -> serde_json::Value {
|
||||
let fields = optional_input_facts!(input);
|
||||
serde_json::json!({"fields":fields,"source":legacy_source_facts(input.copy_source),"none":matches!(input.if_none_match,Some(ETagCondition::ETag(_))),
|
||||
"match":legacy_condition(input.copy_source_if_match),"not_match":legacy_condition(input.copy_source_if_none_match),
|
||||
"retain":input.object_lock_retain_until_date.map(|value|time::OffsetDateTime::from(value).unix_timestamp_nanos().to_string())})
|
||||
}
|
||||
|
||||
fn compare_input(rows: &mut Vec<serde_json::Value>, name: &str, make: impl Fn() -> gateway_dto::CopyObjectInput) {
|
||||
let current = owned::copy_input(make())
|
||||
.map(owned_input_facts)
|
||||
.map_err(|error| error.to_string());
|
||||
let old = legacy_input(make())
|
||||
.map(legacy_input_facts)
|
||||
.map_err(|error| error.to_string());
|
||||
if current != old {
|
||||
rows.push(serde_json::json!([name, current, old]));
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_output_facts(tag: Option<&str>) -> CopyObjectWriteOutput {
|
||||
CopyObjectWriteOutput {
|
||||
e_tag: tag.map(str::to_owned),
|
||||
last_modified: Some(time::OffsetDateTime::from_unix_timestamp_nanos(1_700_000_000_123_456_789).expect("instant")),
|
||||
copy_source_version_id: None,
|
||||
version_id: None,
|
||||
server_side_encryption: None,
|
||||
ssekms_key_id: None,
|
||||
sse_customer_algorithm: None,
|
||||
sse_customer_key_md5: None,
|
||||
checksum_crc32: None,
|
||||
checksum_crc32c: None,
|
||||
checksum_sha1: None,
|
||||
checksum_sha256: None,
|
||||
checksum_crc64nvme: None,
|
||||
checksum_md5: None,
|
||||
checksum_sha512: None,
|
||||
checksum_xxhash3: None,
|
||||
checksum_xxhash64: None,
|
||||
checksum_xxhash128: None,
|
||||
checksum_type: None,
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn protocol_copy_request_head_matches_legacy() {
|
||||
fn facts(envelope: &crate::app::RequestEnvelope) -> serde_json::Value {
|
||||
let info = envelope.req_info().expect("request info");
|
||||
let credentials = envelope.credentials().expect("request credentials");
|
||||
let identity = info.cred.as_ref().expect("request identity");
|
||||
serde_json::json!({
|
||||
"method":envelope.method().as_str(),"uri":envelope.uri().to_string(),"headers":format!("{:?}",envelope.headers()),
|
||||
"credentials":[credentials.access_key(),credentials.secret_key(),credentials.session_token()],
|
||||
"identity":[identity.access_key,identity.secret_key,identity.session_token],
|
||||
"bucket":info.bucket,"object":info.object,"version":info.version_id,"owner":info.is_owner,
|
||||
"keystone":info.keystone_session_present,"replication":info.replication_request_authorized,"region":info.region,
|
||||
"request_context":info.request_context.is_some(),"suppress_log":info.suppress_denial_log,"suppress_audit":info.suppress_denial_audit,
|
||||
"head_region":envelope.region(),"service":envelope.service(),"server":envelope.server_context().is_some(),"presigned":envelope.verified_presigned().is_some(),
|
||||
})
|
||||
}
|
||||
for secret in ["copy-secret", ""] {
|
||||
let credentials = rustfs_credentials::Credentials {
|
||||
access_key: "copy-identity".into(),
|
||||
secret_key: secret.into(),
|
||||
session_token: "identity-token".into(),
|
||||
status: "on".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let uri = build_object_uri("copy-target", "a ?&/%é", &[]).expect("request URI");
|
||||
let params = || RequestParams {
|
||||
bucket: Some("copy-target".to_owned()),
|
||||
object: Some("a ?&/%é".to_owned()),
|
||||
credentials: &credentials,
|
||||
};
|
||||
let old = ProtocolStorageClient::create_request((), Method::PUT, uri.clone(), params()).expect("legacy request");
|
||||
let old = crate::app::RequestEnvelope::from_s3s(&old);
|
||||
let current = ProtocolStorageClient::create_envelope(Method::PUT, uri, params());
|
||||
assert_eq!(facts(¤t), facts(&old));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn protocol_copy_input_projection_matches_legacy() {
|
||||
let mut rows = Vec::new();
|
||||
for field in [
|
||||
"if_match",
|
||||
"if_none_match",
|
||||
"copy_source_if_match",
|
||||
"copy_source_if_none_match",
|
||||
] {
|
||||
for value in [
|
||||
"",
|
||||
"*",
|
||||
" * ",
|
||||
"abc",
|
||||
"W/abc",
|
||||
"\"abc\"",
|
||||
"W/\"abc\"",
|
||||
"\"\"",
|
||||
"\"abc",
|
||||
"abc\"",
|
||||
"\"a b\"",
|
||||
"\"a\\b\"",
|
||||
"\"a\"b\"",
|
||||
"\"a\nb\"",
|
||||
"a,b",
|
||||
"é",
|
||||
"\"é\"",
|
||||
] {
|
||||
compare_input(&mut rows, &format!("{field}:{value:?}"), || {
|
||||
let mut request = input();
|
||||
match field {
|
||||
"if_match" => request.if_match = Some(value.into()),
|
||||
"if_none_match" => request.if_none_match = Some(value.into()),
|
||||
"copy_source_if_match" => request.copy_source_if_match = Some(value.into()),
|
||||
_ => request.copy_source_if_none_match = Some(value.into()),
|
||||
}
|
||||
request
|
||||
});
|
||||
}
|
||||
}
|
||||
for value in ["", "value"] {
|
||||
compare_input(&mut rows, &format!("optionals:{value:?}"), || {
|
||||
let mut request = input();
|
||||
request.cache_control = Some(value.into());
|
||||
request.content_disposition = Some(value.into());
|
||||
request.content_encoding = Some(value.into());
|
||||
request.content_language = Some(value.into());
|
||||
request.content_type = Some(value.into());
|
||||
request.tagging = Some(value.into());
|
||||
request.ssekms_key_id = Some(value.into());
|
||||
request.sse_customer_algorithm = Some(value.into());
|
||||
request.sse_customer_key_md5 = Some(value.into());
|
||||
request.copy_source_sse_customer_algorithm = Some(value.into());
|
||||
request.copy_source_sse_customer_key_md5 = Some(value.into());
|
||||
request.website_redirect_location = Some(value.into());
|
||||
request.metadata_directive = Some(gateway_dto::MetadataDirective::custom(value.to_owned()));
|
||||
request.tagging_directive = Some(gateway_dto::TaggingDirective::custom(value.to_owned()));
|
||||
request.object_lock_legal_hold_status = Some(gateway_dto::ObjectLockLegalHoldStatus::custom(value.to_owned()));
|
||||
request.object_lock_mode = Some(gateway_dto::ObjectLockMode::custom(value.to_owned()));
|
||||
request.storage_class = Some(gateway_dto::StorageClass::custom(value.to_owned()));
|
||||
request.server_side_encryption = Some(gateway_dto::ServerSideEncryption::custom(value.to_owned()));
|
||||
request.checksum_algorithm = Some(gateway_dto::ChecksumAlgorithm::custom(value.to_owned()));
|
||||
request.expires = Some(OpaqueString::from(value));
|
||||
request
|
||||
});
|
||||
}
|
||||
for (secs, nanos) in [
|
||||
(1_700_000_000, 123_456_789),
|
||||
(-1, 123_456_789),
|
||||
(0, 123_456_789),
|
||||
(i64::MAX, 0),
|
||||
] {
|
||||
compare_input(&mut rows, &format!("retain:{secs}:{nanos}"), || {
|
||||
let mut request = input();
|
||||
request.object_lock_retain_until_date =
|
||||
Some(rustfs_gateway_types::Timestamp::from_secs_nanos(secs, nanos).expect("instant"));
|
||||
request
|
||||
});
|
||||
}
|
||||
for case in [
|
||||
"event-hold",
|
||||
"event-days",
|
||||
"event-years",
|
||||
"source-modified-time",
|
||||
"source-unmodified-time",
|
||||
] {
|
||||
compare_input(&mut rows, case, || {
|
||||
let mut request = input();
|
||||
match case {
|
||||
"event-hold" => request.object_lock_event_hold = Some(gateway_dto::ObjectLockEventHold::custom("ON".to_owned())),
|
||||
"event-days" => request.object_lock_event_hold_duration_days = Some(0),
|
||||
"event-years" => request.object_lock_event_hold_duration_years = Some(1),
|
||||
"source-modified-time" => {
|
||||
request.copy_source_if_modified_since =
|
||||
Some(rustfs_gateway_types::Timestamp::from_secs_nanos(i64::MAX, 0).expect("gateway timestamp"))
|
||||
}
|
||||
_ => {
|
||||
request.copy_source_if_unmodified_since =
|
||||
Some(rustfs_gateway_types::Timestamp::from_secs_nanos(i64::MAX, 0).expect("gateway timestamp"))
|
||||
}
|
||||
}
|
||||
request
|
||||
});
|
||||
}
|
||||
assert!(rows.is_empty(), "CopyObject input projection mismatches: {rows:#?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn protocol_copy_source_projection_matches_legacy() {
|
||||
let mut rows = Vec::new();
|
||||
for bucket in [
|
||||
"x",
|
||||
"ab",
|
||||
"abc",
|
||||
"bad_bucket",
|
||||
"Abc",
|
||||
"127.0.0.1",
|
||||
"a-s3alias",
|
||||
"xn--reserved",
|
||||
"-abc",
|
||||
"abc-",
|
||||
"a..b",
|
||||
"a.-b",
|
||||
"a.b",
|
||||
"a/b",
|
||||
"",
|
||||
"abc\0",
|
||||
] {
|
||||
for key in ["key", "", "/leading", "trailing/", "a?versionId=x", "%FF", "a\0b"] {
|
||||
let source = rustfs_gateway_types::CopySourceValue::Bucket {
|
||||
bucket: bucket.into(),
|
||||
key: key.into(),
|
||||
version_id: Some("ver ?&%é".into()),
|
||||
};
|
||||
let current = owned::copy_source(source.clone())
|
||||
.map(source_facts)
|
||||
.map_err(|error| error.to_string());
|
||||
let old = legacy_copy_source(source)
|
||||
.map(legacy_source_facts)
|
||||
.map_err(|error| conversion_error("CopyObject copy_source", error).to_string());
|
||||
if current != old {
|
||||
rows.push(serde_json::json!([bucket, key, current, old]));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(rows.is_empty(), "CopyObject source projection mismatches: {rows:#?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn protocol_copy_output_projection_matches_legacy() {
|
||||
let mut mismatches = Vec::new();
|
||||
for (raw, tag) in [
|
||||
(None, None),
|
||||
(Some("abc"), Some(ETag::Strong("abc".to_owned()))),
|
||||
(Some("\"abc\""), Some(ETag::Strong("abc".to_owned()))),
|
||||
(Some("W/\"abc\""), Some(ETag::Weak("abc".to_owned()))),
|
||||
(Some("a&\"b"), Some(ETag::Strong("a&"b".to_owned()))),
|
||||
(Some(""), Some(ETag::Strong(String::new()))),
|
||||
(Some("\"\""), Some(ETag::Strong(String::new()))),
|
||||
(Some("a\nb"), Some(ETag::Strong("a\nb".to_owned()))),
|
||||
] {
|
||||
let old = CopyObjectOutput {
|
||||
copy_object_result: Some(CopyObjectResult {
|
||||
e_tag: tag,
|
||||
last_modified: Some(Timestamp::from(
|
||||
time::OffsetDateTime::from_unix_timestamp_nanos(1_700_000_000_123_456_789).expect("instant"),
|
||||
)),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
let old = gateway_s3s_compat::generated::ops::copy_object::output_from_s3s(old)
|
||||
.map(|value| format!("{value:?}"))
|
||||
.map_err(|error| conversion_error("CopyObject output", error).to_string());
|
||||
let current = owned::copy_output(copy_output_facts(raw))
|
||||
.map(|value| format!("{value:?}"))
|
||||
.map_err(|error| error.to_string());
|
||||
if old != current {
|
||||
mismatches.push((raw, current, old));
|
||||
}
|
||||
}
|
||||
let mut current = copy_output_facts(Some("populated"));
|
||||
let mut old = CopyObjectOutput {
|
||||
copy_object_result: Some(CopyObjectResult {
|
||||
e_tag: Some(ETag::Strong("populated".into())),
|
||||
last_modified: Some(Timestamp::from(current.last_modified.expect("fixture instant"))),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
macro_rules! top_fields {
|
||||
($($field:ident),*) => {$(current.$field=Some(stringify!($field).into());old.$field=Some(stringify!($field).into());)*};
|
||||
}
|
||||
top_fields!(
|
||||
version_id,
|
||||
copy_source_version_id,
|
||||
ssekms_key_id,
|
||||
sse_customer_algorithm,
|
||||
sse_customer_key_md5
|
||||
);
|
||||
current.server_side_encryption = Some("AES256".into());
|
||||
old.server_side_encryption = Some(ServerSideEncryption::from("AES256".to_owned()));
|
||||
let result = old.copy_object_result.as_mut().expect("fixture result");
|
||||
macro_rules! result_fields {
|
||||
($($field:ident),*) => {$(current.$field=Some(stringify!($field).into());result.$field=Some(stringify!($field).into());)*};
|
||||
}
|
||||
result_fields!(
|
||||
checksum_crc32,
|
||||
checksum_crc32c,
|
||||
checksum_crc64nvme,
|
||||
checksum_sha1,
|
||||
checksum_sha256,
|
||||
checksum_md5,
|
||||
checksum_sha512,
|
||||
checksum_xxhash3,
|
||||
checksum_xxhash64,
|
||||
checksum_xxhash128
|
||||
);
|
||||
current.checksum_type = Some("FULL_OBJECT".into());
|
||||
result.checksum_type = Some(ChecksumType::from("FULL_OBJECT".to_owned()));
|
||||
let old = gateway_s3s_compat::generated::ops::copy_object::output_from_s3s(old)
|
||||
.map(|value| format!("{value:?}"))
|
||||
.map_err(|error| conversion_error("CopyObject output", error).to_string());
|
||||
let current = owned::copy_output(current)
|
||||
.map(|value| format!("{value:?}"))
|
||||
.map_err(|error| error.to_string());
|
||||
if old != current {
|
||||
mismatches.push((Some("populated"), current, old));
|
||||
}
|
||||
assert!(mismatches.is_empty(), "CopyObject output projection mismatches: {mismatches:#?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn protocol_copy_error_answers_match_legacy() {
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode};
|
||||
let mut rows = Vec::new();
|
||||
for code in [
|
||||
S3ErrorCode::InvalidStorageClass,
|
||||
S3ErrorCode::PreconditionFailed,
|
||||
S3ErrorCode::NotImplemented,
|
||||
S3ErrorCode::InternalError,
|
||||
] {
|
||||
let old: S3Result<()> = Err(S3Error::new(code.clone()).into());
|
||||
let old = old.map_err(S3Error::from).expect_err("legacy error");
|
||||
let current = owned::copy_error(S3Error::new(code.clone()));
|
||||
if (old.code(), old.message(), old.status_code(), old.headers())
|
||||
!= (current.code(), current.message(), current.status_code(), current.headers())
|
||||
{
|
||||
rows.push((
|
||||
code,
|
||||
format!("{:?}:{:?}:{:?}:{:?}", old.code(), old.message(), old.status_code(), old.headers()),
|
||||
format!(
|
||||
"{:?}:{:?}:{:?}:{:?}",
|
||||
current.code(),
|
||||
current.message(),
|
||||
current.status_code(),
|
||||
current.headers()
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
let make = || {
|
||||
let mut error = S3Error::with_message(S3ErrorCode::PreconditionFailed, "copy refusal");
|
||||
error.set_status_code(http::StatusCode::BAD_REQUEST);
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("x-copy-fact", "preserved".parse().expect("fixture header"));
|
||||
error.set_headers(headers);
|
||||
error
|
||||
};
|
||||
let old: S3Result<()> = Err(make().into());
|
||||
let old = old.map_err(S3Error::from).expect_err("legacy refusal");
|
||||
let current = owned::copy_error(make());
|
||||
if (old.code(), old.message(), old.status_code(), old.headers())
|
||||
!= (current.code(), current.message(), current.status_code(), current.headers())
|
||||
{
|
||||
rows.push((
|
||||
S3ErrorCode::PreconditionFailed,
|
||||
format!("{:?}:{:?}:{:?}:{:?}", old.code(), old.message(), old.status_code(), old.headers()),
|
||||
format!(
|
||||
"{:?}:{:?}:{:?}:{:?}",
|
||||
current.code(),
|
||||
current.message(),
|
||||
current.status_code(),
|
||||
current.headers()
|
||||
),
|
||||
));
|
||||
}
|
||||
assert!(rows.is_empty(), "CopyObject error projection mismatches: {rows:#?}");
|
||||
}
|
||||
@@ -16,12 +16,15 @@
|
||||
//! Protocol clients retain their session checks; use cases own storage and bucket visibility.
|
||||
|
||||
use super::{ProtocolStorageClient, RequestParams};
|
||||
use crate::app::object_usecase::{DefaultObjectUsecase, GetObjectBody, GetObjectOutputFacts, HeadObjectOutputFacts};
|
||||
use crate::app::object_usecase::{
|
||||
CopyObjectWriteInput, CopyObjectWriteOutput, CopySourceCondition, DefaultObjectUsecase, GetObjectBody, GetObjectOutputFacts,
|
||||
HeadObjectOutputFacts,
|
||||
};
|
||||
use crate::app::{RequestCredentials, RequestEnvelope, RequestHead};
|
||||
use crate::runtime_sources::current_action_credentials;
|
||||
use crate::storage_api::protocols::client::{ReqInfo, RequestContext};
|
||||
use http::{HeaderMap, Method, Uri};
|
||||
use rustfs_gateway_types::{ETag, Timestamp, dto};
|
||||
use rustfs_gateway_types::{CopySourceValue, ETag, Timestamp, dto};
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result};
|
||||
|
||||
impl ProtocolStorageClient {
|
||||
@@ -399,3 +402,196 @@ pub(super) fn create_bucket_input(bucket: &str) -> S3Result<dto::CreateBucketInp
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn copy_condition(value: Option<&str>, field: &str) -> S3Result<Option<CopySourceCondition>> {
|
||||
let Some(value) = value.filter(|value| !value.is_empty()) else {
|
||||
return Ok(None);
|
||||
};
|
||||
if value == "*" {
|
||||
return Ok(Some(CopySourceCondition::Any));
|
||||
}
|
||||
let quoted = value.strip_prefix("W/").unwrap_or(value);
|
||||
let quoted_tag = quoted.strip_prefix('"').and_then(|value| value.strip_suffix('"'));
|
||||
let valid = if quoted_tag.is_some() {
|
||||
quoted.bytes().all(|byte| byte == b'\t' || (b' '..=b'~').contains(&byte))
|
||||
} else {
|
||||
value.bytes().all(|byte| byte.is_ascii_alphanumeric() || byte == b'-')
|
||||
};
|
||||
if !valid {
|
||||
return Err(super::conversion_error(
|
||||
"CopyObject input",
|
||||
format!("{field}: not an entity-tag condition the s3s input can hold"),
|
||||
));
|
||||
}
|
||||
Ok(Some(if value.starts_with("W/") {
|
||||
CopySourceCondition::Weak
|
||||
} else {
|
||||
CopySourceCondition::Strong(quoted_tag.unwrap_or(value).to_owned())
|
||||
}))
|
||||
}
|
||||
|
||||
pub(super) fn copy_source(source: CopySourceValue) -> S3Result<Option<CopySourceValue>> {
|
||||
let CopySourceValue::Bucket { bucket, key, version_id } = source else {
|
||||
return Ok(None);
|
||||
};
|
||||
let alphanumeric = |byte: u8| byte.is_ascii_lowercase() || byte.is_ascii_digit();
|
||||
if !(3..=63).contains(&bucket.len())
|
||||
|| !bucket.bytes().all(|byte| alphanumeric(byte) || byte == b'.' || byte == b'-')
|
||||
|| !bucket.bytes().next().is_some_and(alphanumeric)
|
||||
|| !bucket.bytes().next_back().is_some_and(alphanumeric)
|
||||
|| bucket.contains("..")
|
||||
|| bucket.starts_with("xn--")
|
||||
|| bucket.parse::<std::net::Ipv4Addr>().is_ok()
|
||||
{
|
||||
return Err(super::conversion_error(
|
||||
"CopyObject copy_source",
|
||||
"ParseAmzCopySourceError: InvalidBucketName",
|
||||
));
|
||||
}
|
||||
Ok(Some(CopySourceValue::Bucket { bucket, key, version_id }))
|
||||
}
|
||||
|
||||
pub(super) fn copy_input(input: dto::CopyObjectInput) -> S3Result<CopyObjectWriteInput> {
|
||||
let copy_source = copy_source(input.copy_source)?;
|
||||
let error = |field, reason| super::conversion_error("CopyObject input", format!("{field}: {reason}"));
|
||||
for (field, named) in [
|
||||
(
|
||||
"object_lock_event_hold",
|
||||
input
|
||||
.object_lock_event_hold
|
||||
.as_ref()
|
||||
.is_some_and(|value| !value.as_str().is_empty()),
|
||||
),
|
||||
(
|
||||
"object_lock_event_hold_duration_days",
|
||||
input.object_lock_event_hold_duration_days.is_some(),
|
||||
),
|
||||
(
|
||||
"object_lock_event_hold_duration_years",
|
||||
input.object_lock_event_hold_duration_years.is_some(),
|
||||
),
|
||||
] {
|
||||
if named {
|
||||
return Err(error(
|
||||
field,
|
||||
"an Object Lock event hold, which no pinned s3s shape holds and RustFS does not store",
|
||||
));
|
||||
}
|
||||
}
|
||||
copy_condition(input.if_match.as_deref(), "if_match")?;
|
||||
let specific_if_none_match = copy_condition(input.if_none_match.as_deref(), "if_none_match")?
|
||||
.is_some_and(|value| !matches!(value, CopySourceCondition::Any));
|
||||
let copy_source_if_match = copy_condition(input.copy_source_if_match.as_deref(), "copy_source_if_match")?;
|
||||
let copy_source_if_none_match = copy_condition(input.copy_source_if_none_match.as_deref(), "copy_source_if_none_match")?;
|
||||
for (field, value) in [
|
||||
("copy_source_if_modified_since", input.copy_source_if_modified_since),
|
||||
("copy_source_if_unmodified_since", input.copy_source_if_unmodified_since),
|
||||
] {
|
||||
value
|
||||
.map(|at| {
|
||||
time::OffsetDateTime::from_unix_timestamp_nanos(
|
||||
i128::from(at.secs()) * 1_000_000_000 + i128::from(at.subsec_nanos()),
|
||||
)
|
||||
.map_err(|_| error(field, "an instant outside what the s3s shape can hold"))
|
||||
})
|
||||
.transpose()?;
|
||||
}
|
||||
let retain_until = input
|
||||
.object_lock_retain_until_date
|
||||
.map(|at| {
|
||||
time::OffsetDateTime::from_unix_timestamp_nanos(i128::from(at.secs()) * 1_000_000_000 + i128::from(at.subsec_nanos()))
|
||||
.map_err(|_| error("object_lock_retain_until_date", "an instant outside what the s3s shape can hold"))
|
||||
})
|
||||
.transpose()?;
|
||||
Ok(CopyObjectWriteInput {
|
||||
copy_source,
|
||||
bucket: input.bucket.as_str().to_owned(),
|
||||
key: input.key.as_str().to_owned(),
|
||||
version_id: None,
|
||||
specific_if_none_match,
|
||||
server_side_encryption: nonempty(input.server_side_encryption.map(|value| value.as_str().to_owned())),
|
||||
ssekms_key_id: nonempty(input.ssekms_key_id),
|
||||
sse_customer_algorithm: nonempty(input.sse_customer_algorithm),
|
||||
sse_customer_key: input.sse_customer_key.map(|value| value.expose_secret().to_owned()),
|
||||
sse_customer_key_md5: nonempty(input.sse_customer_key_md5),
|
||||
copy_source_sse_customer_algorithm: nonempty(input.copy_source_sse_customer_algorithm),
|
||||
copy_source_sse_customer_key: input
|
||||
.copy_source_sse_customer_key
|
||||
.map(|value| value.expose_secret().to_owned()),
|
||||
copy_source_sse_customer_key_md5: nonempty(input.copy_source_sse_customer_key_md5),
|
||||
metadata_directive: nonempty(input.metadata_directive.map(|value| value.as_str().to_owned())),
|
||||
metadata: (!input.metadata.is_empty()).then(|| input.metadata.into_iter().collect()),
|
||||
tagging: nonempty(input.tagging),
|
||||
tagging_directive: nonempty(input.tagging_directive.map(|value| value.as_str().to_owned())),
|
||||
copy_source_if_match,
|
||||
copy_source_if_none_match,
|
||||
cache_control: nonempty(input.cache_control),
|
||||
content_disposition: nonempty(input.content_disposition),
|
||||
content_encoding: nonempty(input.content_encoding),
|
||||
content_language: nonempty(input.content_language),
|
||||
content_type: nonempty(input.content_type),
|
||||
expires: nonempty(input.expires.map(|value| value.as_str().to_owned())),
|
||||
website_redirect_location: nonempty(input.website_redirect_location),
|
||||
object_lock_legal_hold_status: nonempty(input.object_lock_legal_hold_status.map(|value| value.as_str().to_owned())),
|
||||
object_lock_mode: nonempty(input.object_lock_mode.map(|value| value.as_str().to_owned())),
|
||||
object_lock_retain_until_date: retain_until,
|
||||
storage_class: nonempty(input.storage_class.map(|value| value.as_str().to_owned())),
|
||||
checksum_algorithm: nonempty(input.checksum_algorithm.map(|value| value.as_str().to_owned())),
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn copy_output(output: CopyObjectWriteOutput) -> S3Result<dto::CopyObjectOutput> {
|
||||
let e_tag = output
|
||||
.e_tag
|
||||
.map(|raw| {
|
||||
let (weak, value) = if let Some(rest) = raw.strip_prefix("W/\"") {
|
||||
(true, rest.strip_suffix('"').unwrap_or(rest))
|
||||
} else {
|
||||
(false, raw.strip_prefix('"').and_then(|rest| rest.strip_suffix('"')).unwrap_or(&raw))
|
||||
};
|
||||
let value = quick_xml::escape::escape(value).into_owned();
|
||||
if weak { ETag::new_weak(value) } else { ETag::new(value) }
|
||||
.map_err(|_| super::conversion_error("CopyObject output", "e_tag: not an entity tag the gateway can write"))
|
||||
})
|
||||
.transpose()?;
|
||||
Ok(dto::CopyObjectOutput {
|
||||
e_tag,
|
||||
last_modified: output
|
||||
.last_modified
|
||||
.map(crate::app::dto_values::timestamp)
|
||||
.map(millisecond_timestamp),
|
||||
copy_source_version_id: output.copy_source_version_id,
|
||||
version_id: output.version_id,
|
||||
server_side_encryption: output.server_side_encryption.map(dto::ServerSideEncryption::custom),
|
||||
ssekms_key_id: output.ssekms_key_id,
|
||||
sse_customer_algorithm: output.sse_customer_algorithm,
|
||||
sse_customer_key_md5: output.sse_customer_key_md5,
|
||||
checksum_crc32: output.checksum_crc32,
|
||||
checksum_crc32c: output.checksum_crc32c,
|
||||
checksum_sha1: output.checksum_sha1,
|
||||
checksum_sha256: output.checksum_sha256,
|
||||
checksum_crc64nvme: output.checksum_crc64nvme,
|
||||
checksum_md5: output.checksum_md5,
|
||||
checksum_sha512: output.checksum_sha512,
|
||||
checksum_xxhash3: output.checksum_xxhash3,
|
||||
checksum_xxhash64: output.checksum_xxhash64,
|
||||
checksum_xxhash128: output.checksum_xxhash128,
|
||||
checksum_type: output.checksum_type,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn copy_error(mut error: S3Error) -> S3Error {
|
||||
if error.message().is_some() {
|
||||
return error;
|
||||
}
|
||||
let message = match error.code() {
|
||||
S3ErrorCode::InvalidStorageClass => "The storage class you specified is not valid.",
|
||||
S3ErrorCode::PreconditionFailed => "At least one of the preconditions you specified did not hold.",
|
||||
S3ErrorCode::NotImplemented => "A header you provided implies functionality that is not implemented.",
|
||||
S3ErrorCode::InternalError => "We encountered an internal error. Please try again.",
|
||||
_ => return error,
|
||||
};
|
||||
error.set_message(message);
|
||||
error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user