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 8897420EC8B for ; Tue, 23 Apr 2024 13:53:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6095730666; Tue, 23 Apr 2024 13:53:38 +0200 (CEST) From: Lukas Wagner To: pbs-devel@lists.proxmox.com Date: Tue, 23 Apr 2024 13:51:58 +0200 Message-Id: <20240423115230.170113-13-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240423115230.170113-1-l.wagner@proxmox.com> References: <20240423115230.170113-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.048 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 POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v5 12/44] api: add endpoints for querying/testing notification targets X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" These endpoints require Sys.Audit permissions on /system/notifications. Signed-off-by: Lukas Wagner Tested-by: Gabriel Goller Reviewed-by: Gabriel Goller Tested-by: Maximiliano Sandoval --- src/api2/config/mod.rs | 2 + src/api2/config/notifications/mod.rs | 12 +++++ src/api2/config/notifications/targets.rs | 63 ++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/api2/config/notifications/mod.rs create mode 100644 src/api2/config/notifications/targets.rs diff --git a/src/api2/config/mod.rs b/src/api2/config/mod.rs index 6cfeaea1..15dc5db9 100644 --- a/src/api2/config/mod.rs +++ b/src/api2/config/mod.rs @@ -11,6 +11,7 @@ pub mod datastore; pub mod drive; pub mod media_pool; pub mod metrics; +pub mod notifications; pub mod prune; pub mod remote; pub mod sync; @@ -28,6 +29,7 @@ const SUBDIRS: SubdirMap = &sorted!([ ("drive", &drive::ROUTER), ("media-pool", &media_pool::ROUTER), ("metrics", &metrics::ROUTER), + ("notifications", ¬ifications::ROUTER), ("prune", &prune::ROUTER), ("remote", &remote::ROUTER), ("sync", &sync::ROUTER), diff --git a/src/api2/config/notifications/mod.rs b/src/api2/config/notifications/mod.rs new file mode 100644 index 00000000..f75e3910 --- /dev/null +++ b/src/api2/config/notifications/mod.rs @@ -0,0 +1,12 @@ +use proxmox_router::list_subdirs_api_method; +use proxmox_router::{Router, SubdirMap}; +use proxmox_sortable_macro::sortable; + +mod targets; + +#[sortable] +const SUBDIRS: SubdirMap = &sorted!([("targets", &targets::ROUTER),]); + +pub const ROUTER: Router = Router::new() + .get(&list_subdirs_api_method!(SUBDIRS)) + .subdirs(SUBDIRS); diff --git a/src/api2/config/notifications/targets.rs b/src/api2/config/notifications/targets.rs new file mode 100644 index 00000000..6c5017b0 --- /dev/null +++ b/src/api2/config/notifications/targets.rs @@ -0,0 +1,63 @@ +use anyhow::Error; +use serde_json::Value; + +use proxmox_notify::api::Target; +use proxmox_notify::schema::ENTITY_NAME_SCHEMA; +use proxmox_router::{list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap}; +use proxmox_schema::api; +use proxmox_sortable_macro::sortable; + +use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; + +#[api( + protected: true, + input: { + properties: {}, + }, + returns: { + description: "List of all entities which can be used as notification targets.", + type: Array, + items: { type: Target }, + }, + access: { + permission: &Permission::Privilege(&["system", "notifications"], PRIV_SYS_AUDIT, false), + }, +)] +/// List all notification targets. +pub fn list_targets(_param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result, Error> { + let config = pbs_config::notifications::config()?; + let targets = proxmox_notify::api::get_targets(&config)?; + + Ok(targets) +} + +#[api( + protected: true, + input: { + properties: { + name: { + schema: ENTITY_NAME_SCHEMA, + }, + } + }, + access: { + permission: &Permission::Privilege(&["system", "notifications"], PRIV_SYS_MODIFY, false), + }, +)] +/// Test a given notification target. +pub fn test_target(name: String, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> { + let config = pbs_config::notifications::config()?; + proxmox_notify::api::common::test_target(&config, &name)?; + Ok(()) +} + +#[sortable] +const SUBDIRS: SubdirMap = &sorted!([("test", &TEST_ROUTER),]); +const TEST_ROUTER: Router = Router::new().post(&API_METHOD_TEST_TARGET); +const ITEM_ROUTER: Router = Router::new() + .get(&list_subdirs_api_method!(SUBDIRS)) + .subdirs(SUBDIRS); + +pub const ROUTER: Router = Router::new() + .get(&API_METHOD_LIST_TARGETS) + .match_all("name", &ITEM_ROUTER); -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel