From c17f8ff8cd1ce96932b1fea9d9a1e80c9e81797d Mon Sep 17 00:00:00 2001 From: Nathan Lee Date: Sun, 19 Jul 2026 22:05:04 -0500 Subject: Initial commit --- src/config.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/config.rs (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..85dbbe2 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,32 @@ +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 +} \ No newline at end of file -- cgit v1.2.3