public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Lukas Wagner" <l.wagner@proxmox.com>
To: "Proxmox Datacenter Manager development discussion"
	<pdm-devel@lists.proxmox.com>,
	"Michael Köppl" <m.koeppl@proxmox.com>
Subject: Re: [pdm-devel] [PATCH datacenter-manager v3 01/11] pdm-api-types: views: add ViewConfig type
Date: Wed, 12 Nov 2025 11:05:32 +0100	[thread overview]
Message-ID: <DE6MRB4E6T68.2BR2GPL7QPCUQ@proxmox.com> (raw)
In-Reply-To: <DE5T9GMPFCGH.34LJ0M8K0D799@proxmox.com>

On Tue Nov 11, 2025 at 11:58 AM CET, Michael Köppl wrote:
>> +/// Schema for filter rules.
>> +pub const FILTER_RULE_SCHEMA: Schema = StringSchema::new("Filter rule for resources.")
>> +    .format(&ApiStringFormat::VerifyFn(verify_filter_rule))
>> +    .type_text(
>> +        "resource-type:storage|qemu|lxc|sdn-zone|datastore|node>\
>
> This line seems to be missing a <
>

Fixed, thank you!

>> +            |resource-pool:<pool-name>\
>> +            |tag:<tag-name>\
>> +            |remote:<remote-name>\
>> +            |resource-id:<resource-id>",
>> +    )
>> +    .schema();
>> +
>> +/// Schema for list of filter rules.
>> +pub const FILTER_RULE_LIST_SCHEMA: Schema =
>> +    ArraySchema::new("List of filter rules.", &FILTER_RULE_SCHEMA).schema();
>> +
>> +#[api(
>> +    properties: {
>> +        "id": {
>> +            schema: VIEW_ID_SCHEMA,
>> +        },
>> +        "include": {
>> +            schema: FILTER_RULE_LIST_SCHEMA,
>> +            optional: true,
>> +        },
>> +        "exclude": {
>> +            schema: FILTER_RULE_LIST_SCHEMA,
>> +            optional: true,
>> +        }
>> +    }
>> +)]
>> +#[derive(Clone, Debug, Default, Deserialize, Serialize, Updater, PartialEq)]
>> +#[serde(rename_all = "kebab-case")]
>> +/// View definition
>> +pub struct ViewConfig {
>> +    /// View name.
>> +    #[updater(skip)]
>> +    pub id: String,
>> +
>> +    /// List of includes.
>> +    #[serde(default, skip_serializing_if = "Vec::is_empty")]
>> +    #[updater(serde(skip_serializing_if = "Option::is_none"))]
>> +    pub include: Vec<FilterRule>,
>> +
>> +    /// List of excludes.
>> +    #[serde(default, skip_serializing_if = "Vec::is_empty")]
>> +    #[updater(serde(skip_serializing_if = "Option::is_none"))]
>> +    pub exclude: Vec<FilterRule>,
>> +}
>> +
>> +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
>> +#[serde(rename_all = "kebab-case")]
>> +/// Enum for the different sections in the 'views.cfg' file.
>> +pub enum ViewConfigEntry {
>> +    /// 'view' section
>> +    View(ViewConfig),
>> +}
>> +
>> +const VIEW_SECTION_NAME: &str = "view";
>> +
>> +impl ApiSectionDataEntry for ViewConfigEntry {
>> +    fn section_config() -> &'static SectionConfig {
>> +        static CONFIG: OnceLock<SectionConfig> = OnceLock::new();
>> +
>> +        CONFIG.get_or_init(|| {
>> +            let mut this = SectionConfig::new(&VIEW_ID_SCHEMA);
>> +
>> +            this.register_plugin(SectionConfigPlugin::new(
>> +                VIEW_SECTION_NAME.into(),
>> +                Some("id".to_string()),
>> +                ViewConfig::API_SCHEMA.unwrap_object_schema(),
>> +            ));
>> +            this
>> +        })
>> +    }
>> +
>> +    fn section_type(&self) -> &'static str {
>> +        match self {
>> +            ViewConfigEntry::View(_) => VIEW_SECTION_NAME,
>> +        }
>> +    }
>> +}
>> +
>> +#[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}");
>
> This should probably have different error message such as "invalid
> resource pool ID".
>

Fixed as well.



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

  reply	other threads:[~2025-11-12 10:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06 13:43 [pdm-devel] [PATCH datacenter-manager v3 00/11] backend implementation for view filters Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 01/11] pdm-api-types: views: add ViewConfig type Lukas Wagner
2025-11-11 10:57   ` Michael Köppl
2025-11-12 10:04     ` Lukas Wagner
2025-11-11 10:58   ` Michael Köppl
2025-11-12 10:05     ` Lukas Wagner [this message]
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 02/11] pdm-config: views: add support for views Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 03/11] acl: add '/view' and '/view/{view-id}' as allowed ACL paths Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 04/11] views: add implementation for view resource filtering Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 05/11] api: resources: list: add support for view parameter Lukas Wagner
2025-11-11 14:31   ` Michael Köppl
2025-11-12 10:14     ` Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 06/11] api: resources: top entities: " Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 07/11] api: resources: status: " Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 08/11] api: subscription " Lukas Wagner
2025-11-11 14:46   ` Michael Köppl
2025-11-12  8:19     ` Shannon Sterz
2025-11-12 10:26       ` Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 09/11] api: remote-tasks: " Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 10/11] pdm-client: resource list: add view-filter parameter Lukas Wagner
2025-11-06 13:43 ` [pdm-devel] [PATCH datacenter-manager v3 11/11] pdm-client: top entities: " Lukas Wagner
2025-11-11 15:00 ` [pdm-devel] [PATCH datacenter-manager v3 00/11] backend implementation for view filters Michael Köppl
2025-11-12 10:37 ` [pdm-devel] superseded: " 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=DE6MRB4E6T68.2BR2GPL7QPCUQ@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=m.koeppl@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