proxmox/proxmox-notify/src/context.rs
Lukas Wagner c5f91aa1c8 notify: sendmail: allow users as recipients
This introduces a new configuration parameter `mailto-user`.
A user's email address will be looked up in the product-specific
user database.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 10:25:57 +02:00

17 lines
457 B
Rust

use once_cell::sync::OnceCell;
use std::fmt::Debug;
pub trait Context: Send + Sync + Debug {
fn lookup_email_for_user(&self, user: &str) -> Option<String>;
}
static CONTEXT: OnceCell<&'static dyn Context> = OnceCell::new();
pub fn set_context(context: &'static dyn Context) {
CONTEXT.set(context).expect("context has already been set");
}
pub(crate) fn context() -> &'static dyn Context {
*CONTEXT.get().expect("context has not been yet")
}