0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-10-30 09:05:52 +01:00
simple-wkd/src/settings.rs

55 lines
1.3 KiB
Rust
Raw Normal View History

2023-04-14 00:52:54 +02:00
use once_cell::sync::Lazy;
use sequoia_net::wkd::Variant;
use serde::{Deserialize, Serialize};
2023-04-14 12:18:49 +02:00
use std::fs;
2023-04-14 00:52:54 +02:00
#[derive(Serialize, Deserialize, Debug)]
pub struct Settings {
#[serde(with = "VariantDef")]
pub variant: Variant,
2023-04-14 12:18:49 +02:00
pub root_folder: String,
2023-04-14 00:52:54 +02:00
pub max_age: i64,
2023-04-14 01:05:27 +02:00
pub cleanup_interval: u64,
2023-04-14 00:52:54 +02:00
pub port: u16,
2023-04-14 12:18:49 +02:00
pub external_url: String,
pub mail_settings: MailSettings,
2023-04-14 00:52:54 +02:00
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MailSettings {
pub smtp_host: String,
pub smtp_username: String,
pub smtp_password: String,
pub smtp_port: u16,
2023-04-14 12:18:49 +02:00
pub smtp_tls: SMTPEncryption,
2023-04-14 00:52:54 +02:00
pub mail_from: String,
pub mail_subject: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(remote = "Variant")]
pub enum VariantDef {
Advanced,
Direct,
}
2023-04-14 12:18:49 +02:00
#[derive(Serialize, Deserialize, Debug)]
pub enum SMTPEncryption {
Tls,
Starttls,
}
2023-04-14 00:52:54 +02:00
fn get_settings() -> Settings {
2023-04-14 01:05:27 +02:00
println!("Reaing settings...");
2023-04-14 12:18:49 +02:00
let content = match fs::read_to_string("wkd.toml") {
Ok(content) => content,
Err(_) => panic!("Unable to access settings file!"),
};
match toml::from_str(&content) {
Ok(settings) => settings,
Err(_) => panic!("Unable to parse settings from file!"),
}
2023-04-14 00:52:54 +02:00
}
pub static SETTINGS: Lazy<Settings> = Lazy::new(get_settings);