From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id E302F1FF168 for <inbox@lore.proxmox.com>; Tue, 4 Mar 2025 15:43:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 830C3217E; Tue, 4 Mar 2025 15:43:40 +0100 (CET) From: Shannon Sterz <s.sterz@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Tue, 4 Mar 2025 15:42:37 +0100 Message-Id: <20250304144247.231089-12-s.sterz@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250304144247.231089-1-s.sterz@proxmox.com> References: <20250304144247.231089-1-s.sterz@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.014 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: [pdm-devel] [PATCH proxmox v5 11/21] login: make password optional when creating Login requests X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> in certain context (for example, the browser), no password needs to be provided when using HttpOnly cookies as they are handle by said context. so make renewing ticket with password optional and add a new helper function that does not require a password. Signed-off-by: Shannon Sterz <s.sterz@proxmox.com> --- proxmox-login/src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/proxmox-login/src/lib.rs b/proxmox-login/src/lib.rs index d7798b62..3b3558d0 100644 --- a/proxmox-login/src/lib.rs +++ b/proxmox-login/src/lib.rs @@ -50,7 +50,7 @@ pub struct Request { pub struct Login { api_url: String, userid: String, - password: String, + password: Option<String>, pve_compat: bool, } @@ -96,7 +96,18 @@ impl Login { api_url: normalize_url(api_url.into()), pve_compat: ticket.product() == "PVE", userid: ticket.userid().to_string(), - password: ticket.into(), + password: Some(ticket.into()), + } + } + + /// Prepare a request with the assumption that the context handles the ticket (usually in a + /// browser via an HttpOnly cookie). + 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, + userid: userid.into(), + password: None, } } @@ -109,7 +120,7 @@ impl Login { Self { api_url: normalize_url(api_url.into()), userid: userid.into(), - password: password.into(), + password: Some(password.into()), pve_compat: false, } } @@ -129,7 +140,7 @@ impl Login { let request = api::CreateTicket { new_format: self.pve_compat.then_some(true), username: self.userid.clone(), - password: Some(self.password.clone()), + password: self.password.clone(), ..Default::default() }; -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel