mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-04-30 20:38:38 +00:00
api: add endpoints for querying/testing notification targets
These endpoints require Sys.Audit permissions on /system/notifications. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> Tested-by: Gabriel Goller <g.goller@proxmox.com> Reviewed-by: Gabriel Goller <g.goller@proxmox.com> Tested-by: Maximiliano Sandoval <m.sandoval@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
fb0c163789
commit
c37f9dff6d
@ -11,6 +11,7 @@ pub mod datastore;
|
|||||||
pub mod drive;
|
pub mod drive;
|
||||||
pub mod media_pool;
|
pub mod media_pool;
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
|
pub mod notifications;
|
||||||
pub mod prune;
|
pub mod prune;
|
||||||
pub mod remote;
|
pub mod remote;
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
@ -28,6 +29,7 @@ const SUBDIRS: SubdirMap = &sorted!([
|
|||||||
("drive", &drive::ROUTER),
|
("drive", &drive::ROUTER),
|
||||||
("media-pool", &media_pool::ROUTER),
|
("media-pool", &media_pool::ROUTER),
|
||||||
("metrics", &metrics::ROUTER),
|
("metrics", &metrics::ROUTER),
|
||||||
|
("notifications", ¬ifications::ROUTER),
|
||||||
("prune", &prune::ROUTER),
|
("prune", &prune::ROUTER),
|
||||||
("remote", &remote::ROUTER),
|
("remote", &remote::ROUTER),
|
||||||
("sync", &sync::ROUTER),
|
("sync", &sync::ROUTER),
|
||||||
|
12
src/api2/config/notifications/mod.rs
Normal file
12
src/api2/config/notifications/mod.rs
Normal file
@ -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);
|
63
src/api2/config/notifications/targets.rs
Normal file
63
src/api2/config/notifications/targets.rs
Normal file
@ -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<Vec<Target>, 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);
|
Loading…
Reference in New Issue
Block a user