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 6BFDD1FF140 for ; Fri, 24 Apr 2026 12:36:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 481F613464; Fri, 24 Apr 2026 12:36:53 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup 3/3] api: encryption keys: refactor associated keys check Date: Fri, 24 Apr 2026 12:36:07 +0200 Message-ID: <20260424103607.531400-4-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260424103607.531400-1-c.ebner@proxmox.com> References: <20260424103607.531400-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1777026888964 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.070 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 Message-ID-Hash: RMS3DNMVAHEBPQYMI5P64CQSKG5TGPTZ X-Message-ID-Hash: RMS3DNMVAHEBPQYMI5P64CQSKG5TGPTZ X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Fixes an if_same_then_else clippy warning and improves the readability for the check of sync jobs having a key assigned as associated key. Both branches have the same push logic, so combine into a common if statement. Since the if statement would then however be hard to parse, move the associated key check logic into a closue instead. Signed-off-by: Christian Ebner --- src/api2/config/encryption_keys.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/api2/config/encryption_keys.rs b/src/api2/config/encryption_keys.rs index 81483302e..5c0c08e52 100644 --- a/src/api2/config/encryption_keys.rs +++ b/src/api2/config/encryption_keys.rs @@ -195,15 +195,17 @@ fn check_encryption_key_in_use(id: &str, include_associated: bool) -> Result<(), let mut used_by_jobs = Vec::new(); let job_list: Vec = config.convert_to_typed_array("sync")?; + + let contains_associated_key = |job: &SyncJobConfig| { + job.associated_key + .as_deref() + .unwrap_or(&[]) + .contains(&id.to_string()) + }; + for job in job_list { - if job.active_encryption_key.as_deref() == Some(id) { - used_by_jobs.push(job.id.clone()); - } else if include_associated - && job - .associated_key - .as_deref() - .unwrap_or(&[]) - .contains(&id.to_string()) + if job.active_encryption_key.as_deref() == Some(id) + || (include_associated && contains_associated_key(&job)) { used_by_jobs.push(job.id.clone()); } -- 2.47.3