From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <c.heiss@proxmox.com>
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 8773D9358C
 for <pve-devel@lists.proxmox.com>; Tue,  9 Apr 2024 11:20:27 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 68C991A1C9
 for <pve-devel@lists.proxmox.com>; Tue,  9 Apr 2024 11:20:27 +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 <pve-devel@lists.proxmox.com>; Tue,  9 Apr 2024 11:20:26 +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 7179D42DB7
 for <pve-devel@lists.proxmox.com>; Tue,  9 Apr 2024 11:20:26 +0200 (CEST)
Date: Tue, 9 Apr 2024 11:20:25 +0200
From: Christoph Heiss <c.heiss@proxmox.com>
To: Aaron Lauterer <a.lauterer@proxmox.com>
Cc: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Message-ID: <kylnjafxlr5fvqmbk5z4oinxcyfwq27kgl3gdo72wr3mjmidvw@63aqdgcgy5oo>
References: <20240404144902.273800-1-a.lauterer@proxmox.com>
 <20240405142507.264620-1-a.lauterer@proxmox.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20240405142507.264620-1-a.lauterer@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.000 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, proxmox.com]
Subject: Re: [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 <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 09 Apr 2024 09:20:27 -0000

LGTM, does exactly what is says on the tin.

Tested it using both the `proxmox-autoinst-helper validate-answer` tool
and trying to boot the auto-installer itself with a bogus answer file.

So please consider this also:

Reviewed-by: Christoph Heiss <c.heiss@proxmox.com>
Tested-by: Christoph Heiss <c.heiss@proxmox.com>

On Fri, Apr 05, 2024 at 04:25:07PM +0200, Aaron Lauterer wrote:
> 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.

Yeah, that's kinda how I discovered that, wondering why a certain
option did not get applied :^)

>
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
> 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<String, String>),
>  }
>  #[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<ZfsRaidLevel>,
>      pub ashift: Option<usize>,
> @@ -234,6 +238,7 @@ pub struct ZfsOptions {
>  }
>
>  #[derive(Clone, Copy, Default, Deserialize, Serialize, Debug)]
> +#[serde(deny_unknown_fields)]
>  pub struct LvmOptions {
>      pub hdsize: Option<f64>,
>      pub swapsize: Option<f64>,
> @@ -243,6 +248,7 @@ pub struct LvmOptions {
>  }
>
>  #[derive(Clone, Copy, Default, Deserialize, Debug)]
> +#[serde(deny_unknown_fields)]
>  pub struct BtrfsOptions {
>      pub hdsize: Option<f64>,
>      pub raid: Option<BtrfsRaidLevel>,
> --
> 2.39.2
>
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
>