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 0732C1FF348 for ; Wed, 17 Apr 2024 14:40:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 01910692C; Wed, 17 Apr 2024 14:40:20 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Wed, 17 Apr 2024 14:31:03 +0200 Message-Id: <20240417123108.212720-32-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240417123108.212720-1-a.lauterer@proxmox.com> References: <20240417123108.212720-1-a.lauterer@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.046 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 v6 31/36] 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: , 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" 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. Tested-by: Christoph Heiss Reviewed-by: Christoph Heiss Signed-off-by: Aaron Lauterer --- 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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel