//! Configuration loaded from environment variables. use std::path::PathBuf; /// Application configuration. pub struct Config { /// Port to listen on for SSH connections. pub port: u16, /// MNW API base URL (e.g., "http://localhost:3000"). pub api_url: String, /// Service token for authenticating with MNW internal API. pub service_token: String, /// Path to the ed25519 host key file. pub host_key_path: PathBuf, /// Base directory for staging uploaded files. pub staging_dir: PathBuf, /// System user that owns git repositories (for `sudo -u`). pub git_user: String, } impl Config { /// Load configuration from environment variables. pub fn from_env() -> anyhow::Result { let port: u16 = std::env::var("SSH_PORT") .unwrap_or_else(|_| "2222".to_string()) .parse() .map_err(|_| anyhow::anyhow!("Invalid SSH_PORT"))?; let api_url = std::env::var("MNW_API_URL") .unwrap_or_else(|_| "http://localhost:3000".to_string()); let service_token = std::env::var("MNW_SERVICE_TOKEN") .map_err(|_| anyhow::anyhow!("MNW_SERVICE_TOKEN is required"))?; let host_key_path = std::env::var("SSH_HOST_KEY") .unwrap_or_else(|_| "host_ed25519".to_string()) .into(); let staging_dir = std::env::var("STAGING_DIR") .unwrap_or_else(|_| "/var/lib/mnw-cli/staging".to_string()) .into(); let git_user = std::env::var("GIT_SUDO_USER") .unwrap_or_else(|_| "git".to_string()); Ok(Config { port, api_url, service_token, host_key_path, staging_dir, git_user, }) } }