all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH datacenter-manager] pdm-api-types: views: use regex to verify resource-id values
@ 2025-11-13 10:47 Lukas Wagner
  0 siblings, 0 replies; only message in thread
From: Lukas Wagner @ 2025-11-13 10:47 UTC (permalink / raw)
  To: pdm-devel

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-11-13 10:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-13 10:47 [pdm-devel] [PATCH datacenter-manager] pdm-api-types: views: use regex to verify resource-id values Lukas Wagner

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