From: Dominik Csapak <d.csapak@proxmox.com>
To: Proxmox Datacenter Manager development discussion
<pdm-devel@lists.proxmox.com>,
Lukas Wagner <l.wagner@proxmox.com>
Subject: Re: [pdm-devel] [PATCH datacenter-manager v2 02/12] pdm-config: views: add support for view-filters
Date: Wed, 5 Nov 2025 11:07:56 +0100 [thread overview]
Message-ID: <a20f7d22-bc35-4ae3-a5dd-36fa726d96de@proxmox.com> (raw)
In-Reply-To: <20251103123521.266258-3-l.wagner@proxmox.com>
high level comments:
would it be nicer if we use the ApiSectionDataEntry trait like we do for
Remotes ?
that way we can use the typed section config helpers
(which are a bit more ergonomic to use later in the CRUD api calls)
Also if we just use one file for the views, is it necessary
to put it in a views folder?
I'm currently thinking about how to save the layouts, and (as we
recently discussed off-list) I'm leaning towards simply saving the
layout as a json string into the config here, as that makes the
loading/saving/updating/deleting much easier for both view filters
and layouts (no need to track/lock both configs, etc.)
We can of course leave it , but then we have to make sure to create
the directory correctly :)
On 11/3/25 1:35 PM, Lukas Wagner wrote:
> This allows to read ViewFilterConfig entries from a new config file at
> /etc/proxmox-datacenter-manager/views/filters.cfg.
>
> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
> ---
> lib/pdm-api-types/src/lib.rs | 6 ++++
> lib/pdm-config/src/lib.rs | 2 +-
> lib/pdm-config/src/views.rs | 62 ++++++++++++++++++++++++++++++++++++
> 3 files changed, 69 insertions(+), 1 deletion(-)
> create mode 100644 lib/pdm-config/src/views.rs
>
> diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs
> index a7ba6d89..ed284ab2 100644
> --- a/lib/pdm-api-types/src/lib.rs
> +++ b/lib/pdm-api-types/src/lib.rs
> @@ -159,6 +159,12 @@ pub const REALM_ID_SCHEMA: Schema = StringSchema::new("Realm name.")
> .max_length(32)
> .schema();
>
> +pub const VIEW_FILTER_ID_SCHEMA: Schema = StringSchema::new("View filter name.")
> + .format(&PROXMOX_SAFE_ID_FORMAT)
> + .min_length(2)
> + .max_length(32)
> + .schema();
> +
> pub const VMID_SCHEMA: Schema = IntegerSchema::new("A guest ID").minimum(1).schema();
> pub const SNAPSHOT_NAME_SCHEMA: Schema = StringSchema::new("The name of the snapshot")
> .format(&PROXMOX_SAFE_ID_FORMAT)
> diff --git a/lib/pdm-config/src/lib.rs b/lib/pdm-config/src/lib.rs
> index ac398cab..4c490541 100644
> --- a/lib/pdm-config/src/lib.rs
> +++ b/lib/pdm-config/src/lib.rs
> @@ -1,6 +1,5 @@
> use anyhow::{format_err, Error};
> use nix::unistd::{Gid, Group, Uid, User};
> -
> pub use pdm_buildcfg::{BACKUP_GROUP_NAME, BACKUP_USER_NAME};
>
> pub mod certificate_config;
> @@ -8,6 +7,7 @@ pub mod domains;
> pub mod node;
> pub mod remotes;
> pub mod setup;
> +pub mod views;
>
> mod config_version_cache;
> pub use config_version_cache::ConfigVersionCache;
> diff --git a/lib/pdm-config/src/views.rs b/lib/pdm-config/src/views.rs
> new file mode 100644
> index 00000000..adeb67b1
> --- /dev/null
> +++ b/lib/pdm-config/src/views.rs
> @@ -0,0 +1,62 @@
> +use std::sync::LazyLock;
> +
> +use anyhow::Error;
> +
> +use proxmox_schema::ApiType;
> +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
> +
> +use pdm_api_types::{views::ViewFilterConfig, ConfigDigest, VIEW_FILTER_ID_SCHEMA};
> +
> +use pdm_buildcfg::configdir;
> +
> +static VIEW_FILTER_SECTION_NAME: &str = "view-filter";
> +
> +static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
> +
> +fn init() -> SectionConfig {
> + let mut config = SectionConfig::new(&VIEW_FILTER_ID_SCHEMA);
> +
> + let view_plugin = SectionConfigPlugin::new(
> + VIEW_FILTER_SECTION_NAME.to_string(),
> + Some("id".to_string()),
> + ViewFilterConfig::API_SCHEMA.unwrap_object_schema(),
> + );
> + config.register_plugin(view_plugin);
> +
> + config
> +}
> +
> +const VIEW_FILTER_CFG_FILENAME: &str = configdir!("/views/filters.cfg");
> +
> +// TODO: Will be needed once the CRUD API for view filters is implemented.
> +// const VIEW_FILTER_CFG_LOCKFILE: &str = configdir!("/views/.filters.lock");
> +
> +// TODO: Will be needed once the CRUD API for view filters is implemented.
> +/// Get exclusive lock
> +// fn lock_config() -> Result<ApiLockGuard, Error> {
> +// open_api_lockfile(VIEW_FILTER_CFG_LOCKFILE, None, true)
> +// }
> +
> +fn config() -> Result<(SectionConfigData, ConfigDigest), Error> {
> + let content =
> + proxmox_sys::fs::file_read_optional_string(VIEW_FILTER_CFG_FILENAME)?.unwrap_or_default();
> + let digest = ConfigDigest::from_slice(content.as_bytes());
> + let data = CONFIG.parse(VIEW_FILTER_CFG_FILENAME, &content)?;
> + Ok((data, digest))
> +}
> +
> +// TODO: Will be needed once the CRUD API for view filters is implemented.
> +// fn save_config(config: &SectionConfigData) -> Result<(), Error> {
> +// let raw = CONFIG.write(VIEW_FILTER_CFG_FILENAME, config)?;
> +// replace_privileged_config(VIEW_FILTER_CFG_FILENAME, raw.as_bytes())
> +// }
> +//
> +
> +/// Get the [`ViewFilterConfig`] entry for a view filter with a given ID.
> +///
> +/// This will fail if the config file does not exist or if the view filter does not exist.
> +pub fn get_view_filter_config(filter_name: &str) -> Result<ViewFilterConfig, Error> {
> + let (cfg, _) = config()?;
> +
> + cfg.lookup(VIEW_FILTER_SECTION_NAME, filter_name)
> +}
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-11-05 10:07 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 12:35 [pdm-devel] [PATCH datacenter-manager v2 00/12] backend implementation for view filters Lukas Wagner
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 01/12] pdm-api-types: views: add ViewFilterConfig type Lukas Wagner
2025-11-05 10:07 ` Dominik Csapak
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 02/12] pdm-config: views: add support for view-filters Lukas Wagner
2025-11-05 10:07 ` Dominik Csapak [this message]
2025-11-05 10:37 ` Lukas Wagner
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 03/12] acl: add '/view' and '/view/{view-id}' as allowed ACL paths Lukas Wagner
2025-11-05 10:07 ` Dominik Csapak
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 04/12] views: add implementation for view filters Lukas Wagner
2025-11-05 10:08 ` Dominik Csapak
2025-11-05 10:58 ` Lukas Wagner
2025-11-05 11:48 ` Dominik Csapak
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 05/12] views: add tests for view filter implementation Lukas Wagner
2025-11-05 10:08 ` Dominik Csapak
2025-11-05 10:58 ` Lukas Wagner
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 06/12] api: resources: list: add support for view-filter parameter Lukas Wagner
2025-11-05 10:08 ` Dominik Csapak
2025-11-05 14:56 ` Lukas Wagner
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 07/12] api: resources: top entities: " Lukas Wagner
2025-11-05 10:08 ` Dominik Csapak
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 08/12] api: resources: status: " Lukas Wagner
2025-11-05 10:08 ` Dominik Csapak
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 09/12] api: subscription " Lukas Wagner
2025-11-05 10:08 ` Dominik Csapak
2025-11-05 14:11 ` Lukas Wagner
2025-11-05 14:28 ` Dominik Csapak
2025-11-05 14:35 ` Lukas Wagner
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 10/12] api: remote-tasks: " Lukas Wagner
2025-11-05 10:09 ` Dominik Csapak
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 11/12] pdm-client: resource list: add " Lukas Wagner
2025-11-05 10:11 ` Dominik Csapak
2025-11-03 12:35 ` [pdm-devel] [PATCH datacenter-manager v2 12/12] pdm-client: top entities: " Lukas Wagner
2025-11-05 10:12 ` Dominik Csapak
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=a20f7d22-bc35-4ae3-a5dd-36fa726d96de@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox