diff --git a/examples/github.rs b/examples/github.rs index d0c1119..68d0b96 100644 --- a/examples/github.rs +++ b/examples/github.rs @@ -29,10 +29,11 @@ struct Opt { pub config: String, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct Config { secret: String, outdir: PathBuf, + disable_hmac_verify: bool, } #[derive(Serialize, Deserialize)] @@ -44,6 +45,7 @@ struct Payload { fn main() -> Result<(), Error> { let args = Opt::from_args(); let config: Config = serde_json::from_str(&args.config)?; + println!("{:?}", config); let mut payload = String::new(); io::stdin().read_to_string(&mut payload)?; @@ -51,24 +53,26 @@ fn main() -> Result<(), Error> { let payload: Payload = serde_json::from_str(&payload)?; println!("processed payload: {}", payload.body); - let secret = GenericArray::from_iter(config.secret.bytes()); - let mut mac = Hmac::::new(&secret); - mac.input(payload.body.as_bytes()); - let signature = mac.result() - .code() - .into_iter() - .map(|b| format!("{:02x}", b)) - .collect::>() - .join(""); + if !config.disable_hmac_verify { + let secret = GenericArray::from_iter(config.secret.bytes()); + let mut mac = Hmac::::new(&secret); + mac.input(payload.body.as_bytes()); + let signature = mac.result() + .code() + .into_iter() + .map(|b| format!("{:02x}", b)) + .collect::>() + .join(""); - let auth = payload - .headers - .get("x-hub-signature") - .ok_or(err_msg("Missing auth header"))?; + let auth = payload + .headers + .get("x-hub-signature") + .ok_or(err_msg("Missing auth header"))?; - let left = SecStr::from(format!("sha1={}", signature)); - let right = SecStr::from(auth.bytes().collect::>()); - assert!(left == right, "HMAC signature didn't match"); + let left = SecStr::from(format!("sha1={}", signature)); + let right = SecStr::from(auth.bytes().collect::>()); + assert!(left == right, "HMAC signature didn't match"); + } println!("gonna clone it to {:?}", config.outdir); Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 23fb59c..3f312dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,6 +119,7 @@ where } } } + println!("Done loading config."); } fn watch

(root: P) -> notify::Result<()>