From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 09C6F1FF173 for ; Mon, 11 Nov 2024 16:44:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D02A61006A; Mon, 11 Nov 2024 16:44:42 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 11 Nov 2024 16:43:38 +0100 Message-Id: <20241111154353.482734-17-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241111154353.482734-1-c.ebner@proxmox.com> References: <20241111154353.482734-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.032 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH v7 proxmox-backup 16/31] api types/config: add `sync-push` config type for push sync jobs X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" In order for sync jobs to be either pull or push jobs, allow to configure the direction of the job. Adds an additional config type `sync-push` to the sync job config, to clearly distinguish sync jobs configured in pull and in push direction and defines and implements the required `SyncDirection` api type. This approach was chosen in order to limit possible misconfiguration, as unintentionally switching the sync direction could potentially delete still required snapshots. Signed-off-by: Christian Ebner --- changes since version 6: - no changes pbs-api-types/src/jobs.rs | 38 ++++++++++++++++++++++++++++++++++++++ pbs-config/src/sync.rs | 16 +++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs index bf7a6bd5a..e8056beb0 100644 --- a/pbs-api-types/src/jobs.rs +++ b/pbs-api-types/src/jobs.rs @@ -498,6 +498,44 @@ pub const TRANSFER_LAST_SCHEMA: Schema = .minimum(1) .schema(); +#[api()] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +/// Direction of the sync job, push or pull +pub enum SyncDirection { + /// Sync direction pull + #[default] + Pull, + /// Sync direction push + Push, +} + +impl std::fmt::Display for SyncDirection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SyncDirection::Pull => f.write_str("pull"), + SyncDirection::Push => f.write_str("push"), + } + } +} + +impl SyncDirection { + pub fn as_config_type_str(&self) -> &'static str { + match self { + SyncDirection::Pull => "sync", + SyncDirection::Push => "sync-push", + } + } + + pub fn from_config_type_str(config_type: &str) -> Result { + match config_type { + "sync" => Ok(SyncDirection::Pull), + "sync-push" => Ok(SyncDirection::Push), + _ => bail!("invalid config type for sync job"), + } + } +} + #[api( properties: { id: { diff --git a/pbs-config/src/sync.rs b/pbs-config/src/sync.rs index 45453abb1..7fc977e77 100644 --- a/pbs-config/src/sync.rs +++ b/pbs-config/src/sync.rs @@ -6,7 +6,7 @@ use anyhow::Error; use proxmox_schema::{ApiType, Schema}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; -use pbs_api_types::{SyncJobConfig, JOB_ID_SCHEMA}; +use pbs_api_types::{SyncDirection, SyncJobConfig, JOB_ID_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; @@ -18,9 +18,19 @@ fn init() -> SectionConfig { _ => unreachable!(), }; - let plugin = SectionConfigPlugin::new("sync".to_string(), Some(String::from("id")), obj_schema); + let pull_plugin = SectionConfigPlugin::new( + SyncDirection::Pull.as_config_type_str().to_string(), + Some(String::from("id")), + obj_schema, + ); + let push_plugin = SectionConfigPlugin::new( + SyncDirection::Push.as_config_type_str().to_string(), + Some(String::from("id")), + obj_schema, + ); let mut config = SectionConfig::new(&JOB_ID_SCHEMA); - config.register_plugin(plugin); + config.register_plugin(pull_plugin); + config.register_plugin(push_plugin); config } -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel