[pve-devel] [PATCH v2 proxmox-perl-rs 21/42] notify: add api for notification channels
Lukas Wagner
l.wagner at proxmox.com
Wed May 24 15:56:28 CEST 2023
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
pve-rs/src/notify.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/pve-rs/src/notify.rs b/pve-rs/src/notify.rs
index a101416..c6483dc 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::channel::{ChannelConfig, ChannelConfigUpdater, DeleteableChannelProperty};
use proxmox_notify::{api, api::ApiError, Config, Notification, Severity};
pub struct NotificationConfig {
@@ -92,4 +93,70 @@ mod export {
let config = this.config.lock().unwrap();
api::common::test_endpoint(&config, endpoint)
}
+
+ #[export(serialize_error)]
+ fn get_channels(
+ #[try_from_ref] this: &NotificationConfig,
+ ) -> Result<Vec<ChannelConfig>, ApiError> {
+ let config = this.config.lock().unwrap();
+ api::channel::get_channels(&config)
+ }
+
+ #[export(serialize_error)]
+ fn get_channel(
+ #[try_from_ref] this: &NotificationConfig,
+ id: &str,
+ ) -> Result<ChannelConfig, ApiError> {
+ let config = this.config.lock().unwrap();
+ api::channel::get_channel(&config, id)
+ }
+
+ #[export(serialize_error)]
+ fn add_channel(
+ #[try_from_ref] this: &NotificationConfig,
+ name: String,
+ endpoints: Option<Vec<String>>,
+ comment: Option<String>,
+ ) -> Result<(), ApiError> {
+ let mut config = this.config.lock().unwrap();
+ api::channel::add_channel(
+ &mut config,
+ &ChannelConfig {
+ name,
+ endpoint: endpoints,
+ comment,
+ },
+ )
+ }
+
+ #[export(serialize_error)]
+ fn update_channel(
+ #[try_from_ref] this: &NotificationConfig,
+ name: &str,
+ endpoints: Option<Vec<String>>,
+ comment: Option<String>,
+ delete: Option<Vec<DeleteableChannelProperty>>,
+ digest: Option<&str>,
+ ) -> Result<(), ApiError> {
+ let mut config = this.config.lock().unwrap();
+ api::channel::update_channel(
+ &mut config,
+ name,
+ &ChannelConfigUpdater {
+ endpoint: endpoints,
+ comment,
+ },
+ delete.as_deref(),
+ digest.map(|d| d.as_bytes()),
+ )
+ }
+
+ #[export(serialize_error)]
+ fn delete_channel(
+ #[try_from_ref] this: &NotificationConfig,
+ name: &str,
+ ) -> Result<(), ApiError> {
+ let mut config = this.config.lock().unwrap();
+ api::channel::delete_channel(&mut config, name)
+ }
}
--
2.30.2
More information about the pve-devel
mailing list