blob: 85dbbe280e070d896bf14cb9de9c3765ad7104bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
}
|