mirror of
https://git.proxmox.com/git/proxmox-perl-rs
synced 2025-05-23 20:11:03 +00:00
notify: add api for notification groups
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
parent
350cdd6b59
commit
4b64b63ff7
@ -5,6 +5,7 @@ mod export {
|
|||||||
use serde_json::Value as JSONValue;
|
use serde_json::Value as JSONValue;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use proxmox_notify::group::{DeleteableGroupProperty, GroupConfig, GroupConfigUpdater};
|
||||||
use proxmox_notify::{api, api::ApiError, Config, Notification, Severity};
|
use proxmox_notify::{api, api::ApiError, Config, Notification, Severity};
|
||||||
|
|
||||||
pub struct NotificationConfig {
|
pub struct NotificationConfig {
|
||||||
@ -101,4 +102,73 @@ mod export {
|
|||||||
let config = this.config.lock().unwrap();
|
let config = this.config.lock().unwrap();
|
||||||
api::common::test_target(&config, target)
|
api::common::test_target(&config, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[export(serialize_error)]
|
||||||
|
fn get_groups(#[try_from_ref] this: &NotificationConfig) -> Result<Vec<GroupConfig>, ApiError> {
|
||||||
|
let config = this.config.lock().unwrap();
|
||||||
|
api::group::get_groups(&config)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[export(serialize_error)]
|
||||||
|
fn get_group(
|
||||||
|
#[try_from_ref] this: &NotificationConfig,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<GroupConfig, ApiError> {
|
||||||
|
let config = this.config.lock().unwrap();
|
||||||
|
api::group::get_group(&config, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[export(serialize_error)]
|
||||||
|
fn add_group(
|
||||||
|
#[try_from_ref] this: &NotificationConfig,
|
||||||
|
name: String,
|
||||||
|
endpoints: Vec<String>,
|
||||||
|
comment: Option<String>,
|
||||||
|
filter: Option<String>,
|
||||||
|
) -> Result<(), ApiError> {
|
||||||
|
let mut config = this.config.lock().unwrap();
|
||||||
|
api::group::add_group(
|
||||||
|
&mut config,
|
||||||
|
&GroupConfig {
|
||||||
|
name,
|
||||||
|
endpoint: endpoints,
|
||||||
|
comment,
|
||||||
|
filter,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[export(serialize_error)]
|
||||||
|
fn update_group(
|
||||||
|
#[try_from_ref] this: &NotificationConfig,
|
||||||
|
name: &str,
|
||||||
|
endpoints: Option<Vec<String>>,
|
||||||
|
comment: Option<String>,
|
||||||
|
filter: Option<String>,
|
||||||
|
delete: Option<Vec<DeleteableGroupProperty>>,
|
||||||
|
digest: Option<&str>,
|
||||||
|
) -> Result<(), ApiError> {
|
||||||
|
let mut config = this.config.lock().unwrap();
|
||||||
|
let digest = digest.map(hex::decode).transpose().map_err(|e| {
|
||||||
|
ApiError::internal_server_error(format!("invalid digest: {e}"), Some(Box::new(e)))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
api::group::update_group(
|
||||||
|
&mut config,
|
||||||
|
name,
|
||||||
|
&GroupConfigUpdater {
|
||||||
|
endpoint: endpoints,
|
||||||
|
comment,
|
||||||
|
filter,
|
||||||
|
},
|
||||||
|
delete.as_deref(),
|
||||||
|
digest.as_deref(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[export(serialize_error)]
|
||||||
|
fn delete_group(#[try_from_ref] this: &NotificationConfig, name: &str) -> Result<(), ApiError> {
|
||||||
|
let mut config = this.config.lock().unwrap();
|
||||||
|
api::group::delete_group(&mut config, name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user