From 7747ac46de296155770d2957ef04e7811a5bb43d Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Fri, 8 Nov 2024 15:41:14 +0100 Subject: [PATCH] common: notify: add bindings for webhook API routes Signed-off-by: Lukas Wagner Tested-By: Stefan Hanreich --- common/src/notify.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/common/src/notify.rs b/common/src/notify.rs index e1b006b..fe192d5 100644 --- a/common/src/notify.rs +++ b/common/src/notify.rs @@ -19,6 +19,9 @@ mod export { DeleteableSmtpProperty, SmtpConfig, SmtpConfigUpdater, SmtpMode, SmtpPrivateConfig, SmtpPrivateConfigUpdater, }; + use proxmox_notify::endpoints::webhook::{ + DeleteableWebhookProperty, WebhookConfig, WebhookConfigUpdater, + }; use proxmox_notify::matcher::{ CalendarMatcher, DeleteableMatcherProperty, FieldMatcher, MatchModeOperator, MatcherConfig, MatcherConfigUpdater, SeverityMatcher, @@ -393,6 +396,66 @@ mod export { api::smtp::delete_endpoint(&mut config, name) } + #[export(serialize_error)] + fn get_webhook_endpoints( + #[try_from_ref] this: &NotificationConfig, + ) -> Result, HttpError> { + let config = this.config.lock().unwrap(); + api::webhook::get_endpoints(&config) + } + + #[export(serialize_error)] + fn get_webhook_endpoint( + #[try_from_ref] this: &NotificationConfig, + id: &str, + ) -> Result { + let config = this.config.lock().unwrap(); + api::webhook::get_endpoint(&config, id) + } + + #[export(serialize_error)] + #[allow(clippy::too_many_arguments)] + fn add_webhook_endpoint( + #[try_from_ref] this: &NotificationConfig, + endpoint_config: WebhookConfig, + ) -> Result<(), HttpError> { + let mut config = this.config.lock().unwrap(); + api::webhook::add_endpoint( + &mut config, + endpoint_config, + ) + } + + #[export(serialize_error)] + #[allow(clippy::too_many_arguments)] + fn update_webhook_endpoint( + #[try_from_ref] this: &NotificationConfig, + name: &str, + config_updater: WebhookConfigUpdater, + delete: Option>, + digest: Option<&str>, + ) -> Result<(), HttpError> { + let mut config = this.config.lock().unwrap(); + let digest = decode_digest(digest)?; + + api::webhook::update_endpoint( + &mut config, + name, + config_updater, + delete.as_deref(), + digest.as_deref(), + ) + } + + #[export(serialize_error)] + fn delete_webhook_endpoint( + #[try_from_ref] this: &NotificationConfig, + name: &str, + ) -> Result<(), HttpError> { + let mut config = this.config.lock().unwrap(); + api::webhook::delete_endpoint(&mut config, name) + } + #[export(serialize_error)] fn get_matchers( #[try_from_ref] this: &NotificationConfig,