kanidm/src/lib/config.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

2019-07-27 08:54:31 +02:00
use rand::prelude::*;
use std::path::PathBuf;
2018-11-26 07:13:22 +01:00
#[derive(Serialize, Deserialize, Debug)]
pub struct Configuration {
pub address: String,
pub domain: String,
2018-11-26 07:13:22 +01:00
pub threads: usize,
2019-07-27 08:54:31 +02:00
// db type later
2018-11-26 07:13:22 +01:00
pub db_path: String,
pub maximum_request: usize,
pub secure_cookies: bool,
2019-07-27 08:54:31 +02:00
pub cookie_key: [u8; 32],
2018-11-26 07:13:22 +01:00
}
impl Configuration {
pub fn new() -> Self {
2019-07-27 08:54:31 +02:00
let mut c = Configuration {
2018-11-26 07:13:22 +01:00
address: String::from("127.0.0.1:8080"),
2019-07-29 09:09:09 +02:00
domain: String::from("localhost"),
2018-11-26 07:13:22 +01:00
threads: 8,
db_path: String::from(""),
maximum_request: 262144, // 256k
// log type
// log path
2019-07-27 08:54:31 +02:00
// TODO #63: default true in prd
secure_cookies: false,
2019-07-27 08:54:31 +02:00
cookie_key: [0; 32],
};
let mut rng = StdRng::from_entropy();
rng.fill(&mut c.cookie_key);
c
2018-11-26 07:13:22 +01:00
}
pub fn update_db_path(&mut self, p: &PathBuf) {
match p.to_str() {
Some(p) => self.db_path = p.to_string(),
None => {
error!("Invalid DB path supplied");
std::process::exit(1);
}
}
}
2018-11-26 07:13:22 +01:00
}