From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id B43751FF163 for ; Thu, 10 Oct 2024 16:49:01 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2EDB21C95F; Thu, 10 Oct 2024 16:49:30 +0200 (CEST) Date: Thu, 10 Oct 2024 16:48:51 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20240912143322.548839-1-c.ebner@proxmox.com> <20240912143322.548839-17-c.ebner@proxmox.com> In-Reply-To: <20240912143322.548839-17-c.ebner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1728560818.cdhd0ts9dx.astroid@yuna.none> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.049 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: Re: [pbs-devel] [PATCH v3 proxmox-backup 16/33] config: jobs: 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" On September 12, 2024 4:33 pm, Christian Ebner wrote: > 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. > > 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 2: > - no changes > > pbs-api-types/src/jobs.rs | 52 +++++++++++++++++++++++++++++++++++++++ > pbs-config/src/sync.rs | 11 +++++++-- > 2 files changed, 61 insertions(+), 2 deletions(-) > > diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs > index 868702bc0..12b39782c 100644 > --- a/pbs-api-types/src/jobs.rs > +++ b/pbs-api-types/src/jobs.rs > @@ -20,6 +20,8 @@ const_regex! { > pub VERIFICATION_JOB_WORKER_ID_REGEX = concatcp!(r"^(", PROXMOX_SAFE_ID_REGEX_STR, r"):"); > /// Regex for sync jobs '(REMOTE|\-):REMOTE_DATASTORE:LOCAL_DATASTORE:(?:LOCAL_NS_ANCHOR:)ACTUAL_JOB_ID' > pub SYNC_JOB_WORKER_ID_REGEX = concatcp!(r"^(", PROXMOX_SAFE_ID_REGEX_STR, r"|\-):(", PROXMOX_SAFE_ID_REGEX_STR, r"):(", PROXMOX_SAFE_ID_REGEX_STR, r")(?::(", BACKUP_NS_RE, r"))?:"); > + /// Regex for sync direction'(pull|push)' > + pub SYNC_DIRECTION_REGEX = r"^(pull|push)$"; > } > > pub const JOB_ID_SCHEMA: Schema = StringSchema::new("Job ID.") > @@ -498,6 +500,56 @@ pub const TRANSFER_LAST_SCHEMA: Schema = > .minimum(1) > .schema(); > > +pub const SYNC_DIRECTION_SCHEMA: Schema = StringSchema::new("Sync job direction (pull|push)") > + .format(&ApiStringFormat::Pattern(&SYNC_DIRECTION_REGEX)) > + .schema(); > + > +/// Direction of the sync job, push or pull > +#[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash, UpdaterType)] > +pub enum SyncDirection { > + #[default] > + Pull, > + Push, > +} > + > +impl ApiType for SyncDirection { > + const API_SCHEMA: Schema = SYNC_DIRECTION_SCHEMA; > +} > + > +// used for serialization using `proxmox_serde::forward_serialize_to_display` macro > +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 std::str::FromStr for SyncDirection { > + type Err = anyhow::Error; > + > + fn from_str(s: &str) -> Result { > + match s { > + "pull" => Ok(SyncDirection::Pull), > + "push" => Ok(SyncDirection::Push), > + _ => bail!("invalid sync direction"), > + } > + } > +} > + > +proxmox_serde::forward_deserialize_to_from_str!(SyncDirection); > +proxmox_serde::forward_serialize_to_display!(SyncDirection); wouldn't just implementing Display, and deriving Serialize/Deserialize be enough? > + > +impl SyncDirection { > + pub fn as_config_type_str(&self) -> &'static str { > + match self { > + SyncDirection::Pull => "sync", > + SyncDirection::Push => "sync-push", > + } > + } > +} > + > #[api( > properties: { > id: { > diff --git a/pbs-config/src/sync.rs b/pbs-config/src/sync.rs > index 45453abb1..143b73e78 100644 > --- a/pbs-config/src/sync.rs > +++ b/pbs-config/src/sync.rs > @@ -18,9 +18,16 @@ fn init() -> SectionConfig { > _ => unreachable!(), > }; > > - let plugin = SectionConfigPlugin::new("sync".to_string(), Some(String::from("id")), obj_schema); > + let pull_plugin = > + SectionConfigPlugin::new("sync".to_string(), Some(String::from("id")), obj_schema); > + let push_plugin = SectionConfigPlugin::new( > + "sync-push".to_string(), these here should probably use SyncDirection's as_config_type_str to make the connection obvious when adapting that at some point in the future? > + 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.2 > > > > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel > > > _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel