summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-07-19 22:05:04 -0500
committerNathan Lee <me@nwlee.tech>2026-07-19 22:05:04 -0500
commitc17f8ff8cd1ce96932b1fea9d9a1e80c9e81797d (patch)
treeaa0c7c14892468603a611712b6b6044d7cdeb08e /src/config.rs
Initial commit
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs32
1 files changed, 32 insertions, 0 deletions
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<T: DeserializeOwned>() -> Option<T> {
+ 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