From 4b64b63ff734e053946c1f92d5b588d9e847f4bc Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Thu, 20 Jul 2023 16:31:55 +0200 Subject: [PATCH] notify: add api for notification groups Signed-off-by: Lukas Wagner --- pve-rs/src/notify.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/pve-rs/src/notify.rs b/pve-rs/src/notify.rs index cff1b44..8014e6d 100644 --- a/pve-rs/src/notify.rs +++ b/pve-rs/src/notify.rs @@ -5,6 +5,7 @@ mod export { use serde_json::Value as JSONValue; use std::sync::Mutex; + use proxmox_notify::group::{DeleteableGroupProperty, GroupConfig, GroupConfigUpdater}; use proxmox_notify::{api, api::ApiError, Config, Notification, Severity}; pub struct NotificationConfig { @@ -101,4 +102,73 @@ mod export { let config = this.config.lock().unwrap(); api::common::test_target(&config, target) } + + #[export(serialize_error)] + fn get_groups(#[try_from_ref] this: &NotificationConfig) -> Result, 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 { + 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, + comment: Option, + filter: Option, + ) -> 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>, + comment: Option, + filter: Option, + delete: Option>, + 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) + } }