all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH proxmox 1/3] installer types: move email validation from proxmox-installer-common
Date: Wed, 27 May 2026 15:05:57 +0200	[thread overview]
Message-ID: <20260527130611.2995147-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260527130611.2995147-1-d.csapak@proxmox.com>

we want to use this not only in the installer itself but also e.g. in
PDM which can generate answer files.

Since we don't only want this when we have the api types, move the
proxmox-schema and regex dependencies from the api-types feature.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 proxmox-installer-types/Cargo.toml    |  6 +++---
 proxmox-installer-types/src/answer.rs | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/proxmox-installer-types/Cargo.toml b/proxmox-installer-types/Cargo.toml
index 4526b47f..5b0b489c 100644
--- a/proxmox-installer-types/Cargo.toml
+++ b/proxmox-installer-types/Cargo.toml
@@ -15,15 +15,15 @@ rust-version.workspace = true
 anyhow.workspace = true
 serde = { workspace = true, features = ["derive"] }
 serde_plain.workspace = true
-regex = { workspace = true, optional = true }
+regex = { workspace = true }
 proxmox-network-types.workspace = true
-proxmox-schema = { workspace = true, optional = true, features = ["api-macro"] }
+proxmox-schema = { workspace = true, features = ["api-macro"] }
 proxmox-section-config = { workspace = true, optional = true }
 proxmox-node-status.workspace = true
 
 [features]
 default = []
-api-types = ["dep:regex", "dep:proxmox-schema", "dep:proxmox-section-config", "proxmox-network-types/api-types"]
+api-types = ["dep:proxmox-section-config", "proxmox-network-types/api-types"]
 # enable old-style answer file keys with underscores for backwards compatibility
 legacy = []
 
diff --git a/proxmox-installer-types/src/answer.rs b/proxmox-installer-types/src/answer.rs
index 9c6317ae..8bb9f0dd 100644
--- a/proxmox-installer-types/src/answer.rs
+++ b/proxmox-installer-types/src/answer.rs
@@ -41,6 +41,17 @@ proxmox_schema::const_regex! {
     pub SUBSCRIPTION_KEY_REGEX = r"^(?:pve[0-9]+|pbs|pmg)[cbsp]-[0-9a-f]{10}$";
 }
 
+proxmox_schema::const_regex! {
+    /// An email address using the regex for `<input type="email" />` elements
+    /// as defined in the [HTML specification].
+    /// Using that /should/ cover all possible cases that are encountered in the wild.
+    ///
+    /// It additionally checks whether the email our default email placeholder value.
+    ///
+    /// [HTML specification]: <https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address>
+    pub EMAIL_REGEX = r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$";
+}
+
 /// Schema for an optional Proxmox subscription key.
 #[cfg(feature = "api-types")]
 pub const SUBSCRIPTION_KEY_SCHEMA: proxmox_schema::Schema =
@@ -1229,3 +1240,14 @@ where
         _ => Ok(None),
     }
 }
+
+/// Validates an email address according to [EMAIL_REGEX]
+pub fn email_validate(email: &str) -> Result<()> {
+    if !EMAIL_REGEX.is_match(email) {
+        bail!("Email does not look like a valid address (user@domain.tld)")
+    } else if email == crate::EMAIL_DEFAULT_PLACEHOLDER {
+        bail!("Invalid (default) email address")
+    }
+
+    Ok(())
+}
-- 
2.47.3





  reply	other threads:[~2026-05-27 13:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27 13:05 [PATCH datacenter-manager/installer/proxmox 0/3] use correct email validation in auto-installer ui Dominik Csapak
2026-05-27 13:05 ` Dominik Csapak [this message]
2026-05-27 13:05 ` [PATCH pve-installer 2/3] use email validation from installer-types Dominik Csapak
2026-05-27 13:05 ` [PATCH datacenter-manager 3/3] ui: auto-installer: " Dominik Csapak
2026-05-28 11:00 ` partially-applied: [PATCH datacenter-manager/installer/proxmox 0/3] use correct email validation in auto-installer ui Thomas Lamprecht

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=20260527130611.2995147-2-d.csapak@proxmox.com \
    --to=d.csapak@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal