myc_notifier/models/
smtp_config.rs

1use super::tmp_config::TmpConfig;
2
3use myc_config::{load_config_from_file, secret_resolver::SecretResolver};
4use mycelium_base::utils::errors::{creation_err, MappedErrors};
5use serde::Deserialize;
6use std::path::PathBuf;
7
8#[derive(Clone, Debug, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct SmtpConfig {
11    pub host: SecretResolver<String>,
12    pub username: SecretResolver<String>,
13    pub password: SecretResolver<String>,
14    pub port: SecretResolver<u16>,
15}
16
17unsafe impl Send for SmtpConfig {}
18
19impl SmtpConfig {
20    pub fn from_default_config_file(
21        file: PathBuf,
22    ) -> Result<Self, MappedErrors> {
23        if !file.exists() {
24            return creation_err(format!(
25                "Could not find config file: {}",
26                file.to_str().unwrap()
27            ))
28            .as_error();
29        }
30
31        match load_config_from_file::<TmpConfig>(file) {
32            Ok(config) => Ok(config.smtp),
33            Err(err) => Err(err),
34        }
35    }
36}