mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 00:38:16 +00:00
init bucketmeta struct
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// 定义Algorithm枚举类型
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Algorithm {
|
||||
AES256,
|
||||
AWSKms,
|
||||
}
|
||||
|
||||
// 实现从字符串到Algorithm的转换
|
||||
impl std::str::FromStr for Algorithm {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"AES256" => Ok(Algorithm::AES256),
|
||||
"aws:kms" => Ok(Algorithm::AWSKms),
|
||||
_ => Err(format!("未知的 SSE 算法: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 定义EncryptionAction结构体
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct EncryptionAction {
|
||||
algorithm: Option<Algorithm>,
|
||||
master_key_id: Option<String>,
|
||||
}
|
||||
|
||||
// 定义Rule结构体
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Rule {
|
||||
default_encryption_action: EncryptionAction,
|
||||
}
|
||||
|
||||
// 定义BucketSSEConfig结构体
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BucketSSEConfig {
|
||||
xml_ns: String,
|
||||
xml_name: String,
|
||||
rules: Vec<Rule>,
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::{prefix::Prefix, tag::Tag};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct And {
|
||||
pub object_size_greater_than: i64,
|
||||
pub object_size_less_than: i64,
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#[derive(Debug)]
|
||||
pub struct DelMarkerExpiration {
|
||||
pub days: usize,
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::{and::And, prefix::Prefix, tag::Tag};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Filter {
|
||||
pub set: bool,
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use super::rule::Rule;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Lifecycle {
|
||||
pub rules: Vec<Rule>,
|
||||
pub expiry_updated_at: Option<OffsetDateTime>,
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
mod and;
|
||||
mod delmarker;
|
||||
mod expiration;
|
||||
mod fileter;
|
||||
pub(crate) mod lifecycle;
|
||||
mod noncurrentversion;
|
||||
mod prefix;
|
||||
mod rule;
|
||||
mod tag;
|
||||
mod transition;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
use super::{expiration::ExpirationDays, transition::TransitionDays};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NoncurrentVersionExpiration {
|
||||
pub noncurrent_days: ExpirationDays,
|
||||
pub newer_noncurrent_versions: usize,
|
||||
set: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NoncurrentVersionTransition {
|
||||
pub noncurrent_days: TransitionDays,
|
||||
pub storage_class: String,
|
||||
set: bool,
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#[derive(Debug)]
|
||||
pub struct Prefix {
|
||||
pub val: String,
|
||||
pub set: bool,
|
||||
pub val: String,
|
||||
pub set: bool,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
use super::{
|
||||
delmarker::DelMarkerExpiration,
|
||||
expiration::Expiration,
|
||||
fileter::Filter,
|
||||
noncurrentversion::{NoncurrentVersionExpiration, NoncurrentVersionTransition},
|
||||
prefix::Prefix,
|
||||
transition::Transition,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Status {
|
||||
Enabled,
|
||||
Disabled,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Rule {
|
||||
pub id: String,
|
||||
pub status: Status,
|
||||
pub filter: Filter,
|
||||
pub prefix: Prefix,
|
||||
pub pxpiration: Expiration,
|
||||
pub transition: Transition,
|
||||
pub del_marker_expiration: DelMarkerExpiration,
|
||||
pub noncurrent_version_expiration: NoncurrentVersionExpiration,
|
||||
pub noncurrent_version_transition: NoncurrentVersionTransition,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use time::OffsetDateTime;
|
||||
|
||||
pub type TransitionDays = usize;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TransitionDate(OffsetDateTime);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Transition {
|
||||
pub days: Option<TransitionDays>,
|
||||
pub date: Option<TransitionDate>,
|
||||
pub storage_class: String,
|
||||
|
||||
pub set: bool,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use super::{event, policy::bucket_policy::BucketPolicy};
|
||||
use super::{
|
||||
encryption::BucketSSEConfig, event, lifecycle::lifecycle::Lifecycle, objectlock, policy::bucket_policy::BucketPolicy,
|
||||
quota::BucketQuota, replication, tags::Tags, versioning::Versioning,
|
||||
};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct BucketMetadata {
|
||||
@@ -40,29 +43,15 @@ pub struct BucketMetadata {
|
||||
policy_config: Option<BucketPolicy>, // 假设Policy是一个已经定义好的结构体
|
||||
notification_config: Option<event::config::Config>,
|
||||
lifecycle_config: Option<Lifecycle>,
|
||||
object_lock_config: Option<ObjectLock>,
|
||||
object_lock_config: Option<objectlock::Config>,
|
||||
versioning_config: Option<Versioning>,
|
||||
sse_config: Option<BucketSSEConfig>,
|
||||
tagging_config: Option<Tags>,
|
||||
quota_config: Option<BucketQuota>,
|
||||
replication_config: Option<ReplicationConfig>,
|
||||
replication_config: Option<replication::Config>,
|
||||
bucket_target_config: Option<BucketTargets>,
|
||||
bucket_target_config_meta: Option<std::collections::HashMap<String, String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct Lifecycle;
|
||||
#[derive(Debug, Default)]
|
||||
struct ObjectLock;
|
||||
#[derive(Debug, Default)]
|
||||
struct Versioning;
|
||||
#[derive(Debug, Default)]
|
||||
struct BucketSSEConfig;
|
||||
#[derive(Debug, Default)]
|
||||
struct Tags;
|
||||
#[derive(Debug, Default)]
|
||||
struct BucketQuota;
|
||||
#[derive(Debug, Default)]
|
||||
struct ReplicationConfig;
|
||||
#[derive(Debug, Default)]
|
||||
struct BucketTargets;
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
mod encryption;
|
||||
mod event;
|
||||
mod lifecycle;
|
||||
mod metadata;
|
||||
mod objectlock;
|
||||
mod policy;
|
||||
mod quota;
|
||||
mod replication;
|
||||
mod tags;
|
||||
mod versioning;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum RetMode {
|
||||
Govenance,
|
||||
Compliance,
|
||||
}
|
||||
|
||||
// 为RetMode实现FromStr trait,方便从字符串创建枚举实例
|
||||
impl std::str::FromStr for RetMode {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"GOVERNANCE" => Ok(RetMode::Govenance),
|
||||
"COMPLIANCE" => Ok(RetMode::Compliance),
|
||||
_ => Err(format!("Invalid RetMode: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DefaultRetention {
|
||||
pub mode: RetMode,
|
||||
pub days: Option<usize>,
|
||||
pub years: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Rule {
|
||||
pub default_retention: DefaultRetention,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
pub object_lock_enabled: String,
|
||||
pub rule: Option<Rule>,
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// 定义QuotaType枚举类型
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum QuotaType {
|
||||
Hard,
|
||||
}
|
||||
|
||||
// 定义BucketQuota结构体
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BucketQuota {
|
||||
quota: Option<u64>, // 使用Option来表示可能不存在的字段
|
||||
|
||||
size: u64,
|
||||
|
||||
rate: u64,
|
||||
|
||||
requests: u64,
|
||||
|
||||
quota_type: Option<QuotaType>,
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
use super::tag::Tag;
|
||||
|
||||
// 定义And结构体
|
||||
#[derive(Debug)]
|
||||
pub struct And {
|
||||
prefix: Option<String>,
|
||||
tags: Option<Vec<Tag>>,
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
use super::and::And;
|
||||
use super::tag::Tag;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Filter {
|
||||
prefix: String,
|
||||
and: And,
|
||||
tag: Tag,
|
||||
cached_tags: HashMap<String, String>,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use rule::Rule;
|
||||
|
||||
mod and;
|
||||
mod filter;
|
||||
mod rule;
|
||||
mod tag;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
rules: Vec<Rule>,
|
||||
role_arn: String,
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
use super::filter::Filter;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Status {
|
||||
Enabled,
|
||||
Disabled,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DeleteMarkerReplication {
|
||||
pub status: Status,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DeleteReplication {
|
||||
pub status: Status,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ExistingObjectReplication {
|
||||
pub status: Status,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Destination {
|
||||
pub bucket: String,
|
||||
pub storage_class: String,
|
||||
pub arn: String,
|
||||
}
|
||||
|
||||
// 定义ReplicaModifications结构体
|
||||
#[derive(Debug)]
|
||||
pub struct ReplicaModifications {
|
||||
status: Status,
|
||||
}
|
||||
|
||||
// 定义SourceSelectionCriteria结构体
|
||||
#[derive(Debug)]
|
||||
pub struct SourceSelectionCriteria {
|
||||
replica_modifications: ReplicaModifications,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Rule {
|
||||
pub id: String,
|
||||
pub status: Status,
|
||||
pub priority: usize,
|
||||
pub delete_marker_replication: DeleteMarkerReplication,
|
||||
pub delete_replication: DeleteReplication,
|
||||
pub destination: Destination,
|
||||
pub source_selection_criteria: SourceSelectionCriteria,
|
||||
pub filter: Filter,
|
||||
pub existing_object_replication: ExistingObjectReplication,
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#[derive(Debug)]
|
||||
pub struct Tag {
|
||||
pub key: Option<String>,
|
||||
pub value: Option<String>,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
// 定义tagSet结构体
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct TagSet {
|
||||
#[serde(rename = "Tag")]
|
||||
tag_map: HashMap<String, String>,
|
||||
is_object: bool,
|
||||
}
|
||||
|
||||
// 定义tagging结构体
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Tags {
|
||||
#[serde(rename = "Tagging")]
|
||||
xml_name: String,
|
||||
#[serde(rename = "TagSet")]
|
||||
tag_set: Option<TagSet>,
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum State {
|
||||
Enabled,
|
||||
Suspended,
|
||||
// 如果未来可能会使用到Disabled状态,可以在这里添加
|
||||
// Disabled,
|
||||
}
|
||||
|
||||
// 实现Display trait用于打印
|
||||
impl std::fmt::Display for State {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match *self {
|
||||
State::Enabled => "Enabled",
|
||||
State::Suspended => "Suspended",
|
||||
// 如果未来可能会使用到Disabled状态,可以在这里添加
|
||||
// State::Disabled => "Disabled",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ExcludedPrefix {
|
||||
pub prefix: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Versioning {
|
||||
pub status: State,
|
||||
pub excluded_prefixes: Vec<ExcludedPrefix>,
|
||||
pub exclude_folders: bool,
|
||||
}
|
||||
Reference in New Issue
Block a user