Skip to content

Commit

Permalink
osrdyne: allow specifying an overriding configuration using CLI args
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Valais <[email protected]>
  • Loading branch information
leovalais committed Sep 9, 2024
1 parent 23edcec commit e77107d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 10 additions & 7 deletions osrdyne/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Duration;
use std::{path::PathBuf, time::Duration};

use crate::drivers::{
docker::DockerDriverOptions, kubernetes::KubernetesDriverOptions,
Expand Down Expand Up @@ -53,10 +53,13 @@ impl Default for OsrdyneConfig {
}
}

pub fn parse_config() -> Result<OsrdyneConfig, figment::Error> {
Figment::from(Serialized::defaults(OsrdyneConfig::default()))
.merge(Yaml::file("osrdyne.yml"))
// We use `__` as a separator for nested keys
.merge(Env::prefixed("OSRDYNE__").split("__"))
.extract()
pub fn parse_config(file: Option<PathBuf>) -> Result<OsrdyneConfig, figment::Error> {
let mut fig = Figment::from(Serialized::defaults(OsrdyneConfig::default()))
.merge(Yaml::file("osrdyne.yml"));
if let Some(file) = file {
log::info!("Using configuration file: {}", file.display());
fig = fig.merge(Yaml::file(file));
}
// We use `__` as a separator for nested keys
fig.merge(Env::prefixed("OSRDYNE__").split("__")).extract()
}
8 changes: 7 additions & 1 deletion osrdyne/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use lapin::ConnectionProperties;
use log::error;
use log::info;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use tokio::select;
Expand Down Expand Up @@ -62,7 +63,12 @@ fn request_queues_policy(config: &OsrdyneConfig) -> BTreeMap<String, ArgumentVal
async fn main() -> Result<(), anyhow::Error> {
env_logger::init();

let config = parse_config()?;
let file = {
let mut args = std::env::args();
args.nth(1).map(PathBuf::from)
};

let config = parse_config(file)?;
log::info!("config: {:?}", &config);
let pool = Arc::new(Pool::new(
config.pool_id.clone(),
Expand Down

0 comments on commit e77107d

Please sign in to comment.