[pdm-devel] [PATCH datacenter-manager v2 02/12] pdm-config: views: add support for view-filters
Dominik Csapak
d.csapak at proxmox.com
Wed Nov 5 11:07:56 CET 2025
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 at 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)
> +}
More information about the pdm-devel
mailing list