public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Christoph Heiss" <c.heiss@proxmox.com>
To: "Lukas Wagner" <l.wagner@proxmox.com>
Cc: Proxmox Datacenter Manager development discussion
	<pdm-devel@lists.proxmox.com>
Subject: Re: [pdm-devel] [PATCH proxmox v2 02/14] network-types: move `Fqdn` type from proxmox-installer-common
Date: Tue, 09 Dec 2025 13:26:36 +0100	[thread overview]
Message-ID: <DETOO16VFK6O.3DBF59ZM2VUUC@proxmox.com> (raw)
In-Reply-To: <DETKJXADNIYO.DFNU7O4DZIU5@proxmox.com>

Thanks for the review!

On Tue Dec 9, 2025 at 10:13 AM CET, Lukas Wagner wrote:
> Looks good in general, I assume this was reviewed before this it was
> moved from somewhere else.
>
> One note inline.
>
> Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
>
> On Fri Dec 5, 2025 at 12:25 PM CET, Christoph Heiss wrote:
[..]
>> +impl Fqdn {
>> +    /// Maximum length of a single label of the FQDN
>> +    const MAX_LABEL_LENGTH: usize = 63;
>> +    /// Maximum total length of the FQDN
>> +    const MAX_LENGTH: usize = 253;
>> +
>> +    pub fn from(fqdn: &str) -> Result<Self, FqdnParseError> {
>> +        if fqdn.len() > Self::MAX_LENGTH {
>> +            return Err(FqdnParseError::TooLong(fqdn.len()));
>> +        }
>> +
>> +        let parts = fqdn
>> +            .split('.')
>> +            .map(ToOwned::to_owned)
>> +            .collect::<Vec<String>>();
>> +
>> +        for part in &parts {
>> +            if !Self::validate_single(part) {
>> +                return Err(FqdnParseError::InvalidPart(part.clone()));
>> +            }
>> +        }
>> +
>> +        if parts.len() < 2 {
>> +            Err(FqdnParseError::MissingHostname)
>
> (a)
>
> Since `Fqdn::from` seems to be the only way to instantiate the Fqdn
> type, and since the parts.len() < 2 establishes the invariant that the
> number of parts can only ever be >= 2,
>
>> +        } else if parts[0].chars().all(|c| c.is_ascii_digit()) {
>> +            // Do not allow a purely numeric hostname, see:
>> +            // https://bugzilla.proxmox.com/show_bug.cgi?id=1054
>> +            Err(FqdnParseError::NumericHostname)
>> +        } else {
>> +            Ok(Self { parts })
>> +        }
>> +    }
>> +
>> +    pub fn host(&self) -> Option<&str> {
>> +        self.has_host().then_some(&self.parts[0])
>> +    }
>
> (c)
>
> ... therefore you could assume that it is safe to just access
> self.parts[0] and avoid the `Option<..>` in the return type?
>
> I'm always on board with being careful, but since this type is
> relatively small, I think it would be reasonable to rely on the
> invariant, which makes the call sites a bit nicer since it does not have
> to handle the Option.
>
> What do you think?

That seems very sensible, thanks for reasoning about this! The given
invariant is also already established by the current unit tests
below, so fine from my side too.

Less `Option`s to handle at callsites is always a nice improvement IMO.

I will change it for v2, it's a good chance to improve upon things.

>
>> +
>> +    pub fn domain(&self) -> String {
>> +        let parts = if self.has_host() {
>> +            &self.parts[1..]
>> +        } else {
>> +            &self.parts
>> +        };
>> +
>> +        parts.join(".")
>> +    }
>> +
>> +    /// Checks whether the FQDN has a hostname associated with it, i.e. is has more than 1 part.
>> +    fn has_host(&self) -> bool {
>> +        self.parts.len() > 1
>> +    }
>
> (b)
>
> ... which means that this should always return true, ...
>


_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


  reply	other threads:[~2025-12-09 12:26 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05 11:25 [pdm-devel] [PATCH proxmox/datacenter-manager v2 00/14] initial auto-installer integration Christoph Heiss
2025-12-05 11:25 ` [pdm-devel] [PATCH proxmox v2 01/14] api-macro: allow $ in identifier name Christoph Heiss
2025-12-05 11:25 ` [pdm-devel] [PATCH proxmox v2 02/14] network-types: move `Fqdn` type from proxmox-installer-common Christoph Heiss
2025-12-09  9:13   ` Lukas Wagner
2025-12-09 12:26     ` Christoph Heiss [this message]
2025-12-05 11:25 ` [pdm-devel] [PATCH proxmox v2 03/14] network-types: implement api type for Fqdn Christoph Heiss
2025-12-09  9:13   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH proxmox v2 04/14] network-types: add api wrapper type for std::net::IpAddr Christoph Heiss
2025-12-09  9:16   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH proxmox v2 05/14] installer-types: add common types used by the installer Christoph Heiss
2025-12-09  9:35   ` Lukas Wagner
2025-12-09 12:17     ` Christoph Heiss
2025-12-05 11:25 ` [pdm-devel] [PATCH proxmox v2 06/14] installer-types: add types used by the auto-installer Christoph Heiss
2025-12-09  9:44   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH proxmox v2 07/14] installer-types: implement api type for all externally-used types Christoph Heiss
2025-12-09  9:52   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH datacenter-manager v2 08/14] api-types: add api types for auto-installer integration Christoph Heiss
2025-12-09 10:03   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH datacenter-manager v2 09/14] config: add auto-installer configuration module Christoph Heiss
2025-12-09 10:22   ` Lukas Wagner
2025-12-09 12:10     ` Christoph Heiss
2025-12-05 11:25 ` [pdm-devel] [PATCH datacenter-manager v2 10/14] acl: wire up new /system/auto-installation acl path Christoph Heiss
2025-12-09 10:23   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH datacenter-manager v2 11/14] server: api: add auto-installer integration module Christoph Heiss
2025-12-09 11:01   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH datacenter-manager v2 12/14] ui: auto-installer: add installations overview panel Christoph Heiss
2025-12-09 12:35   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH datacenter-manager v2 13/14] ui: auto-installer: add prepared answer configuration panel Christoph Heiss
2025-12-09 13:01   ` Lukas Wagner
2025-12-05 11:25 ` [pdm-devel] [PATCH datacenter-manager v2 14/14] docs: add documentation for auto-installer integration Christoph Heiss
2025-12-09 13:12   ` Lukas Wagner
2025-12-05 11:53 ` [pdm-devel] [PATCH proxmox/datacenter-manager v2 00/14] initial " Thomas Lamprecht
2025-12-05 15:50   ` Christoph Heiss
2025-12-05 15:57     ` Thomas Lamprecht
2025-12-09 13:38 ` Lukas Wagner

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=DETOO16VFK6O.3DBF59ZM2VUUC@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=l.wagner@proxmox.com \
    --cc=pdm-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal