[pdm-devel] [PATCH datacenter-manager v3 01/11] pdm-api-types: views: add ViewConfig type

Michael Köppl m.koeppl at proxmox.com
Tue Nov 11 11:57:56 CET 2025


On Thu Nov 6, 2025 at 2:43 PM CET, Lukas Wagner wrote:
> +#[derive(Clone, Debug, PartialEq)]
> +/// Filter rule for includes/excludes.
> +pub enum FilterRule {
> +    /// Match a resource type.
> +    ResourceType(ResourceType),
> +    /// Match a resource pools (for PVE guests).
> +    ResourcePool(String),
> +    /// Match a (global) resource ID, e.g. 'remote/<remote>/guest/<vmid>'.
> +    ResourceId(String),
> +    /// Match a tag (for PVE guests).
> +    Tag(String),
> +    /// Match a remote.
> +    Remote(String),
> +}
> +
> +impl FromStr for FilterRule {
> +    type Err = anyhow::Error;
> +
> +    fn from_str(s: &str) -> Result<Self, Self::Err> {
> +        Ok(match s.split_once(':') {
> +            Some(("resource-type", value)) => FilterRule::ResourceType(value.parse()?),
> +            Some(("resource-pool", value)) => {
> +                if !SAFE_ID_FORMAT.unwrap_pattern_format().is_match(value) {
> +                    bail!("invalid tag value: {value}");
> +                }
> +                FilterRule::ResourcePool(value.to_string())
> +            }
> +            Some(("resource-id", value)) => {
> +                // TODO: Define schema and use it to validate. Can't use SAFE_ID_FORMAT since it does
> +                // not allow '/'.

Is there a plan for this TODO?

> +                if value.is_empty() {
> +                    bail!("empty resource-id rule not allowed");
> +                }
> +                FilterRule::ResourceId(value.to_string())
> +            }
> +            Some(("tag", value)) => {
> +                if !SAFE_ID_FORMAT.unwrap_pattern_format().is_match(value) {
> +                    bail!("invalid tag value: {value}");
> +                }
> +                FilterRule::Tag(value.to_string())
> +            }
> +            Some(("remote", value)) => {
> +                let _ = REMOTE_ID_SCHEMA.parse_simple_value(value)?;
> +                FilterRule::Remote(value.to_string())
> +            }
> +            Some((ty, _)) => bail!("invalid type: {ty}"),
> +            None => bail!("invalid filter rule: {s}"),
> +        })
> +    }
> +}





More information about the pdm-devel mailing list