Load defaults from environment variables

This commit is contained in:
Kienan Stewart 2022-10-02 15:37:46 -04:00
parent 33fa4bd266
commit 43e97d4db7
1 changed files with 15 additions and 3 deletions

View File

@ -17,10 +17,22 @@ impl Conf {
Err(_) => "http://localhost:4444".to_string(),
Ok(v) => v,
};
let default_job_dir = match std::env::var("HAUNTER_JOBS_DIR") {
Err(_) => PathBuf::from("jobs.d".to_string()),
Ok(v) => PathBuf::from(v),
};
let default_results_dir = match std::env::var("HAUNTER_RESULTS_DIR") {
Err(_) => PathBuf::from("results.d".to_string()),
Ok(v) => PathBuf::from(v),
};
let default_interval = match std::env::var("HAUNTER_DEFAULT_INTERVAL") {
Err(_) => Duration::new(15*60, 0),
Ok(v) => Duration::new(v.parse::<u64>().unwrap(), 0),
};
return Conf {
job_dir: PathBuf::from_str("jobs.d").unwrap(),
output_dir: PathBuf::from_str("results.d").unwrap(),
check_interval: Duration::new(15*60, 0),
job_dir: default_job_dir,
output_dir: default_results_dir,
check_interval: default_interval,
driver_url: default_driver_url,
};
}