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 0603D1FF179 for ; Wed, 29 Oct 2025 15:48:45 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CD70AE523; Wed, 29 Oct 2025 15:49:16 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Wed, 29 Oct 2025 15:48:52 +0100 Message-ID: <20251029144902.446852-4-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251029144902.446852-1-l.wagner@proxmox.com> References: <20251029144902.446852-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1761749337862 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 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: [pdm-devel] [PATCH datacenter-manager 03/13] 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" 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) +} -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel