From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BB65B9256A for ; Fri, 5 Apr 2024 16:25:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9511915485 for ; Fri, 5 Apr 2024 16:25:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 5 Apr 2024 16:25:08 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9E68946652 for ; Fri, 5 Apr 2024 16:25:08 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Fri, 5 Apr 2024 16:25:07 +0200 Message-Id: <20240405142507.264620-1-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240404144902.273800-1-a.lauterer@proxmox.com> References: <20240404144902.273800-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.054 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [answer.rs] Subject: [pve-devel] [PATCH v4 installer 31/30 follow-up] auto-installer: answer: deny unknown fields 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: , X-List-Received-Date: Fri, 05 Apr 2024 14:25:39 -0000 This way, serde will throw errors if fields are not known. This can help to reduce frustration if one might think to have set an option, but for example a small type has happened. Signed-off-by: Aaron Lauterer --- Since Christoph mentioned it I tried to implement it. Tested quickly with the proxmox-autoinst-helper tool. proxmox-auto-installer/src/answer.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs index 94cebb3..57c2602 100644 --- a/proxmox-auto-installer/src/answer.rs +++ b/proxmox-auto-installer/src/answer.rs @@ -10,7 +10,7 @@ use std::{collections::BTreeMap, net::IpAddr}; /// storing them in a HashMap #[derive(Clone, Deserialize, Debug)] -#[serde(rename_all = "kebab-case")] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] pub struct Answer { pub global: Global, pub network: Network, @@ -19,6 +19,7 @@ pub struct Answer { } #[derive(Clone, Deserialize, Debug)] +#[serde(deny_unknown_fields)] pub struct Global { pub country: String, pub fqdn: Fqdn, @@ -33,6 +34,7 @@ pub struct Global { } #[derive(Clone, Deserialize, Debug)] +#[serde(deny_unknown_fields)] struct NetworkInAnswer { #[serde(default)] pub use_dhcp: bool, @@ -43,7 +45,7 @@ struct NetworkInAnswer { } #[derive(Clone, Deserialize, Debug)] -#[serde(try_from = "NetworkInAnswer")] +#[serde(try_from = "NetworkInAnswer", deny_unknown_fields)] pub struct Network { pub network_settings: NetworkSettings, } @@ -97,6 +99,7 @@ pub struct NetworkManual { } #[derive(Clone, Debug, Deserialize)] +#[serde(deny_unknown_fields)] pub struct DiskSetup { pub filesystem: Filesystem, #[serde(default)] @@ -109,7 +112,7 @@ pub struct DiskSetup { } #[derive(Clone, Debug, Deserialize)] -#[serde(try_from = "DiskSetup")] +#[serde(try_from = "DiskSetup", deny_unknown_fields)] pub struct Disks { pub fs_type: FsType, pub disk_selection: DiskSelection, @@ -207,14 +210,14 @@ pub enum DiskSelection { Filter(BTreeMap), } #[derive(Clone, Deserialize, Debug, PartialEq, ValueEnum)] -#[serde(rename_all = "lowercase")] +#[serde(rename_all = "lowercase", deny_unknown_fields)] pub enum FilterMatch { Any, All, } #[derive(Clone, Deserialize, Serialize, Debug, PartialEq)] -#[serde(rename_all = "lowercase")] +#[serde(rename_all = "lowercase", deny_unknown_fields)] pub enum Filesystem { Ext4, Xfs, @@ -223,6 +226,7 @@ pub enum Filesystem { } #[derive(Clone, Copy, Default, Deserialize, Debug)] +#[serde(deny_unknown_fields)] pub struct ZfsOptions { pub raid: Option, pub ashift: Option, @@ -234,6 +238,7 @@ pub struct ZfsOptions { } #[derive(Clone, Copy, Default, Deserialize, Serialize, Debug)] +#[serde(deny_unknown_fields)] pub struct LvmOptions { pub hdsize: Option, pub swapsize: Option, @@ -243,6 +248,7 @@ pub struct LvmOptions { } #[derive(Clone, Copy, Default, Deserialize, Debug)] +#[serde(deny_unknown_fields)] pub struct BtrfsOptions { pub hdsize: Option, pub raid: Option, -- 2.39.2