use std::env; use config::{Config, ConfigError}; #[derive(Debug, Deserialize, Default, Clone)] pub struct Database { pub connection_string: String, } #[derive(Debug, Deserialize, Default, Clone)] pub struct Application { pub url: String, pub default_language: String, pub fallback_language: String, pub loglevel: String, pub session_timeout: i64, pub upload_path: String, pub max_login_attempts: i32, pub login_lock_duration: i32, pub name: String, pub reset_password_token_valid_duration: i64, pub user_support_email: String, pub new_member_default_role: String, pub default_timezone: String, } #[derive(Debug, Deserialize, Default, Clone)] pub struct Mail{ pub from: String, pub reply_to: String, pub communication_email_type_id: String, pub smtp_host: String, pub smtp_username: String, pub smtp_password: String, } #[derive(Debug, Deserialize, Default, Clone)] pub struct Api { pub default_pagination_limit: i64, } #[derive(Debug, Deserialize, Default, Clone)] pub struct Billing { pub member_responsible_overwrites_permissions: bool, pub send_personnel_billing_to_email: bool, pub personnel_billing_emails: String, pub lump_sum_name: String, pub money_for_time_name: String, } #[derive(Debug, Deserialize, Default, Clone)] pub struct Settings { pub database: Database, pub application: Application, pub mail: Mail, pub api: Api, pub billing: Billing, } impl Settings { pub fn new() -> Result { let env = env::var("RUN_MODE").unwrap_or("development".into()); Config::builder() .add_source(config::File::with_name("config/default")) .add_source(config::File::with_name(&format!("config/{}", env)).required(false)) // This file shouldn't be checked in to git: .add_source(config::File::with_name("config/local").required(false)) .build()?.try_deserialize() } }