Skip to content

Commit

Permalink
Escape ec2-cargo args (#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Jan 24, 2024
1 parent 4621efa commit 994bcea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
15 changes: 15 additions & 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 ec2-cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ aws-throwaway.workspace = true
tracing-appender.workspace = true
shellfish = { version = "0.9.0", features = ["async"] }
cargo_metadata = "0.18.0"
shell-quote = "0.5.0"
18 changes: 12 additions & 6 deletions ec2-cargo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ fi
println!("All AWS throwaway resources have been deleted")
}

async fn test(state: &mut State, mut args: Vec<String>) -> Result<(), Box<dyn Error>> {
async fn test(state: &mut State, args: Vec<String>) -> Result<(), Box<dyn Error>> {
rsync_push_shotover(state).await;
args.remove(0);
let args = args.join(" ");
let args = process_args(args);
let mut receiver = state
.instance
.ssh()
Expand All @@ -156,10 +155,9 @@ cargo nextest run {} 2>&1
Ok(())
}

async fn windsock(state: &mut State, mut args: Vec<String>) -> Result<(), Box<dyn Error>> {
async fn windsock(state: &mut State, args: Vec<String>) -> Result<(), Box<dyn Error>> {
rsync_push_shotover(state).await;
args.remove(0);
let args = args.join(" ");
let args = process_args(args);
let mut receiver = state
.instance
.ssh()
Expand All @@ -186,6 +184,14 @@ cargo windsock {} 2>&1
Ok(())
}

fn process_args(mut args: Vec<String>) -> String {
args.remove(0);
args.iter()
.map(|x| String::from_utf8(shell_quote::Bash::quote(x)).unwrap())
.collect::<Vec<_>>()
.join(" ")
}

async fn rsync_push_shotover(state: &State) {
let instance = &state.instance;
let project_root_dir = &state.cargo_meta.workspace_root;
Expand Down

0 comments on commit 994bcea

Please sign in to comment.