feat: add proper env vars for home and the csv

This commit is contained in:
silver 2023-07-17 01:24:52 +01:00
parent 480860ca26
commit f73a7dfa29
4 changed files with 19 additions and 13 deletions

View file

@ -31,7 +31,7 @@ pub struct Accounts {
}
pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
let database = &config.database;
let database = format!("{}/{}", &config.home, &config.database);
let pool = SqlitePoolOptions::new()
.max_connections(5)
.connect_with(SqliteConnectOptions::from_str(&format!("sqlite://{}", database))?.create_if_missing(true))
@ -91,7 +91,9 @@ pub struct Config {
pub ldap_host: String,
pub ldap_admin: String,
pub ldap_admin_pw: String,
pub home: String,
pub database: String,
pub csv: String,
pub host_port: String,
}
@ -103,7 +105,9 @@ pub fn get_config() -> Config {
ldap_host: "".to_string(),
ldap_admin: "".to_string(),
ldap_admin_pw: "".to_string(),
home: ".".to_string(),
database: "database.db".to_string(),
csv: "wolves.csv".to_string(),
host_port: "127.0.0.1:8087".to_string(),
};
@ -116,9 +120,15 @@ pub fn get_config() -> Config {
if let Ok(x) = env::var("LDAP_ADMIN_PW") {
config.ldap_admin_pw = x.trim().to_string();
}
if let Ok(x) = env::var("HOME") {
config.home = x.trim().to_string();
}
if let Ok(x) = env::var("DATABASE") {
config.database = x.trim().to_string();
}
if let Ok(x) = env::var("CSV") {
config.csv = x.trim().to_string();
}
if let Ok(x) = env::var("HOST_PORT") {
config.host_port = x.trim().to_string();
}