proxmox/proxmox-notify/src/context.rs
Lukas Wagner d44ce2c70d notify: gotify: add proxy support
The proxy configuration will be read from datacenter.cfg via
a new method of the `Context` trait.

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

20 lines
604 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>;
fn default_sendmail_author(&self) -> String;
fn default_sendmail_from(&self) -> String;
fn http_proxy_config(&self) -> 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")
}