Skip to content

Commit

Permalink
update identifier to {{*}}
Browse files Browse the repository at this point in the history
  • Loading branch information
pranshi06 committed Oct 2, 2024
1 parent 79199d6 commit e19124a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ insta = "1"
jsonschema = "0.18.0"
log = "0.4.22"
prometheus = "0.13"
regex = "1.11.0"
reqwest = "0.11"
schemars = "0.8"
serde = "1"
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tracing-subscriber = "0.3.18"
tracing = "0.1.40"
log = "0.4.22"
env_logger = "0.11.5"
regex = { workspace = true }

[build-dependencies]
build-data = { workspace = true }
Expand Down
14 changes: 10 additions & 4 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! then done, making it easier to test this crate deterministically.
use std::path::PathBuf;
use regex::Regex;

use std::collections::BTreeMap;
use anyhow::Ok;
Expand Down Expand Up @@ -227,14 +228,19 @@ async fn update(context: Context<impl Environment>, calcite_ref_singleton: &Calc
// for each env var present in the map from the metadata file, replace the placeholder in the model file
for (key, value) in &env_var_map {
// include the identifiers with the env var to avoid replacing the wrong value
let env_var_identifier = format!("<$>{}", key);
let env_var_identifier = format!("{{{{{}}}}}", key);
model_file_value = model_file_value.replace(&env_var_identifier, value);
}

// Create a regex pattern to match `{{*}}`
let re = Regex::new(r"\{\{.*?\}\}").unwrap();

// check if there is any placeholder left in the model file, which means
// there is an extra env var which is not allowed i the metadata or there is
// there is an extra env var which is not allowed in the metadata or there is
// a mismatch between the two files.
let final_model_string = if model_file_value.contains("<$>") {
Err(anyhow::Error::msg("Some environment variables are not replaced"))
let final_model_string = if re.is_match(&model_file_value) {
Err(anyhow::Error::msg(
"Some environment variable placeholders are not updated in the model file"))
} else {
Ok(model_file_value)
}?;
Expand Down

0 comments on commit e19124a

Please sign in to comment.