// 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::error::Result; use rmp_serde::Serializer as rmpSerializer; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; #[derive(Debug, Deserialize, Serialize, Default, Clone)] pub struct Credentials { #[serde(rename = "accessKey")] pub access_key: String, #[serde(rename = "secretKey")] pub secret_key: String, pub session_token: Option, pub expiration: Option>, } #[derive(Debug, Deserialize, Serialize, Default, Clone)] pub enum ServiceType { #[default] Replication, } #[derive(Debug, Deserialize, Serialize, Default, Clone)] pub struct LatencyStat { curr: u64, // current latency avg: u64, // average latency max: u64, // maximum latency } // Define BucketTarget struct #[derive(Debug, Deserialize, Serialize, Default, Clone)] pub struct BucketTarget { #[serde(rename = "sourcebucket")] pub source_bucket: String, pub endpoint: String, pub credentials: Option, #[serde(rename = "targetbucket")] pub target_bucket: String, secure: bool, pub path: Option, api: Option, pub arn: Option, #[serde(rename = "type")] pub type_: Option, pub region: Option, bandwidth_limit: Option, #[serde(rename = "replicationSync")] replication_sync: bool, storage_class: Option, #[serde(rename = "healthCheckDuration")] health_check_duration: u64, #[serde(rename = "disableProxy")] disable_proxy: bool, #[serde(rename = "resetBeforeDate")] reset_before_date: String, reset_id: Option, #[serde(rename = "totalDowntime")] total_downtime: u64, last_online: Option, #[serde(rename = "isOnline")] online: bool, latency: Option, deployment_id: Option, edge: bool, #[serde(rename = "edgeSyncBeforeExpiry")] edge_sync_before_expiry: bool, } impl BucketTarget { pub fn is_empty(self) -> bool { //self.target_bucket.is_empty() && self.endpoint.is_empty() && self.arn.is_empty() self.target_bucket.is_empty() && self.endpoint.is_empty() && self.arn.is_none() } } #[derive(Debug, Deserialize, Serialize, Default, Clone)] pub struct BucketTargets { pub targets: Vec, } impl BucketTargets { pub fn marshal_msg(&self) -> Result> { let mut buf = Vec::new(); self.serialize(&mut rmpSerializer::new(&mut buf).with_struct_map())?; Ok(buf) } pub fn unmarshal(buf: &[u8]) -> Result { let t: BucketTargets = rmp_serde::from_slice(buf)?; Ok(t) } pub fn is_empty(&self) -> bool { if self.targets.is_empty() { return true; } for target in &self.targets { if !target.clone().is_empty() { return false; } } true } }