it works i guess?
This commit is contained in:
parent
642ff66161
commit
34eae4569f
5 changed files with 64 additions and 37 deletions
|
@ -17,7 +17,7 @@ use std::iter::FromIterator;
|
|||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use failure::{err_msg, Error};
|
||||
use failure::err_msg;
|
||||
use generic_array::GenericArray;
|
||||
use hmac::{Hmac, Mac};
|
||||
use secstr::*;
|
||||
|
@ -63,7 +63,6 @@ fn default_path() -> PathBuf {
|
|||
fn main() {
|
||||
let args = Opt::from_args();
|
||||
let config: Config = serde_json::from_str(&args.config).expect("Could not parse config.");
|
||||
println!("{:?}", config);
|
||||
|
||||
let mut payload = String::new();
|
||||
io::stdin()
|
||||
|
@ -71,6 +70,7 @@ 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());
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, Output, Stdio};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use failure::{err_msg, Error};
|
||||
use futures::{
|
||||
future::{self, FutureResult},
|
||||
future::{self, Either, FutureResult},
|
||||
sink::Sink,
|
||||
Future,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use serde_json::{Serializer as JsonSerializer, Value as JsonValue};
|
||||
use tokio::io::write_all;
|
||||
use tokio_process::CommandExt;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
|
@ -113,39 +114,72 @@ impl Handler {
|
|||
.env("DIP_WORKDIR", &temp_path)
|
||||
.arg("--config")
|
||||
.arg(config)
|
||||
.stdin(Stdio::piped())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn_async()
|
||||
.expect("could not spawn child");
|
||||
match child.stdin() {
|
||||
Some(ref mut stdin) => {
|
||||
println!("writing input: '{}'", input);
|
||||
write!(stdin, "{}", input);
|
||||
}
|
||||
None => (),
|
||||
};
|
||||
let result = child
|
||||
.wait_with_output()
|
||||
.and_then(|output| {
|
||||
if output.status.success() {
|
||||
future::ok(output)
|
||||
} else {
|
||||
// TODO: change this
|
||||
future::ok(output)
|
||||
}
|
||||
}).map(|output| {
|
||||
|
||||
let stdin = child.stdin().take().unwrap();
|
||||
|
||||
let input = format!("{}", input);
|
||||
let result = write_all(stdin, input)
|
||||
.and_then(|_| child.wait_with_output())
|
||||
.map(|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());
|
||||
println!("stdout: {}, stderr: {}", stdout, stderr);
|
||||
json!({
|
||||
"stdout": stdout,
|
||||
"stderr": stderr,
|
||||
})
|
||||
}).map_err(|err| err_msg(format!("could not get output: {}", err)));
|
||||
"stdout": stdout,
|
||||
"stderr": stderr,
|
||||
})
|
||||
}).map_err(|err| err_msg(format!("error: {}", err)));
|
||||
|
||||
// let _result: Either<_, FutureResult<(), Error>> = {
|
||||
// match child.stdin() {
|
||||
// Some(ref mut stdin) => Either::A(write_all(stdin, input.as_bytes())),
|
||||
// None => Either::B(future::err(err_msg("rip"))),
|
||||
// }
|
||||
// };
|
||||
Box::new(result)
|
||||
|
||||
// let input_s = format!("{}", input);
|
||||
// let result: Box<Future<Item = (), Error = Error> + Send> = {
|
||||
// let rf = child.clone().lock().unwrap();
|
||||
// match rf.stdin() {
|
||||
// Some(ref mut stdin) => Box::new(
|
||||
// write_all(stdin, input_s.as_bytes())
|
||||
// .map(|_| ())
|
||||
// .map_err(|err| err_msg(format!("error: {}", err))),
|
||||
// ),
|
||||
// None => Box::new(future::err(err_msg("Failed to acquire child stdin"))),
|
||||
// }
|
||||
// };
|
||||
// {
|
||||
// let rf = child.clone().lock().unwrap();
|
||||
// let result = rf
|
||||
// .wait_with_output()
|
||||
// .and_then(|output| {
|
||||
// if output.status.success() {
|
||||
// future::ok(output)
|
||||
// } else {
|
||||
// // TODO: change this
|
||||
// future::ok(output)
|
||||
// }
|
||||
// }).map(|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());
|
||||
// println!("stdout: {}, stderr: {}", stdout, stderr);
|
||||
// json!({
|
||||
// "stdout": stdout,
|
||||
// "stderr": stderr,
|
||||
// })
|
||||
// }).map_err(|err| err_msg(format!("could not get output: {}", err)));
|
||||
// });
|
||||
|
||||
// .and_then(move |output| {
|
||||
// if output.status.success() {
|
||||
// future::ok(output)
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::slice::Iter;
|
||||
use std::sync::Arc;
|
||||
|
||||
use failure::{err_msg, Error};
|
||||
use futures::{future, stream, Future};
|
||||
use futures::{stream, Future};
|
||||
use serde_json::Value as JsonValue;
|
||||
use tokio::{self, prelude::*};
|
||||
use toml::Value;
|
||||
|
||||
use Handler;
|
||||
use HANDLERS;
|
||||
|
||||
pub struct Hook {
|
||||
name: String,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! # Dip
|
||||
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
extern crate futures;
|
||||
extern crate hyper;
|
||||
|
@ -55,8 +54,6 @@ lazy_static! {
|
|||
static ref HOOKS: Arc<Mutex<HashMap<String, Hook>>> = Arc::new(Mutex::new(HashMap::new()));
|
||||
}
|
||||
|
||||
// const NOTFOUND: &str = "<html> <head> <style> * { font-family: sans-serif; } body { padding: 20px 60px; } </style> </head> <body> <h1>Looks like you took a wrong turn!</h1> <p>There's nothing to see here.</p> </body> </html>";
|
||||
|
||||
fn watch<P>(root: P) -> notify::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
|
@ -72,7 +69,7 @@ where
|
|||
// TODO: don't do this
|
||||
config::load_config(root.as_ref())
|
||||
}
|
||||
Err(e) => println!("watch error: {:?}", e),
|
||||
Err(e) => eprintln!("watch error: {:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::thread;
|
||||
|
||||
use futures::{future, Future, Stream};
|
||||
use hyper::{Body, Error, Request, Response, StatusCode};
|
||||
|
|
Loading…
Reference in a new issue