aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-05-19 12:10:48 +0200
committerAlex Auvolat <alex@adnab.me>2022-05-19 12:10:48 +0200
commitc7f767b7d2877cdbbc06893c9cd0fae2c56b96f2 (patch)
tree0fe8afca226ff90dd0fd20985d8216fdb30c8146 /src/config.rs
parent8bd59a8f836d39f89d7e064928949034bec093de (diff)
downloadaerogramme-c7f767b7d2877cdbbc06893c9cd0fae2c56b96f2.tar.gz
aerogramme-c7f767b7d2877cdbbc06893c9cd0fae2c56b96f2.zip
More construction of things
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..47db90d
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,56 @@
+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 s3_region: String,
+ pub k2v_endpoint: String,
+ pub k2v_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 master_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 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)?)
+}