From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id E369A1FF16E for ; Mon, 9 Dec 2024 13:46:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F1E201B4A; Mon, 9 Dec 2024 13:46:11 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 9 Dec 2024 13:45:59 +0100 Message-ID: <20241209124601.1272122-7-c.heiss@proxmox.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209124601.1272122-1-c.heiss@proxmox.com> References: <20241209124601.1272122-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 6/6] assistant: validate answer first-boot hook and locale settings 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" For the first-boot hook, the check from the auto-installer can be easily re-used. For the locale, as we now have that information available as JSON, include that file in the assistant and use it to verify the answer file settings. Signed-off-by: Christoph Heiss --- proxmox-auto-install-assistant/src/main.rs | 11 +++++++++-- proxmox-auto-installer/src/utils.rs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/proxmox-auto-install-assistant/src/main.rs b/proxmox-auto-install-assistant/src/main.rs index 6796c06..969922c 100644 --- a/proxmox-auto-install-assistant/src/main.rs +++ b/proxmox-auto-install-assistant/src/main.rs @@ -15,14 +15,18 @@ use proxmox_auto_installer::{ sysinfo::SysInfo, utils::{ get_matched_udev_indexes, get_nic_list, get_single_udev_index, - verify_email_and_root_password_settings, AutoInstSettings, - FetchAnswerFrom, HttpOptions, + verify_email_and_root_password_settings, verify_first_boot_settings, + verify_locale_settings, AutoInstSettings, FetchAnswerFrom, HttpOptions, }, }; use proxmox_installer_common::{FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME}; static PROXMOX_ISO_FLAG: &str = "/auto-installer-capable"; +/// Locale information as raw JSON, can be parsed into a +/// [LocaleInfo](`proxmox_installer_common::setup::LocaleInfo`) struct. +const LOCALE_INFO: &str = include_str!("../../locale-info.json"); + /// This tool can be used to prepare a Proxmox installation ISO for automated installations. /// Additional uses are to validate the format of an answer file or to test match filters and /// print information on the properties to match against for the current hardware. @@ -589,8 +593,11 @@ fn parse_answer(path: impl AsRef + fmt::Debug) -> Result { if let Err(err) = file.read_to_string(&mut contents) { bail!("Reading from file {path:?} failed: {err}"); } + match toml::from_str(&contents) { Ok(answer) => { + verify_locale_settings(&answer, &serde_json::from_str(LOCALE_INFO)?)?; + verify_first_boot_settings(&answer)?; verify_email_and_root_password_settings(&answer)?; println!("The answer file was parsed successfully, no errors found!"); Ok(answer) diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index c26b33c..fbf874e 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -291,7 +291,7 @@ fn verify_filesystem_settings(answer: &Answer, setup_info: &SetupInfo) -> Result Ok(()) } -fn verify_locale_settings(answer: &Answer, locales: &LocaleInfo) -> Result<()> { +pub fn verify_locale_settings(answer: &Answer, locales: &LocaleInfo) -> Result<()> { info!("Verifying locale settings"); if !locales .countries @@ -335,7 +335,7 @@ pub fn verify_email_and_root_password_settings(answer: &Answer) -> Result<()> { } } -fn verify_first_boot_settings(answer: &Answer) -> Result<()> { +pub fn verify_first_boot_settings(answer: &Answer) -> Result<()> { info!("Verifying first boot settings"); if let Some(first_boot) = &answer.first_boot { -- 2.47.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel