Compare commits

..

2 commits

Author SHA1 Message Date
6bc4b7b143 docs: add config details for sending emails
All checks were successful
Rust / build (push) Successful in 1m24s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-08-02 18:47:05 +01:00
9fb70f98d6 test: update tests to check for email config parsing
All checks were successful
Rust / build (push) Successful in 1m18s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-08-02 18:47:05 +01:00
3 changed files with 51 additions and 12 deletions

View file

@ -118,11 +118,33 @@ The server should be able to notify the user when manual intervention is require
##### webhook ##### webhook
Will send a POST request for some events.
- **url** - the URL to POST the notification to and the - **url** - the URL to POST the notification to and the
- **secret** - the sync key used to sign the webhook payload - **secret** - the sync key used to sign the webhook payload
See [Notifications](#notifications) for more details. See [Notifications](#notifications) for more details.
##### email
Will send an email for some events.
- **from** - the email address to send the email from
- **to** - the email address to send the email to
With just `from` and `to` specified, `git-next` will attempt to send emails
with `sendmail` if it is configured.
Alternativly, you can use an SMTP relay.
###### smtp
Will send emails using an SMTP relay.
- **hostname** - the SMTP relay server
- **username** - the account to authenticate as
- **password** - the password to authenticate with
#### storage #### storage
`git-next` will create a bare clone of each repo that you configure it to `git-next` will create a bare clone of each repo that you configure it to

View file

@ -8,7 +8,7 @@ use std::{
str::FromStr, str::FromStr,
}; };
use derive_more::Display; use derive_more::{Constructor, Display};
use kxio::fs::FileSystem; use kxio::fs::FileSystem;
use secrecy::Secret; use secrecy::Secret;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -204,19 +204,13 @@ impl ServerStorage {
Ord, Ord,
derive_more::AsRef, derive_more::AsRef,
serde::Deserialize, serde::Deserialize,
Constructor,
)] )]
pub struct Shout { pub struct Shout {
webhook: Option<OutboundWebhook>, webhook: Option<OutboundWebhook>,
email: Option<EmailConfig>, email: Option<EmailConfig>,
} }
impl Shout { impl Shout {
pub const fn new_webhook(webhook: OutboundWebhook) -> Self {
Self {
webhook: Some(webhook),
email: None,
}
}
pub const fn webhook(&self) -> Option<&OutboundWebhook> { pub const fn webhook(&self) -> Option<&OutboundWebhook> {
self.webhook.as_ref() self.webhook.as_ref()
} }

View file

@ -475,6 +475,13 @@ mod server {
.webhook_secret() .webhook_secret()
.map(|secret| secret.expose_secret().clone()) .map(|secret| secret.expose_secret().clone())
.unwrap_or_default(); .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 let forge_alias = server_config
.forges() .forges()
.next() .next()
@ -521,6 +528,15 @@ url = "{listen_url}"
[shout] [shout]
webhook = {{ url = "{shout_webhook_url}", secret = "{shout_webhook_secret}" }} 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] [storage]
path = {storage_path:?} path = {storage_path:?}
@ -692,7 +708,7 @@ mod push {
} }
mod given { mod given {
use crate::server::{Listen, ListenUrl, OutboundWebhook, Shout}; use crate::server::{EmailConfig, Listen, ListenUrl, OutboundWebhook, Shout, SmtpConfig};
use super::*; use super::*;
use rand::Rng as _; use rand::Rng as _;
@ -716,7 +732,7 @@ mod given {
pub fn a_server_config() -> ServerConfig { pub fn a_server_config() -> ServerConfig {
ServerConfig::new( ServerConfig::new(
a_listen(), a_listen(),
a_notification_config(), a_shout(),
a_server_storage(), a_server_storage(),
some_forge_configs(), some_forge_configs(),
) )
@ -746,11 +762,18 @@ mod given {
pub fn an_outbound_webhook() -> OutboundWebhook { pub fn an_outbound_webhook() -> OutboundWebhook {
OutboundWebhook::new(a_name(), a_name()) 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 { pub fn a_server_storage() -> ServerStorage {
ServerStorage::new(a_name().into()) ServerStorage::new(a_name().into())
} }
pub fn a_notification_config() -> Shout { pub fn a_shout() -> Shout {
Shout::new_webhook(an_outbound_webhook()) Shout::new(Some(an_outbound_webhook()), Some(an_email_config()))
} }
pub fn some_forge_configs() -> BTreeMap<String, ForgeConfig> { pub fn some_forge_configs() -> BTreeMap<String, ForgeConfig> {
[(a_name(), a_forge_config())].into() [(a_name(), a_forge_config())].into()