use std::fs; use serde::{Deserialize, Serialize}; use serde::de::DeserializeOwned; const CONFIG_LOCATIONS: [&str; 3] = [ "config.json", "/etc/kps/config.json", "~/.config/kps/config.json", ]; #[derive(Serialize, Deserialize, Debug)] pub struct ClientConfig { pub private_key: String, pub db_path: String, pub server_url: String, } #[derive(Serialize, Deserialize, Debug)] pub struct ServerConfig { pub public_key: String, pub vaults_directory: String } pub fn read_config() -> Option { for file in CONFIG_LOCATIONS { let data = fs::read_to_string(file); if let Ok(data) = data { return Some(serde_json::from_str(data.as_str()).expect("Malformed config file")); } } None }