2022-12-19 20:20:13 +00:00
|
|
|
use serde::Deserialize;
|
|
|
|
use sigh::{PrivateKey, PublicKey, Key};
|
|
|
|
|
2023-10-12 20:09:09 +00:00
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
pub struct RedisConfig {
|
|
|
|
pub connection: String,
|
2023-10-12 20:09:43 +00:00
|
|
|
pub password_file: String,
|
2023-10-12 20:09:09 +00:00
|
|
|
pub in_topic: String,
|
|
|
|
}
|
|
|
|
|
2023-10-12 17:04:05 +00:00
|
|
|
#[derive(Clone, Deserialize)]
|
2022-12-19 20:20:13 +00:00
|
|
|
pub struct Config {
|
2023-01-11 17:45:45 +00:00
|
|
|
pub streams: Vec<String>,
|
2022-12-19 20:20:13 +00:00
|
|
|
pub db: String,
|
|
|
|
pub hostname: String,
|
|
|
|
pub listen_port: u16,
|
2023-10-12 20:09:09 +00:00
|
|
|
pub redis: Option<RedisConfig>,
|
2022-12-19 20:20:13 +00:00
|
|
|
priv_key_file: String,
|
|
|
|
pub_key_file: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
pub fn load(config_file: &str) -> Config {
|
|
|
|
let data = std::fs::read_to_string(config_file)
|
|
|
|
.expect("read config");
|
|
|
|
serde_yaml::from_str(&data)
|
|
|
|
.expect("parse config")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn priv_key(&self) -> PrivateKey {
|
|
|
|
let data = std::fs::read_to_string(&self.priv_key_file)
|
|
|
|
.expect("read priv_key_file");
|
|
|
|
PrivateKey::from_pem(data.as_bytes())
|
|
|
|
.expect("priv_key")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pub_key(&self) -> PublicKey {
|
|
|
|
let data = std::fs::read_to_string(&self.pub_key_file)
|
|
|
|
.expect("read pub_key_file");
|
|
|
|
PublicKey::from_pem(data.as_bytes())
|
|
|
|
.expect("pub_key")
|
|
|
|
}
|
|
|
|
}
|