refactor(replication): move config contracts into crate (#4162)

This commit is contained in:
Zhengchao An
2026-07-02 10:17:48 +08:00
committed by GitHub
parent 18b79ccc2a
commit b57820a486
10 changed files with 482 additions and 411 deletions
+50
View File
@@ -0,0 +1,50 @@
// 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 crate::config::ObjectOpts;
use s3s::dto::ReplicaModificationsStatus;
use s3s::dto::ReplicationRule;
pub trait ReplicationRuleExt {
fn prefix(&self) -> &str;
fn metadata_replicate(&self, obj: &ObjectOpts) -> bool;
}
impl ReplicationRuleExt for ReplicationRule {
fn prefix(&self) -> &str {
if let Some(filter) = &self.filter {
if let Some(prefix) = &filter.prefix {
prefix
} else if let Some(and) = &filter.and {
and.prefix.as_deref().unwrap_or("")
} else {
""
}
} else {
""
}
}
fn metadata_replicate(&self, obj: &ObjectOpts) -> bool {
if !obj.replica {
return true;
}
self.source_selection_criteria.as_ref().is_some_and(|s| {
s.replica_modifications
.clone()
.is_some_and(|r| r.status == ReplicaModificationsStatus::from_static(ReplicaModificationsStatus::ENABLED))
})
}
}