opensmtpd-filter-dkimout/src/action.rs

35 lines
844 B
Rust
Raw Normal View History

2023-04-09 15:13:18 +02:00
use crate::config::Config;
use crate::entry::read_entry;
2023-04-09 17:21:17 +02:00
use crate::key::key_rotation;
2023-04-09 15:13:18 +02:00
use crate::message::Message;
use crate::stdin_reader::StdinReader;
2023-04-09 17:21:17 +02:00
use sqlx::SqlitePool;
2023-04-09 15:13:18 +02:00
use std::sync::Arc;
use tokio::sync::RwLock;
pub enum Action<'a> {
ReadLine(Arc<RwLock<StdinReader>>),
RotateKeys((&'a SqlitePool, &'a Config)),
SendMessage((Message, &'a Config)),
}
2023-04-09 15:13:18 +02:00
pub enum ActionResult {
EndOfStream,
2023-04-09 17:21:17 +02:00
KeyRotation,
2023-04-09 15:13:18 +02:00
MessageSent(String),
MessageSentError(String),
NewEntry(crate::entry::Entry),
NewEntryError(String),
}
pub async fn new_action(action: Action<'_>) -> ActionResult {
match action {
Action::ReadLine(reader_lock) => read_entry(reader_lock).await,
Action::RotateKeys((db, cnf)) => {
key_rotation(db, cnf).await;
ActionResult::KeyRotation
2023-04-09 17:21:17 +02:00
}
Action::SendMessage((msg, cnf)) => msg.sign_and_return(cnf).await,
2023-04-09 15:13:18 +02:00
}
}