From 79f339d1367c2045c1fba7ebb5803ddaa8b476ca Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Thu, 20 Jul 2023 16:31:58 +0200 Subject: [PATCH] notify: add api for notification filters Signed-off-by: Lukas Wagner --- pve-rs/src/notify.rs | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/pve-rs/src/notify.rs b/pve-rs/src/notify.rs index 1d612f1..08726e5 100644 --- a/pve-rs/src/notify.rs +++ b/pve-rs/src/notify.rs @@ -12,6 +12,9 @@ mod export { use proxmox_notify::endpoints::sendmail::{ DeleteableSendmailProperty, SendmailConfig, SendmailConfigUpdater, }; + use proxmox_notify::filter::{ + DeleteableFilterProperty, FilterConfig, FilterConfigUpdater, FilterModeOperator, + }; use proxmox_notify::group::{DeleteableGroupProperty, GroupConfig, GroupConfigUpdater}; use proxmox_notify::{api, api::ApiError, Config, Notification, Severity}; @@ -342,4 +345,84 @@ mod export { let mut config = this.config.lock().unwrap(); api::gotify::delete_gotify_endpoint(&mut config, name) } + + #[export(serialize_error)] + fn get_filters( + #[try_from_ref] this: &NotificationConfig, + ) -> Result, ApiError> { + let config = this.config.lock().unwrap(); + api::filter::get_filters(&config) + } + + #[export(serialize_error)] + fn get_filter( + #[try_from_ref] this: &NotificationConfig, + id: &str, + ) -> Result { + let config = this.config.lock().unwrap(); + api::filter::get_filter(&config, id) + } + + #[export(serialize_error)] + #[allow(clippy::too_many_arguments)] + fn add_filter( + #[try_from_ref] this: &NotificationConfig, + name: String, + min_severity: Option, + mode: Option, + invert_match: Option, + comment: Option, + ) -> Result<(), ApiError> { + let mut config = this.config.lock().unwrap(); + api::filter::add_filter( + &mut config, + &FilterConfig { + name, + min_severity, + mode, + invert_match, + comment, + }, + ) + } + + #[export(serialize_error)] + #[allow(clippy::too_many_arguments)] + fn update_filter( + #[try_from_ref] this: &NotificationConfig, + name: &str, + min_severity: Option, + mode: Option, + invert_match: Option, + comment: 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::filter::update_filter( + &mut config, + name, + &FilterConfigUpdater { + min_severity, + mode, + invert_match, + comment, + }, + delete.as_deref(), + digest.as_deref(), + ) + } + + #[export(serialize_error)] + fn delete_filter( + #[try_from_ref] this: &NotificationConfig, + name: &str, + ) -> Result<(), ApiError> { + let mut config = this.config.lock().unwrap(); + api::filter::delete_filter(&mut config, name) + } } -- 2.39.2