From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 6BC891FF0ED for ; Fri, 31 Jul 2026 16:39:50 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 3DF4B21572; Fri, 31 Jul 2026 16:39:50 +0200 (CEST) From: Christoph Heiss To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox 05/16] installer-types: systeminfo: add check for API token creation capability Date: Fri, 31 Jul 2026 16:35:28 +0200 Message-ID: <20260731143910.936881-6-c.heiss@proxmox.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260731143910.936881-1-c.heiss@proxmox.com> References: <20260731143910.936881-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1785508776578 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.000 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust 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: VDHLKQ64OMNCACVPRTV6IXZP4ET3RCZA X-Message-ID-Hash: VDHLKQ64OMNCACVPRTV6IXZP4ET3RCZA X-MailFrom: c.heiss@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 Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Only newer installers support creating API tokens on (supported) products, i.e. currently PVE and PBS only, for usage with PDM. Signed-off-by: Christoph Heiss --- proxmox-installer-types/src/lib.rs | 73 +++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/proxmox-installer-types/src/lib.rs b/proxmox-installer-types/src/lib.rs index 718867be..b04de27e 100644 --- a/proxmox-installer-types/src/lib.rs +++ b/proxmox-installer-types/src/lib.rs @@ -14,7 +14,10 @@ pub mod post_hook; use proxmox_schema::api; use serde::{Deserialize, Serialize}; -use std::collections::{BTreeMap, HashMap}; +use std::{ + cmp::Ordering, + collections::{BTreeMap, HashMap}, +}; use proxmox_network_types::mac_address::MacAddress; @@ -67,6 +70,17 @@ pub struct SystemInfo { pub network_interfaces: Vec, } +impl SystemInfo { + /// Determines whether the product supports creating an API token during installation. + pub fn supports_api_token_creation(&self) -> bool { + match self.product.product { + ProxmoxProduct::Pve => self.iso.product_version() >= ProductVersion(9, 2, 2), + ProxmoxProduct::Pbs => self.iso.product_version() >= ProductVersion(4, 2, 2), + _ => false, + } + } +} + #[cfg_attr(feature = "api-types", api)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] /// The per-product configuration of the installer. @@ -108,6 +122,19 @@ impl IsoInfo { isorelease: String::from("mocked-1"), } } + + /// Returns the product version contained in the ISO. + pub fn product_version(&self) -> ProductVersion { + let rel = self + .isorelease + .parse() + // some ALPHA-X, BETA-X release, treat them as 0 + .unwrap_or(0); + + parse_version(&self.release) + .map(|(maj, min)| ProductVersion(maj, min, rel)) + .unwrap_or_else(|| ProductVersion(0, 0, 0)) + } } #[cfg_attr(feature = "api-types", api( @@ -178,6 +205,29 @@ impl ProxmoxProduct { Self::Pdm => "Proxmox Datacenter Manager", } } + + /// Determines whether the product supports creating an API token during installation. + pub fn supports_api_token_creation(&self) -> bool { + matches!(self, ProxmoxProduct::Pve | ProxmoxProduct::Pbs) + } +} + +/// Represents a (major, minor, patch) product version tuple. +#[derive(Debug, PartialEq, Eq)] +pub struct ProductVersion(pub u32, pub u32, pub u32); + +impl PartialOrd for ProductVersion { + fn partial_cmp(&self, other: &Self) -> Option { + match ( + self.0.cmp(&other.0), + self.1.cmp(&other.1), + self.2.cmp(&other.2), + ) { + (Ordering::Equal, Ordering::Equal, ord) => Some(ord), + (Ordering::Equal, ord, _) => Some(ord), + (ord, _, _) => Some(ord), + } + } } pub(crate) fn parse_version(s: &str) -> Option<(u32, u32)> { @@ -196,4 +246,25 @@ mod tests { assert_eq!(parse_version("42.1"), Some((42, 1))); assert_eq!(parse_version("a.1"), None); } + + #[test] + fn iso_is_version_at_least_works() { + let iso = IsoInfo { + release: "9.1".into(), + isorelease: "1".into(), + }; + + assert!(iso.product_version() >= ProductVersion(9, 0, 2)); + assert!(iso.product_version() < ProductVersion(9, 2, 1)); + assert!(iso.product_version() >= ProductVersion(9, 1, 1)); + assert!(iso.product_version() < ProductVersion(9, 1, 2)); + + let iso = IsoInfo { + release: "9.1".into(), + isorelease: "ALPHA-1".into(), + }; + + assert!(iso.product_version() == ProductVersion(9, 1, 0)); + assert!(iso.product_version() < ProductVersion(9, 1, 1)); + } } -- 2.54.0