mirror of
https://github.com/ViViDboarder/bitwarden_rs_ldap.git
synced 2024-11-22 03:06:27 +00:00
Clean up of env config PR
This commit is contained in:
parent
f25278ea3c
commit
5fd947f127
@ -26,7 +26,7 @@ pub fn read_config() -> Config {
|
|||||||
println!("{}", err);
|
println!("{}", err);
|
||||||
match read_config_from_env() {
|
match read_config_from_env() {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(err) => panic!("{}", err)
|
Err(err) => panic!("{}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,27 +36,25 @@ pub fn read_config() -> Config {
|
|||||||
pub fn read_config_from_file() -> Result<Config, String> {
|
pub fn read_config_from_file() -> Result<Config, String> {
|
||||||
let config_path = get_config_path();
|
let config_path = get_config_path();
|
||||||
|
|
||||||
let contents = fs::read_to_string(&config_path).map_err(|_| {
|
let contents = fs::read_to_string(&config_path)
|
||||||
format!("Failed to open config file at {}", config_path)
|
.map_err(|_| format!("Failed to open config file at {}", config_path))?;
|
||||||
})?;
|
let config: Config = toml::from_str(contents.as_str())
|
||||||
let config: Config = toml::from_str(contents.as_str()).map_err(|_| {
|
.map_err(|_| format!("Failed to parse config file at {}", config_path))?;
|
||||||
format!("Failed to parse config file at {}", config_path)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
println!("Reading config from file at {}", config_path);
|
println!("Config read from file at {}", config_path);
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tries to read configuration from environment
|
// Tries to read configuration from environment
|
||||||
pub fn read_config_from_env() -> Result<Config, String> {
|
pub fn read_config_from_env() -> Result<Config, String> {
|
||||||
let config = envy::from_env().map_err(|err| {
|
let config = envy::prefixed("APP_")
|
||||||
format!("error parsing config from env: {}", err)
|
.from_env()
|
||||||
})?;
|
.map_err(|err| format!("Error parsing config from env: {}", err))?;
|
||||||
println!("Reading config from environment");
|
println!("Config read from environment");
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
/// Contains all config values for LDAP syncing
|
/// Contains all config values for LDAP syncing
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
Loading…
Reference in New Issue
Block a user