← history for src/config.rs
35bda350src/config.rs43 lines⬡ raw↓ download
 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
33
34
35
36
37
38
39
40
41
42
43
/**
 * Config Vault - cfgvault
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2026
 */

use serde::Deserialize;
use std::fs;
use clap::Parser;

#[derive(Debug, Deserialize)]
#[serde()]
pub struct AppConfig {
    pub(crate) endpoint: String,
    pub(crate) keystore: String,
    pub(crate) secretkey: String,

    pub(crate) server_tls_certificate: Option<String>,
    pub(crate) server_tls_key: Option<String>,
    pub(crate) server_ca: Option<String>,
    pub(crate) allowlist: Option<Vec<String>>,
    pub(crate) validate_client_cert: Option<bool>,
}

pub fn read_config(filename: String) -> AppConfig {
    let data = fs::read_to_string(filename).expect("Could not read config file");

    let json: serde_json::Value = serde_json::from_str(&data).expect("JSON formatting issues");

    let config: AppConfig =
        serde_json::from_str(&json.to_string()).expect("JSON formatting issues");
    config
}

#[derive(Parser)]
pub(crate) struct Cli {
    #[arg(long, required = false, default_value = "")]
    pub config_file: String,
}