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 E20299720D for ; Tue, 16 Apr 2024 17:33:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3AA721F4BB for ; Tue, 16 Apr 2024 17:33:37 +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 ; Tue, 16 Apr 2024 17:33:34 +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 C0D0945A5B for ; Tue, 16 Apr 2024 17:33:33 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Tue, 16 Apr 2024 17:33:20 +0200 Message-Id: <20240416153325.1154224-32-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240416153325.1154224-1-a.lauterer@proxmox.com> References: <20240416153325.1154224-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.052 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 v5 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: , X-List-Received-Date: Tue, 16 Apr 2024 15:33:41 -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 --- 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