aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
blob: ab40824f7d7f4e7c9afc0510e2044a48f605fb4b (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::collections::HashMap;
use std::io::Read;
use std::path::PathBuf;

use anyhow::Result;
use serde::Deserialize;

#[derive(Deserialize, Debug, Clone)]
pub struct Config {
    pub s3_endpoint: String,
    pub k2v_endpoint: String,
    pub aws_region: String,

    pub login_static: Option<LoginStaticConfig>,
    pub login_ldap: Option<LoginLdapConfig>,
}

#[derive(Deserialize, Debug, Clone)]
pub struct LoginStaticConfig {
    pub default_bucket: Option<String>,
    pub users: HashMap<String, LoginStaticUser>,
}

#[derive(Deserialize, Debug, Clone)]
pub struct LoginStaticUser {
    pub password: String,

    pub aws_access_key_id: String,
    pub aws_secret_access_key: String,
    pub bucket: Option<String>,

    pub user_secret: String,
    #[serde(default)]
    pub alternate_user_secrets: Vec<String>,

    pub master_key: Option<String>,
    pub secret_key: Option<String>,
}

#[derive(Deserialize, Debug, Clone)]
pub struct LoginLdapConfig {
    pub ldap_server: String,

    pub search_dn: String,
    pub username_attr: String,
    pub aws_access_key_id_attr: String,
    pub aws_secret_access_key_attr: String,
    pub user_secret_attr: String,
    pub alternate_user_secrets_attr: Option<String>,

    pub bucket: Option<String>,
    pub bucket_attr: Option<String>,
}

pub fn read_config(config_file: PathBuf) -> Result<Config> {
    let mut file = std::fs::OpenOptions::new()
        .read(true)
        .open(config_file.as_path())?;

    let mut config = String::new();
    file.read_to_string(&mut config)?;

    Ok(toml::from_str(&config)?)
}