Skip to content

Commit

Permalink
Merge branch 'master' into sm/sm-874
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonhurst committed Nov 17, 2023
2 parents c992350 + a55c2d7 commit 39c2982
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 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 crates/bws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ thiserror = "1.0.40"
tokio = { version = "1.28.2", features = ["rt-multi-thread", "macros"] }
toml = "0.8.0"
uuid = { version = "^1.3.3", features = ["serde"] }
regex = { version = "1.10.2", features=["std", "perf"], default-features=false }

bitwarden = { path = "../bitwarden", version = "0.3.1", features = ["secrets"] }

Expand Down
26 changes: 26 additions & 0 deletions crates/bws/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::Serialize;
pub(crate) enum Output {
JSON,
YAML,
Env,
Table,
TSV,
None,
Expand Down Expand Up @@ -49,6 +50,31 @@ pub(crate) fn serialize_response<T: Serialize + TableSerialize<N>, const N: usiz
let text = serde_yaml::to_string(&data).unwrap();
pretty_print("yaml", &text, color);
}
Output::Env => {
let valid_key_regex = regex::Regex::new("^[a-zA-Z_][a-zA-Z0-9_]*$").unwrap();

let mut commented_out = false;
let mut text: Vec<String> = data
.get_values()
.into_iter()
.map(|row| {
if valid_key_regex.is_match(&row[1]) {
format!("{}=\"{}\"", row[1], row[2])
} else {
commented_out = true;
format!("# {}=\"{}\"", row[1], row[2].replace('\n', "\n# "))
}
})
.collect();

if commented_out {
text.push(String::from(
"\n# one or more secrets have been commented-out due to a problematic key name",
));
}

pretty_print("sh", &format!("{}\n", text.join("\n")), color);
}
Output::Table => {
let mut table = Table::new();
table
Expand Down

0 comments on commit 39c2982

Please sign in to comment.