2022-07-04 00:01:24 +00:00
|
|
|
use once_cell::sync::OnceCell;
|
2022-05-10 07:17:47 +00:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
2022-07-04 00:01:24 +00:00
|
|
|
pub static CF: OnceCell<Config> = OnceCell::new();
|
|
|
|
|
2022-05-10 07:17:47 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Config {
|
|
|
|
pub bind: SocketAddr,
|
|
|
|
pub path: String,
|
|
|
|
pub user: String,
|
|
|
|
pub pass: String,
|
|
|
|
pub crt: Option<String>,
|
|
|
|
pub key: Option<String>,
|
|
|
|
}
|
|
|
|
|
2022-07-04 00:01:24 +00:00
|
|
|
pub fn init(matches: &clap::ArgMatches) {
|
2022-05-10 07:17:47 +00:00
|
|
|
// Parse the server binding address
|
|
|
|
let bind = matches
|
|
|
|
.value_of("bind")
|
|
|
|
.unwrap()
|
|
|
|
.parse::<SocketAddr>()
|
|
|
|
.expect("Unable to parse socket address");
|
|
|
|
// Parse the database endpoint path
|
|
|
|
let path = matches.value_of("path").unwrap().to_owned();
|
|
|
|
// Parse the root username for authentication
|
|
|
|
let user = matches.value_of("user").unwrap().to_owned();
|
|
|
|
// Parse the root password for authentication
|
|
|
|
let pass = matches.value_of("pass").unwrap().to_owned();
|
|
|
|
// Parse any TLS server security options
|
|
|
|
let crt = matches.value_of("web-crt").map(|v| v.to_owned());
|
|
|
|
let key = matches.value_of("web-key").map(|v| v.to_owned());
|
2022-07-04 00:01:24 +00:00
|
|
|
// Store the new config object
|
|
|
|
let _ = CF.set(Config {
|
2022-05-10 07:17:47 +00:00
|
|
|
bind,
|
|
|
|
path,
|
|
|
|
user,
|
|
|
|
pass,
|
|
|
|
crt,
|
|
|
|
key,
|
2022-07-04 00:01:24 +00:00
|
|
|
});
|
2022-05-10 07:17:47 +00:00
|
|
|
}
|