From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 85AB61FF15F for ; Mon, 16 Dec 2024 10:41:42 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id ED7FF86D5; Mon, 16 Dec 2024 10:41:52 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 16 Dec 2024 10:40:59 +0100 Message-ID: <20241216094114.476756-2-c.heiss@proxmox.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241216094114.476756-1-c.heiss@proxmox.com> References: <20241216094114.476756-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 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: [pve-devel] [PATCH installer v3 1/8] common: convert `InstallRootPassword` into an enum X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" It's more appropriate for that type of data, since only one of both variants is ever allowed to be set. Makes it also a bit more ergonomic to handle. Signed-off-by: Christoph Heiss --- Changes v2 -> v3: * added rustdoc for `InstallRootPassword` Changes v1 -> v2: * new patch proxmox-auto-installer/src/utils.rs | 15 +++++++++++---- proxmox-installer-common/src/setup.rs | 12 +++++++----- proxmox-tui-installer/src/setup.rs | 5 +---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index fbf874e..3aae474 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -368,6 +368,16 @@ pub fn parse_answer( verify_email_and_root_password_settings(answer)?; verify_first_boot_settings(answer)?; + let root_password = match ( + &answer.global.root_password, + &answer.global.root_password_hashed, + ) { + (Some(password), None) => InstallRootPassword::Plain(password.to_owned()), + (None, Some(hashed)) => InstallRootPassword::Hashed(hashed.to_owned()), + // Make the compiler happy, won't be reached anyway due to above checks + _ => bail!("invalid root password setting"), + }; + let mut config = InstallConfig { autoreboot: 1_usize, filesys: filesystem, @@ -386,10 +396,7 @@ pub fn parse_answer( timezone: answer.global.timezone.clone(), keymap: answer.global.keyboard.to_string(), - root_password: InstallRootPassword { - plain: answer.global.root_password.clone(), - hashed: answer.global.root_password_hashed.clone(), - }, + root_password, mailto: answer.global.mailto.clone(), root_ssh_keys: answer.global.root_ssh_keys.clone(), diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 0ef47d2..26a8755 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -479,12 +479,14 @@ impl Interface { } } +/// Root password which can either be in plain-text or hashed format. +/// +/// The serialized format is suitable for passing to the low-level installer. #[derive(Clone, Deserialize, Serialize)] -pub struct InstallRootPassword { - #[serde(skip_serializing_if = "Option::is_none")] - pub plain: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub hashed: Option, +#[serde(rename_all = "lowercase")] +pub enum InstallRootPassword { + Plain(String), + Hashed(String), } #[derive(Clone, Default, Deserialize, Serialize)] diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs index b2a3511..b90c7dc 100644 --- a/proxmox-tui-installer/src/setup.rs +++ b/proxmox-tui-installer/src/setup.rs @@ -27,10 +27,7 @@ impl From for InstallConfig { timezone: options.timezone.timezone, keymap: options.timezone.kb_layout, - root_password: InstallRootPassword { - plain: Some(options.password.root_password), - hashed: None, - }, + root_password: InstallRootPassword::Plain(options.password.root_password), mailto: options.password.email, root_ssh_keys: vec![], -- 2.47.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel