From 43e97d4db7f0082986018af05d683b762daeb38a Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Sun, 2 Oct 2022 15:37:46 -0400 Subject: [PATCH] Load defaults from environment variables --- src/conf.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/conf.rs b/src/conf.rs index 1127006..ab958a8 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -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::().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, }; }