From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer v2 3/5] common: convert `InstallRootPassword` into an enum
Date: Fri, 29 Nov 2024 13:21:11 +0100 [thread overview]
Message-ID: <20241129122125.1494917-4-c.heiss@proxmox.com> (raw)
In-Reply-To: <20241129122125.1494917-1-c.heiss@proxmox.com>
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 <c.heiss@proxmox.com>
---
Changes v1 -> v2:
* new patch
proxmox-auto-installer/src/utils.rs | 15 +++++++++++----
proxmox-installer-common/src/setup.rs | 9 ++++-----
proxmox-tui-installer/src/setup.rs | 5 +----
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs
index 27bbc3b..3378bdd 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 4b4920e..4adb168 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -464,11 +464,10 @@ impl Interface {
}
#[derive(Clone, Deserialize, Serialize)]
-pub struct InstallRootPassword {
- #[serde(skip_serializing_if = "Option::is_none")]
- pub plain: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub hashed: Option<String>,
+#[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<InstallerOptions> 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
next prev parent reply other threads:[~2024-11-29 12:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 12:21 [pve-devel] [PATCH installer/{pve, pmg}-docs/proxmox-backup v2 0/8] raise minimum root password length to 8 characters Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 1/5] proxinstall: " Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 2/5] tui: " Christoph Heiss
2024-11-29 12:21 ` Christoph Heiss [this message]
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 4/5] auto: " Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 5/5] auto: add negative tests for root password option Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH pve-docs v2 6/8] installation: adapt to raised root password length requirement Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH pmg-docs v2 7/8] " Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH proxmox-backup v2 8/8] using-the-installer: " Christoph Heiss
2024-12-16 11:12 ` [pve-devel] [PATCH installer/{pve, pmg}-docs/proxmox-backup v2 0/8] raise minimum root password length to 8 characters Christoph Heiss
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=20241129122125.1494917-4-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