93 lines
2.2 KiB
Rust
93 lines
2.2 KiB
Rust
use serde::Deserialize;
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct Config {
|
|
pub server: ServerConfig,
|
|
pub database: DatabaseConfig,
|
|
pub auth: AuthConfig,
|
|
#[serde(default)]
|
|
pub oidc: Vec<OidcProviderConfig>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct ServerConfig {
|
|
#[serde(default = "default_bind")]
|
|
pub bind: String,
|
|
#[serde(default = "default_base_url")]
|
|
pub base_url: String,
|
|
#[serde(default)]
|
|
pub allowed_origins: Vec<String>,
|
|
#[serde(default)]
|
|
pub static_dir: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct DatabaseConfig {
|
|
pub url: String,
|
|
#[serde(default = "default_max_connections")]
|
|
pub max_connections: u32,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct AuthConfig {
|
|
#[serde(default = "default_session_ttl_minutes")]
|
|
pub session_ttl_minutes: i64,
|
|
#[serde(default)]
|
|
pub cookie_domain: Option<String>,
|
|
#[serde(default = "default_cookie_secure")]
|
|
pub cookie_secure: bool,
|
|
#[serde(default)]
|
|
pub bootstrap_admin_email: Option<String>,
|
|
#[serde(default)]
|
|
pub bootstrap_admin_password: Option<String>,
|
|
#[serde(default = "default_allow_user_signup")]
|
|
pub allow_user_signup: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct OidcProviderConfig {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub issuer_url: String,
|
|
pub client_id: String,
|
|
pub client_secret: String,
|
|
#[serde(default)]
|
|
pub scopes: Vec<String>,
|
|
#[serde(default)]
|
|
pub extra_params: HashMap<String, String>,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn load() -> Result<Self, config::ConfigError> {
|
|
let settings = config::Config::builder()
|
|
.add_source(config::File::with_name("config").required(false))
|
|
.add_source(config::Environment::with_prefix("LS_ADMIN").separator("__"))
|
|
.build()?;
|
|
settings.try_deserialize()
|
|
}
|
|
}
|
|
|
|
fn default_bind() -> String {
|
|
"0.0.0.0:8081".to_string()
|
|
}
|
|
|
|
fn default_base_url() -> String {
|
|
"http://localhost:8081".to_string()
|
|
}
|
|
|
|
fn default_max_connections() -> u32 {
|
|
20
|
|
}
|
|
|
|
fn default_session_ttl_minutes() -> i64 {
|
|
720
|
|
}
|
|
|
|
fn default_cookie_secure() -> bool {
|
|
false
|
|
}
|
|
|
|
fn default_allow_user_signup() -> bool {
|
|
false
|
|
}
|