Skip to content

Commit

Permalink
Fix config envvar prefix, improve print logging
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Detjens <[email protected]>
  • Loading branch information
detjensrobert committed Nov 8, 2024
1 parent 99ee99a commit 3d45a9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/configparser/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{Context, Result};
use fully_pub::fully_pub;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use simplelog::*;
use std::collections::HashMap as Map;
Expand All @@ -11,8 +12,25 @@ use figment::Figment;
pub fn parse() -> Result<RcdsConfig> {
debug!("trying to parse rcds.yaml");

let env_overrides = Env::prefixed("BEAVER_").split("_");
trace!("overriding config with envvar values: {:?}", env_overrides);
let env_overrides = Env::prefixed("BEAVERCDS_").split("_").map(|var| {
// Using "_" as the split character works for almost all of our keys.
// but some of the profile settings keys have underscores as part of the
// key. This handles those few keys by undoing the s/_/./ that the
// Figment split() did.
var.to_string()
.to_lowercase()
.replace("frontend.", "frontend_")
.replace("challenges.", "challenges_")
.into()
});
trace!(
"overriding config with envvar values: {}",
env_overrides
.iter()
.map(|(key, val)| format!("{}='{}'", key.string, val))
.join(", ")
);

let config = Figment::from(Yaml::file("rcds.yaml"))
.merge(env_overrides)
.extract()
Expand Down
2 changes: 1 addition & 1 deletion tests/repo/rcds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ flag_regex: dam{[a-zA-Z...]}

registry:
domain: localhost:5000/damctf
# then environment variables e.g. REG_USER/REG_PASS
# or environment vars e.g. BEAVERCDS_REGISTRY_BUILD_USER / etc
build:
user: admin
pass: notrealcreds
Expand Down

0 comments on commit 3d45a9a

Please sign in to comment.