Fix execution of scripts
For better script and argument support `run_script` is used instead of `process::Command`.
This commit is contained in:
parent
6af7d29833
commit
17778cf8b4
3 changed files with 42 additions and 34 deletions
45
src/main.rs
45
src/main.rs
|
@ -22,6 +22,7 @@ use rocket::{
|
|||
Outcome::{Failure, Success},
|
||||
Request, Response, State,
|
||||
};
|
||||
use run_script::ScriptOptions;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::Sha256;
|
||||
use thiserror::Error;
|
||||
|
@ -31,8 +32,6 @@ use std::{
|
|||
fs::File,
|
||||
io::{BufReader, Read},
|
||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||
process::Command,
|
||||
str::from_utf8,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
@ -225,28 +224,18 @@ fn filter_match(
|
|||
|
||||
let regex = Regex::new(&filter.regex)?;
|
||||
|
||||
let parameters = hook.command.clone();
|
||||
let parameters = get_parameter(¶meters)?;
|
||||
|
||||
for parameter in parameters {
|
||||
for parameter in get_parameter(&hook.command)? {
|
||||
let parameter = parameter.trim();
|
||||
trace!("Replacing parameter `{}`", parameter);
|
||||
trace!("Pointer parameter `{:?}`", data.pointer(parameter));
|
||||
|
||||
if let Some(json_value) = data.pointer(parameter) {
|
||||
*data.pointer_mut(parameter).unwrap() = match json_value {
|
||||
serde_json::Value::String(string) => {
|
||||
serde_json::Value::String(string.to_string())
|
||||
}
|
||||
serde_json::Value::Number(number) => {
|
||||
serde_json::Value::String(number.to_string())
|
||||
}
|
||||
serde_json::Value::String(string) => serde_json::Value::String(string.to_string()),
|
||||
serde_json::Value::Number(number) => serde_json::Value::String(number.to_string()),
|
||||
x => {
|
||||
error!("Could not get string from: {:?}", x);
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trace!("Ignoring parameter `{}`", parameter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,26 +364,14 @@ fn receive_hook<'a>(address: SocketAddr, hooks: Hooks) -> Result<Response<'a>> {
|
|||
for hook in hooks.0 {
|
||||
info!("Execute `{}` from hook `{}`", &hook.1, &hook.0);
|
||||
|
||||
let command = hook.1.split(' ').collect::<Vec<&str>>();
|
||||
match Command::new(&command[0]).args(&command[1..]).output() {
|
||||
Ok(executed) => {
|
||||
info!(
|
||||
"Command `{}` exited with return code: {}",
|
||||
&command[0], &executed.status
|
||||
);
|
||||
trace!(
|
||||
"Output of command `{}` on stdout: {:?}",
|
||||
&command[0],
|
||||
from_utf8(&executed.stdout)?
|
||||
);
|
||||
debug!(
|
||||
"Output of command `{}` on stderr: {:?}",
|
||||
&command[0],
|
||||
from_utf8(&executed.stderr)?
|
||||
);
|
||||
match run_script::run(&hook.1, &vec![], &ScriptOptions::new()) {
|
||||
Ok((status, stdout, stderr)) => {
|
||||
info!("Command `{}` exited with return code: {}", &hook.1, status);
|
||||
trace!("Output of command `{}` on stdout: {:?}", &hook.1, &stdout);
|
||||
debug!("Output of command `{}` on stderr: {:?}", &hook.1, &stderr);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Execution of `{}` failed: {}", command[0], e);
|
||||
error!("Execution of `{}` failed: {}", &hook.1, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue