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::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use failure::{err_msg, Error};
|
use failure::err_msg;
|
||||||
use generic_array::GenericArray;
|
use generic_array::GenericArray;
|
||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
use secstr::*;
|
use secstr::*;
|
||||||
|
@ -63,7 +63,6 @@ fn default_path() -> PathBuf {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Opt::from_args();
|
let args = Opt::from_args();
|
||||||
let config: Config = serde_json::from_str(&args.config).expect("Could not parse config.");
|
let config: Config = serde_json::from_str(&args.config).expect("Could not parse config.");
|
||||||
println!("{:?}", config);
|
|
||||||
|
|
||||||
let mut payload = String::new();
|
let mut payload = String::new();
|
||||||
io::stdin()
|
io::stdin()
|
||||||
|
@ -71,6 +70,7 @@ fn main() {
|
||||||
.expect("Could not read from stdin");
|
.expect("Could not read from stdin");
|
||||||
let payload: Payload = serde_json::from_str(&payload)
|
let payload: Payload = serde_json::from_str(&payload)
|
||||||
.expect(&format!("Could not parse stdin into json: '{}'", payload));
|
.expect(&format!("Could not parse stdin into json: '{}'", payload));
|
||||||
|
println!("Read body: '{}'", payload.body);
|
||||||
|
|
||||||
if !config.disable_hmac_verify {
|
if !config.disable_hmac_verify {
|
||||||
let secret = GenericArray::from_iter(config.secret.bytes());
|
let secret = GenericArray::from_iter(config.secret.bytes());
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
use std::io::Write;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Command, Output, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
use failure::{err_msg, Error};
|
use failure::{err_msg, Error};
|
||||||
use futures::{
|
use futures::{
|
||||||
future::{self, FutureResult},
|
future::{self, Either, FutureResult},
|
||||||
|
sink::Sink,
|
||||||
Future,
|
Future,
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{Serializer as JsonSerializer, Value as JsonValue};
|
use serde_json::{Serializer as JsonSerializer, Value as JsonValue};
|
||||||
|
use tokio::io::write_all;
|
||||||
use tokio_process::CommandExt;
|
use tokio_process::CommandExt;
|
||||||
use toml::Value as TomlValue;
|
use toml::Value as TomlValue;
|
||||||
|
|
||||||
|
@ -113,39 +114,72 @@ impl Handler {
|
||||||
.env("DIP_WORKDIR", &temp_path)
|
.env("DIP_WORKDIR", &temp_path)
|
||||||
.arg("--config")
|
.arg("--config")
|
||||||
.arg(config)
|
.arg(config)
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn_async()
|
.spawn_async()
|
||||||
.expect("could not spawn child");
|
.expect("could not spawn child");
|
||||||
match child.stdin() {
|
|
||||||
Some(ref mut stdin) => {
|
let stdin = child.stdin().take().unwrap();
|
||||||
println!("writing input: '{}'", input);
|
|
||||||
write!(stdin, "{}", input);
|
let input = format!("{}", input);
|
||||||
}
|
let result = write_all(stdin, input)
|
||||||
None => (),
|
.and_then(|_| child.wait_with_output())
|
||||||
};
|
.map(|output| {
|
||||||
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 stdout =
|
let stdout =
|
||||||
String::from_utf8(output.stdout).unwrap_or_else(|_| String::new());
|
String::from_utf8(output.stdout).unwrap_or_else(|_| String::new());
|
||||||
let stderr =
|
let stderr =
|
||||||
String::from_utf8(output.stderr).unwrap_or_else(|_| String::new());
|
String::from_utf8(output.stderr).unwrap_or_else(|_| String::new());
|
||||||
println!("stdout: {}, stderr: {}", stdout, stderr);
|
|
||||||
json!({
|
json!({
|
||||||
"stdout": stdout,
|
"stdout": stdout,
|
||||||
"stderr": stderr,
|
"stderr": stderr,
|
||||||
})
|
})
|
||||||
}).map_err(|err| err_msg(format!("could not get output: {}", err)));
|
}).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)
|
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| {
|
// .and_then(move |output| {
|
||||||
// if output.status.success() {
|
// if output.status.success() {
|
||||||
// future::ok(output)
|
// future::ok(output)
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::slice::Iter;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use failure::{err_msg, Error};
|
use failure::{err_msg, Error};
|
||||||
use futures::{future, stream, Future};
|
use futures::{stream, Future};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
use tokio::{self, prelude::*};
|
use tokio::{self, prelude::*};
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use Handler;
|
use Handler;
|
||||||
use HANDLERS;
|
|
||||||
|
|
||||||
pub struct Hook {
|
pub struct Hook {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! # Dip
|
//! # Dip
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
|
@ -55,8 +54,6 @@ lazy_static! {
|
||||||
static ref HOOKS: Arc<Mutex<HashMap<String, Hook>>> = Arc::new(Mutex::new(HashMap::new()));
|
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<()>
|
fn watch<P>(root: P) -> notify::Result<()>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
|
@ -72,7 +69,7 @@ where
|
||||||
// TODO: don't do this
|
// TODO: don't do this
|
||||||
config::load_config(root.as_ref())
|
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::collections::HashMap;
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
use futures::{future, Future, Stream};
|
use futures::{future, Future, Stream};
|
||||||
use hyper::{Body, Error, Request, Response, StatusCode};
|
use hyper::{Body, Error, Request, Response, StatusCode};
|
||||||
|
|
Loading…
Reference in a new issue