From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 26AAE1FF183 for ; Wed, 5 Nov 2025 11:07:20 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3A2C01FCEE; Wed, 5 Nov 2025 11:08:00 +0100 (CET) Message-ID: Date: Wed, 5 Nov 2025 11:07:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta To: Proxmox Datacenter Manager development discussion , Lukas Wagner References: <20251103123521.266258-1-l.wagner@proxmox.com> <20251103123521.266258-3-l.wagner@proxmox.com> Content-Language: en-US From: Dominik Csapak In-Reply-To: <20251103123521.266258-3-l.wagner@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762337258167 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pdm-devel] [PATCH datacenter-manager v2 02/12] pdm-config: views: add support for view-filters X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" 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 > --- > 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 = 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 { > +// 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 { > + 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