From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 2EED01FF0C1 for ; Wed, 26 Aug 2026 13:05:54 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2993D213EB; Wed, 26 Aug 2026 13:05:53 +0200 (CEST) From: Christoph Heiss To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox v2 05/16] installer-types: systeminfo: add check for API token creation capability Date: Wed, 26 Aug 2026 13:04:48 +0200 Message-ID: <20260826110504.1339934-6-c.heiss@proxmox.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826110504.1339934-1-c.heiss@proxmox.com> References: <20260826110504.1339934-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: 1787742341964 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.606 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_MED -2.3 Sender listed at https://www.dnswl.org/, medium 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: VUKV63MU57JK6FF3WHV5HP7EGWM63XXT X-Message-ID-Hash: VUKV63MU57JK6FF3WHV5HP7EGWM63XXT 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 --- Changes v1 -> v2: * chain .cmp() calls instead of manually `match`ing on them proxmox-installer-types/src/lib.rs | 70 +++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/proxmox-installer-types/src/lib.rs b/proxmox-installer-types/src/lib.rs index 718867be..0ecc5d70 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,26 @@ 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 { + Some( + self.0 + .cmp(&other.0) + .then(self.1.cmp(&other.1)) + .then(self.2.cmp(&other.2)), + ) + } } pub(crate) fn parse_version(s: &str) -> Option<(u32, u32)> { @@ -196,4 +243,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.55.0