works i guess
This commit is contained in:
parent
7c1360d9b9
commit
e57f8f1796
3 changed files with 25 additions and 50 deletions
|
@ -70,7 +70,6 @@ fn main() {
|
|||
.expect("Could not read from stdin");
|
||||
let payload: Payload = serde_json::from_str(&payload)
|
||||
.expect(&format!("Could not parse stdin into json: '{}'", payload));
|
||||
println!("Read body: '{}'", payload.body);
|
||||
|
||||
if !config.disable_hmac_verify {
|
||||
let secret = GenericArray::from_iter(config.secret.bytes());
|
||||
|
@ -92,7 +91,12 @@ fn main() {
|
|||
|
||||
let left = SecStr::from(format!("sha1={}", signature));
|
||||
let right = SecStr::from(auth.bytes().collect::<Vec<_>>());
|
||||
assert!(left == right, "HMAC signature didn't match",);
|
||||
assert!(
|
||||
left == right,
|
||||
"HMAC signature didn't match: {} vs. {}",
|
||||
signature,
|
||||
auth
|
||||
);
|
||||
}
|
||||
|
||||
let payload: GithubPayload =
|
||||
|
|
|
@ -3,8 +3,7 @@ use std::process::{Command, Stdio};
|
|||
|
||||
use failure::{err_msg, Error};
|
||||
use futures::{
|
||||
future::{self, Either, FutureResult},
|
||||
sink::Sink,
|
||||
future::{self, Either},
|
||||
Future,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
@ -69,7 +68,6 @@ impl Handler {
|
|||
temp_path: PathBuf,
|
||||
input: JsonValue,
|
||||
) -> impl Future<Item = (PathBuf, JsonValue), Error = Error> {
|
||||
println!("Running: {:?} :: {:?}", config, action);
|
||||
let config = {
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
{
|
||||
|
@ -125,16 +123,24 @@ impl Handler {
|
|||
let input = format!("{}", input);
|
||||
let result = write_all(stdin, input)
|
||||
.and_then(|_| child.wait_with_output())
|
||||
.map(|output| {
|
||||
.map_err(|err| err_msg(format!("error: {}", err)))
|
||||
.and_then(|output| {
|
||||
let stdout =
|
||||
String::from_utf8(output.stdout).unwrap_or_else(|_| String::new());
|
||||
let stderr =
|
||||
String::from_utf8(output.stderr).unwrap_or_else(|_| String::new());
|
||||
json!({
|
||||
if output.status.success() {
|
||||
Either::A(future::ok(json!({
|
||||
"stdout": stdout,
|
||||
"stderr": stderr,
|
||||
})
|
||||
}).map_err(|err| err_msg(format!("error: {}", err)));
|
||||
})))
|
||||
} else {
|
||||
Either::B(future::err(err_msg(format!(
|
||||
"Failed, stdout: '{}', stderr: '{}'",
|
||||
stdout, stderr
|
||||
))))
|
||||
}
|
||||
});
|
||||
|
||||
Box::new(result)
|
||||
}
|
||||
|
|
43
src/hook.rs
43
src/hook.rs
|
@ -58,47 +58,12 @@ impl Hook {
|
|||
.collect::<Vec<_>>();
|
||||
let st = stream::iter_ok::<_, Error>(handlers.into_iter())
|
||||
.fold((temp_path, req), |(path, prev), (config, action)| {
|
||||
println!("executing in {:?}", &path);
|
||||
Handler::run(config, action, path, prev)
|
||||
}).map(|_| ())
|
||||
.map_err(|_: Error| ());
|
||||
.map_err(|err: Error| {
|
||||
println!("Error from stream: {}", err);
|
||||
});
|
||||
tokio::executor::spawn(st);
|
||||
// let it = stream::iter_ok::<_, Error>(handlers.iter());
|
||||
// let s = it.fold((temp_path, req), move |(path, prev), handler| {
|
||||
// let result = handler.run(path.clone(), prev.clone());
|
||||
// result
|
||||
// }).map(|_|()).map_err(|_| ());
|
||||
// tokio::executor::spawn(s);
|
||||
Ok("success".to_owned())
|
||||
// let s = stream::iter_ok(self.handlers.iter()).fold((temp_path, req), move |prev, handler| {
|
||||
// let (path, prev) = prev;
|
||||
// handler.run(path, prev)
|
||||
// });
|
||||
// .fold(future::ok(req), |prev, handler| {
|
||||
// prev.and_then(|val| handler.run(temp_path, val))
|
||||
// });
|
||||
// let s = s.map(|_| ()).map_err(|_: Error| ());
|
||||
// tokio::executor::spawn(s);
|
||||
// Ok("success".to_owned())
|
||||
/*
|
||||
Ok(self.iter()
|
||||
.fold(Ok(req), |prev, handler| {
|
||||
prev.and_then(|val| {
|
||||
println!("Running {}...", handler.config());
|
||||
let result = handler.run(&temp_path, val);
|
||||
result
|
||||
})
|
||||
})
|
||||
.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))))
|
||||
*/ }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue