[pve-devel] [PATCH v3 proxmox-perl-rs 26/66] notify: add api for notification groups
Lukas Wagner
l.wagner at proxmox.com
Mon Jul 17 17:00:11 CEST 2023
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
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 74a872b..cac233a 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 {
@@ -98,4 +99,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<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)
+ }
}
--
2.39.2
More information about the pve-devel
mailing list