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 5A29C1FF173 for ; Mon, 25 Nov 2024 12:15:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A9D8210B43; Mon, 25 Nov 2024 12:15:41 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 25 Nov 2024 12:15:33 +0100 Message-Id: <20241125111537.1504618-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241125111537.1504618-1-d.csapak@proxmox.com> References: <20241125111537.1504618-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 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 proxmox-backup 2/6] api: admin: sync: add optional 'all' sync type for listing 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" so that one can list all sync jobs, both pull and push, at the same time. To not confuse existing clients that only know of pull syncs, show only them by default and make the 'all' parameter opt-in. (But add a todo for 4.x to change that) Signed-off-by: Dominik Csapak --- src/api2/admin/sync.rs | 66 ++++++++++++++++++++-------- src/api2/config/datastore.rs | 9 ++-- src/api2/config/notifications/mod.rs | 2 +- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs index 479f1a958..2b8fce484 100644 --- a/src/api2/admin/sync.rs +++ b/src/api2/admin/sync.rs @@ -1,7 +1,7 @@ //! Datastore Synchronization Job Management use anyhow::{bail, format_err, Error}; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use serde_json::Value; use proxmox_router::{ @@ -23,6 +23,30 @@ use crate::{ server::sync::do_sync_job, }; +// FIXME: 4.x make 'all' the default +#[api()] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +/// The direction of the listed sync jobs: push, pull or all. +pub enum ListSyncDirection { + /// All directions + All, + /// Sync direction push + Push, + /// Sync direction pull + #[default] + Pull, +} + +impl From for ListSyncDirection { + fn from(value: SyncDirection) -> Self { + match value { + SyncDirection::Pull => ListSyncDirection::Pull, + SyncDirection::Push => ListSyncDirection::Push, + } + } +} + #[api( input: { properties: { @@ -31,7 +55,7 @@ use crate::{ optional: true, }, "sync-direction": { - type: SyncDirection, + type: ListSyncDirection, optional: true, }, }, @@ -49,7 +73,7 @@ use crate::{ /// List all configured sync jobs pub fn list_config_sync_jobs( store: Option, - sync_direction: Option, + sync_direction: Option, _param: Value, rpcenv: &mut dyn RpcEnvironment, ) -> Result, Error> { @@ -59,23 +83,27 @@ pub fn list_config_sync_jobs( let (config, digest) = sync::config()?; let sync_direction = sync_direction.unwrap_or_default(); - let job_config_iter = config - .convert_to_typed_array(sync_direction.as_config_type_str())? - .into_iter() - .filter(|job: &SyncJobConfig| { - if let Some(store) = &store { - &job.store == store - } else { - true - } - }) - .filter(|job: &SyncJobConfig| { - check_sync_job_read_access(&user_info, &auth_id, job, sync_direction) - }); - let mut list = Vec::new(); + let mut list = Vec::with_capacity(config.sections.len()); + for (_, (sync_type, job)) in config.sections.into_iter() { + let job: SyncJobConfig = serde_json::from_value(job)?; + let direction = SyncDirection::from_config_type_str(&sync_type)?; + + match &store { + Some(store) if &job.store != store => continue, + _ => {} + } + + match &sync_direction { + ListSyncDirection::Pull if direction != SyncDirection::Pull => continue, + ListSyncDirection::Push if direction != SyncDirection::Push => continue, + _ => {} + } + + if !check_sync_job_read_access(&user_info, &auth_id, &job, direction) { + continue; + } - for job in job_config_iter { let last_state = JobState::load("syncjob", &job.id) .map_err(|err| format_err!("could not open statefile for {}: {}", &job.id, err))?; @@ -84,7 +112,7 @@ pub fn list_config_sync_jobs( list.push(SyncJobStatus { config: job, status, - direction: sync_direction, + direction, }); } diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 37d1528c7..8c307a233 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -526,9 +526,12 @@ pub async fn delete_datastore( delete_verification_job(job.config.id, None, rpcenv)? } for direction in [SyncDirection::Pull, SyncDirection::Push] { - for job in - list_config_sync_jobs(Some(name.clone()), Some(direction), Value::Null, rpcenv)? - { + for job in list_config_sync_jobs( + Some(name.clone()), + Some(direction.into()), + Value::Null, + rpcenv, + )? { delete_sync_job(job.config.id, None, rpcenv)? } } diff --git a/src/api2/config/notifications/mod.rs b/src/api2/config/notifications/mod.rs index f156c8cfd..2081b7b75 100644 --- a/src/api2/config/notifications/mod.rs +++ b/src/api2/config/notifications/mod.rs @@ -155,7 +155,7 @@ pub fn get_values( } for direction in [SyncDirection::Pull, SyncDirection::Push] { - let sync_jobs = list_config_sync_jobs(None, Some(direction), param.clone(), rpcenv)?; + let sync_jobs = list_config_sync_jobs(None, Some(direction.into()), param.clone(), rpcenv)?; for job in sync_jobs { values.push(MatchableValue { field: "job-id".into(), -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel