all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager] pdm-api-types: views: use regex to verify resource-id values
Date: Thu, 13 Nov 2025 11:47:27 +0100	[thread overview]
Message-ID: <20251113104726.153549-2-l.wagner@proxmox.com> (raw)

Suggested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

To be applied on top of v4 of my 'view filter' patch series

 lib/pdm-api-types/src/views.rs | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/pdm-api-types/src/views.rs b/lib/pdm-api-types/src/views.rs
index 2bed68f3..ef39cc62 100644
--- a/lib/pdm-api-types/src/views.rs
+++ b/lib/pdm-api-types/src/views.rs
@@ -1,15 +1,24 @@
 use std::{fmt::Display, str::FromStr, sync::OnceLock};
 
 use anyhow::bail;
-use proxmox_section_config::{typed::ApiSectionDataEntry, SectionConfig, SectionConfigPlugin};
+use const_format::concatcp;
 use serde::{Deserialize, Serialize};
 
-use proxmox_schema::{api, ApiStringFormat, ApiType, ArraySchema, Schema, StringSchema, Updater};
+use proxmox_schema::{
+    api, api_types::SAFE_ID_REGEX_STR, const_regex, ApiStringFormat, ApiType, ArraySchema, Schema,
+    StringSchema, Updater,
+};
+use proxmox_section_config::{typed::ApiSectionDataEntry, SectionConfig, SectionConfigPlugin};
 
 use crate::{
     remotes::REMOTE_ID_SCHEMA, resource::ResourceType, PROXMOX_SAFE_ID_REGEX, VIEW_ID_SCHEMA,
 };
 
+const_regex! {
+    /// Regex for matching global resource IDs
+    pub GLOBAL_RESOURCE_ID_REGEX = concatcp!(r"^", SAFE_ID_REGEX_STR, r"(\/", SAFE_ID_REGEX_STR, r")+$");
+}
+
 /// Schema for filter rules.
 pub const FILTER_RULE_SCHEMA: Schema = StringSchema::new("Filter rule for resources.")
     .format(&ApiStringFormat::VerifyFn(verify_filter_rule))
@@ -121,12 +130,10 @@ impl FromStr for FilterRule {
                 FilterRule::ResourcePool(value.to_string())
             }
             Some(("resource-id", value)) => {
-                // TODO: Define schema and use it for validation. Can't use PROXMOX_SAFE_ID_REGEX
-                // since it does not allow '/'.
-
-                if value.is_empty() {
-                    bail!("empty resource-id rule not allowed");
+                if !GLOBAL_RESOURCE_ID_REGEX.is_match(value) {
+                    bail!("invalid resource-id value: {value}");
                 }
+
                 FilterRule::ResourceId(value.to_string())
             }
             Some(("tag", value)) => {
@@ -192,6 +199,7 @@ mod test {
 
         assert!(parse_and_check_display("resource-id:").is_err());
         assert!(parse_and_check_display("resource-id:remote/someremote/guest/100").unwrap());
+        assert!(parse_and_check_display("resource-id:remote").is_err());
 
         assert!(parse_and_check_display("tag:").is_err());
         assert!(parse_and_check_display("tag:sometag").unwrap());
-- 
2.47.3



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


                 reply	other threads:[~2025-11-13 10:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20251113104726.153549-2-l.wagner@proxmox.com \
    --to=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 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