use std::path::{Path, PathBuf}; use clap::Parser; use crate::constants::{CLIENTS_LIST_FILE, USERS_LIST_FILE}; /// Basic OIDC provider #[derive(Parser, Debug, Clone)] #[clap(author, version, about, long_about = None)] pub struct AppConfig { /// Listen address #[clap(short, long, env, default_value = "0.0.0.0:8000")] pub listen_address: String, /// Storage path #[clap(short, long, env)] pub storage_path: String, /// App token token #[clap(short, long, env, default_value = "")] pub token_key: String, /// Website origin #[clap(short, long, env, default_value = "http://localhost:8000")] pub website_origin: String, /// Proxy IP, might end with a star "*" #[clap(short, long, env)] pub proxy_ip: Option, } impl AppConfig { pub fn secure_cookie(&self) -> bool { self.website_origin.starts_with("https:") } pub fn storage_path(&self) -> &Path { self.storage_path.as_ref() } pub fn users_file(&self) -> PathBuf { self.storage_path().join(USERS_LIST_FILE) } pub fn clients_file(&self) -> PathBuf { self.storage_path().join(CLIENTS_LIST_FILE) } pub fn full_url(&self, uri: &str) -> String { if uri.starts_with('/') { format!("{}{}", self.website_origin, uri) } else { format!("{}/{}", self.website_origin, uri) } } }