diff --git a/crates/core/src/config/server.rs b/crates/core/src/config/server.rs index 1133862..13bb1f4 100644 --- a/crates/core/src/config/server.rs +++ b/crates/core/src/config/server.rs @@ -8,7 +8,7 @@ use std::{ str::FromStr, }; -use derive_more::Display; +use derive_more::{Constructor, Display}; use kxio::fs::FileSystem; use secrecy::Secret; use serde::{Deserialize, Serialize}; @@ -204,19 +204,13 @@ impl ServerStorage { Ord, derive_more::AsRef, serde::Deserialize, + Constructor, )] pub struct Shout { webhook: Option, email: Option, } impl Shout { - pub const fn new_webhook(webhook: OutboundWebhook) -> Self { - Self { - webhook: Some(webhook), - email: None, - } - } - pub const fn webhook(&self) -> Option<&OutboundWebhook> { self.webhook.as_ref() } diff --git a/crates/core/src/config/tests.rs b/crates/core/src/config/tests.rs index ec42d62..152dc43 100644 --- a/crates/core/src/config/tests.rs +++ b/crates/core/src/config/tests.rs @@ -475,6 +475,13 @@ mod server { .webhook_secret() .map(|secret| secret.expose_secret().clone()) .unwrap_or_default(); + let_assert!(Some(shout_email) = shout.email()); + let shout_email_from = shout_email.from(); + let shout_email_to = shout_email.to(); + let_assert!(Some(shout_email_smtp) = shout_email.smtp()); + let shout_email_smtp_hostname = shout_email_smtp.hostname(); + let shout_email_smtp_username = shout_email_smtp.username(); + let shout_email_smtp_password = shout_email_smtp.password(); let forge_alias = server_config .forges() .next() @@ -521,6 +528,15 @@ url = "{listen_url}" [shout] webhook = {{ url = "{shout_webhook_url}", secret = "{shout_webhook_secret}" }} +[shout.email] +from = "{shout_email_from}" +to = "{shout_email_to}" + +[shout.email.smtp] +hostname = "{shout_email_smtp_hostname}" +username = "{shout_email_smtp_username}" +password = "{shout_email_smtp_password}" + [storage] path = {storage_path:?} @@ -692,7 +708,7 @@ mod push { } mod given { - use crate::server::{Listen, ListenUrl, OutboundWebhook, Shout}; + use crate::server::{EmailConfig, Listen, ListenUrl, OutboundWebhook, Shout, SmtpConfig}; use super::*; use rand::Rng as _; @@ -716,7 +732,7 @@ mod given { pub fn a_server_config() -> ServerConfig { ServerConfig::new( a_listen(), - a_notification_config(), + a_shout(), a_server_storage(), some_forge_configs(), ) @@ -746,11 +762,18 @@ mod given { pub fn an_outbound_webhook() -> OutboundWebhook { OutboundWebhook::new(a_name(), a_name()) } + pub fn an_email_config() -> EmailConfig { + EmailConfig::new( + a_name(), + a_name(), + Some(SmtpConfig::new(a_name(), a_name(), a_name())), + ) + } pub fn a_server_storage() -> ServerStorage { ServerStorage::new(a_name().into()) } - pub fn a_notification_config() -> Shout { - Shout::new_webhook(an_outbound_webhook()) + pub fn a_shout() -> Shout { + Shout::new(Some(an_outbound_webhook()), Some(an_email_config())) } pub fn some_forge_configs() -> BTreeMap { [(a_name(), a_forge_config())].into()