ephemeris_forge_github/config/
webhooks.rs1use std::collections::BTreeMap;
2
3use ephemeris_forge::{Mode, WebhookContentType, non_empty_name};
4use facet::Facet;
5
6use super::ConfigError;
7
8non_empty_name! {
9 pub struct WebhookUrl;
11 pub error EmptyWebhookUrl("webhook URL cannot be empty");
13}
14
15#[derive(Clone, Debug, Eq, Facet, PartialEq)]
17#[facet(deny_unknown_fields)]
18pub struct Webhook {
19 pub content_type: WebhookContentType,
21 pub insecure_ssl: bool,
23 pub events: Vec<String>,
25 pub active: bool,
27}
28
29#[derive(Clone, Debug, Eq, Facet, PartialEq)]
31#[facet(deny_unknown_fields)]
32pub struct Webhooks {
33 pub mode: Mode,
35 pub webhooks: BTreeMap<WebhookUrl, Webhook>,
37}
38
39impl Webhooks {
40 pub fn validate(&self) -> Result<(), ConfigError> {
45 match self
46 .webhooks
47 .iter()
48 .find(|(_, webhook)| webhook.events.is_empty())
49 {
50 Some((url, _)) => Err(ConfigError::EmptyWebhookEvents { url: url.clone() }),
51 None => Ok(()),
52 }
53 }
54}