all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox 1/3] proxmox-login: refactor PVE TFA compat mode
Date: Mon, 29 Sep 2025 17:48:15 +0200	[thread overview]
Message-ID: <20250929154820.892720-2-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250929154820.892720-1-c.ebner@proxmox.com>

In preparation for extending the compat mode by Proxmox Backup Server
version 3 API compatibility for login ticket parsing.

Instead of storing the compat mode as simple boolean flag and only
considering PVE, use a `CompatMode` enum instead. Further, make the
variable and method names more generic.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 proxmox-login/src/lib.rs | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/proxmox-login/src/lib.rs b/proxmox-login/src/lib.rs
index 4482f2e4..e7b8e023 100644
--- a/proxmox-login/src/lib.rs
+++ b/proxmox-login/src/lib.rs
@@ -49,7 +49,15 @@ pub struct Login {
     api_url: String,
     userid: String,
     password: Option<String>,
-    pve_compat: bool,
+    compat_mode: CompatMode,
+}
+
+/// Compatibility mode to use for login or ticket renewal.
+#[derive(Copy, Clone, Debug, Default, PartialEq)]
+pub enum CompatMode {
+    #[default]
+    Generic,
+    PveTfa,
 }
 
 fn normalize_url(mut api_url: String) -> String {
@@ -90,9 +98,14 @@ impl Login {
 
     /// Prepare a request given an already parsed ticket.
     pub fn renew_ticket(api_url: impl Into<String>, ticket: Ticket) -> Self {
+        let compat_mode = if ticket.product() == "PVE" {
+            CompatMode::PveTfa
+        } else {
+            CompatMode::default()
+        };
         Self {
             api_url: normalize_url(api_url.into()),
-            pve_compat: ticket.product() == "PVE",
+            compat_mode,
             userid: ticket.userid().to_string(),
             password: Some(ticket.into()),
         }
@@ -103,7 +116,7 @@ impl Login {
     pub fn renew_with_cookie(api_url: impl Into<String>, userid: impl Into<String>) -> Self {
         Self {
             api_url: normalize_url(api_url.into()),
-            pve_compat: false,
+            compat_mode: CompatMode::default(),
             userid: userid.into(),
             password: None,
         }
@@ -119,13 +132,13 @@ impl Login {
             api_url: normalize_url(api_url.into()),
             userid: userid.into(),
             password: Some(password.into()),
-            pve_compat: false,
+            compat_mode: CompatMode::default(),
         }
     }
 
     /// Set the Proxmox VE compatibility parameter for Two-Factor-Authentication support.
-    pub fn pve_compatibility(mut self, compatibility: bool) -> Self {
-        self.pve_compat = compatibility;
+    pub fn set_compatibility(mut self, compat_mode: CompatMode) -> Self {
+        self.compat_mode = compat_mode;
         self
     }
 
@@ -135,8 +148,13 @@ impl Login {
     /// [`response`](Login::response) method in order to extract the validated ticket or
     /// Two-Factor-Authentication challenge.
     pub fn request(&self) -> Request {
+        let new_format = if self.compat_mode == CompatMode::PveTfa {
+            Some(true)
+        } else {
+            None
+        };
         let request = api::CreateTicket {
-            new_format: self.pve_compat.then_some(true),
+            new_format,
             username: self.userid.clone(),
             password: self.password.clone(),
             ..Default::default()
@@ -225,7 +243,7 @@ impl Login {
             TicketResponse::Tfa(ticket, challenge) => {
                 TicketResult::TfaRequired(SecondFactorChallenge {
                     api_url: self.api_url.clone(),
-                    pve_compat: self.pve_compat,
+                    pve_compat: self.compat_mode == CompatMode::PveTfa,
                     userid: response.username,
                     ticket,
                     challenge,
-- 
2.47.3



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


  reply	other threads:[~2025-09-29 15:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-29 15:48 [pdm-devel] [PATCH datacenter-manager/proxmox 0/6] pbs client: fix PBS version 3 login ticket parsing compatibility Christian Ebner
2025-09-29 15:48 ` Christian Ebner [this message]
2025-09-29 15:48 ` [pdm-devel] [PATCH proxmox 2/3] proxmox-client: adapt to new compat mode introduced for proxmox-login Christian Ebner
2025-09-29 15:48 ` [pdm-devel] [PATCH proxmox 3/3] proxmox-login: add compat mode to fallback to PBS3 ticket parsing Christian Ebner
2025-09-29 18:01   ` Christian Ebner
2025-09-29 15:48 ` [pdm-devel] [PATCH datacenter-manager 1/3] server: adapt to proxmox-client compat mode changes Christian Ebner
2025-09-29 15:48 ` [pdm-devel] [PATCH datacenter-manager 2/3] server: pbs-client: check and fallback to PBS v3 ticket compat mode Christian Ebner
2025-09-29 15:48 ` [pdm-devel] [PATCH datacenter-manager 3/3] Revert "ui: add wizard: note that login currently only works for PBS 4" Christian Ebner
2025-09-30  8:03 ` [pdm-devel] superseded: [PATCH datacenter-manager/proxmox 0/6] pbs client: fix PBS version 3 login ticket parsing compatibility Christian Ebner

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=20250929154820.892720-2-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pdm-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