refactor: move object option helper contracts (#3521)

This commit is contained in:
安正超
2026-06-17 22:56:10 +08:00
committed by GitHub
parent a97122ab80
commit 919deeb816
22 changed files with 222 additions and 111 deletions
+3 -1
View File
@@ -18,8 +18,10 @@ pub mod admin;
pub mod bucket;
pub mod error;
pub mod multipart;
pub mod object;
pub use admin::{DiskSetSelector, StorageAdminApi};
pub use bucket::{BucketInfo, BucketOperations, BucketOptions, DeleteBucketOptions, MakeBucketOptions, SRBucketDeleteOp};
pub use error::{StorageErrorCode, StorageResult};
pub use multipart::{ListMultipartsInfo, ListPartsInfo, MultipartInfo, MultipartUploadResult, PartInfo};
pub use multipart::{CompletePart, ListMultipartsInfo, ListPartsInfo, MultipartInfo, MultipartUploadResult, PartInfo};
pub use object::{HTTPPreconditions, ObjectLockRetentionOptions};
+29
View File
@@ -69,3 +69,32 @@ pub struct ListPartsInfo {
pub checksum_algorithm: String,
pub checksum_type: String,
}
#[derive(Debug, Clone, Default)]
pub struct CompletePart {
pub part_num: usize,
pub etag: Option<String>,
pub checksum_crc32: Option<String>,
pub checksum_crc32c: Option<String>,
pub checksum_sha1: Option<String>,
pub checksum_sha256: Option<String>,
pub checksum_crc64nvme: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn complete_part_defaults_preserve_empty_checksums() {
let part = CompletePart::default();
assert_eq!(part.part_num, 0);
assert!(part.etag.is_none());
assert!(part.checksum_crc32.is_none());
assert!(part.checksum_crc32c.is_none());
assert!(part.checksum_sha1.is_none());
assert!(part.checksum_sha256.is_none());
assert!(part.checksum_crc64nvme.is_none());
}
}
+70
View File
@@ -0,0 +1,70 @@
// 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.
use time::OffsetDateTime;
#[derive(Debug, Default, Clone)]
pub struct HTTPPreconditions {
pub if_match: Option<String>,
pub if_none_match: Option<String>,
pub if_modified_since: Option<OffsetDateTime>,
pub if_unmodified_since: Option<OffsetDateTime>,
}
impl HTTPPreconditions {
pub fn if_match_value(&self) -> Option<&str> {
non_empty_condition_value(self.if_match.as_deref())
}
pub fn if_none_match_value(&self) -> Option<&str> {
non_empty_condition_value(self.if_none_match.as_deref())
}
}
#[derive(Debug, Default, Clone)]
pub struct ObjectLockRetentionOptions {
pub mode: Option<String>,
pub retain_until: Option<OffsetDateTime>,
pub bypass_governance: bool,
}
fn non_empty_condition_value(value: Option<&str>) -> Option<&str> {
value.map(str::trim).filter(|value| !value.is_empty())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn http_preconditions_ignore_empty_etag_headers() {
let opts = HTTPPreconditions {
if_match: Some(" ".to_owned()),
if_none_match: Some(" * ".to_owned()),
..Default::default()
};
assert_eq!(opts.if_match_value(), None);
assert_eq!(opts.if_none_match_value(), Some("*"));
}
#[test]
fn object_lock_retention_defaults_preserve_false_bypass() {
let opts = ObjectLockRetentionOptions::default();
assert!(opts.mode.is_none());
assert!(opts.retain_until.is_none());
assert!(!opts.bypass_governance);
}
}