diff --git a/src/handler.rs b/src/handler.rs index 96b0acb..4f713b2 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -57,7 +57,7 @@ impl Handler { String::from_utf8(buf).unwrap() }; - match &self.action { + let output = match &self.action { Action::Command(ref cmd) => { // TODO: allow some kind of simple variable replacement let output = Command::new("/bin/bash") @@ -75,6 +75,7 @@ impl Handler { String::from_utf8(output.stderr).unwrap_or_else(|_| String::new()) ))); } + output } Action::Exec(ref path) => { let mut child = Command::new(&path) @@ -104,8 +105,14 @@ impl Handler { String::from_utf8(output.stderr).unwrap_or_else(|_| String::new()) ))); } + output } }; - Ok(json!({})) + let stdout = String::from_utf8(output.stdout).unwrap_or_else(|_| String::new()); + let stderr = String::from_utf8(output.stderr).unwrap_or_else(|_| String::new()); + Ok(json!({ + "stdout": stdout, + "stderr": stderr, + })) } } diff --git a/src/service.rs b/src/service.rs index e72ef37..b5ccd2d 100644 --- a/src/service.rs +++ b/src/service.rs @@ -56,7 +56,16 @@ pub fn dip_service(req: Request) -> Box, Erro .fold(Ok(req_obj), |prev, handler| { prev.and_then(|val| handler.run(val)) }) - .map(|_| (StatusCode::ACCEPTED, "success".to_owned())) + .map(|res| { + ( + StatusCode::ACCEPTED, + format!( + "stdout:\n{}\n\nstderr:\n{}", + res.get("stdout").and_then(|v| v.as_str()).unwrap_or(""), + res.get("stderr").and_then(|v| v.as_str()).unwrap_or(""), + ), + ) + }) .unwrap_or_else(|err| (StatusCode::BAD_REQUEST, format!("Error: {}", err))); Response::builder() .status(code)