public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 6/6] assistant: validate answer first-boot hook and locale settings
Date: Mon,  9 Dec 2024 13:45:59 +0100	[thread overview]
Message-ID: <20241209124601.1272122-7-c.heiss@proxmox.com> (raw)
In-Reply-To: <20241209124601.1272122-1-c.heiss@proxmox.com>

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 <c.heiss@proxmox.com>
---
 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<Path> + fmt::Debug) -> Result<Answer> {
     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


  parent reply	other threads:[~2024-12-09 12:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-09 12:45 [pve-devel] [PATCH installer 0/6] assistant: properly validate answer file settings Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 1/6] tui: options: simplify unit-test setup Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 2/6] country.pl: generate final structure as json at build time directly Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 3/6] common: setup: read locale info as shipped by the installer directly Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 4/6] common: setup: include path in error message if file could not be read Christoph Heiss
2024-12-09 12:45 ` [pve-devel] [PATCH installer 5/6] fix #5889: assistant: validate answer email & root password settings Christoph Heiss
2024-12-09 12:45 ` Christoph Heiss [this message]
2024-12-10 17:37 ` [pve-devel] applied-series: [PATCH installer 0/6] assistant: properly validate answer file settings Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241209124601.1272122-7-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal