all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
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	[thread overview]
Message-ID: <20260424103607.531400-4-c.ebner@proxmox.com> (raw)
In-Reply-To: <20260424103607.531400-1-c.ebner@proxmox.com>

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 <c.ebner@proxmox.com>
---
 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<SyncJobConfig> = 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





  parent reply	other threads:[~2026-04-24 10:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24 10:36 [PATCH proxmox-backup 0/3] fixup for server side decryption Christian Ebner
2026-04-24 10:36 ` [PATCH proxmox-backup 1/3] sync: pull decrypt: check if contents only signed or fully encrypted Christian Ebner
2026-04-24 10:36 ` [PATCH proxmox-backup 2/3] sync: pull: refactor decryption key loading checks Christian Ebner
2026-04-24 12:46   ` Fabian Grünbichler
2026-04-24 10:36 ` Christian Ebner [this message]
2026-04-24 12:46 ` [PATCH proxmox-backup 1/2] pull: decrypt: use let else to reduce indentation Fabian Grünbichler
2026-04-24 12:46   ` [PATCH proxmox-backup 2/2] pull: decrypt: re-order encryption key/state checks Fabian Grünbichler
2026-04-24 19:06 ` applied: [PATCH proxmox-backup 0/3] fixup for server side decryption Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260424103607.531400-4-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal