Don't calculate sig for payloads that don't need it
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
a9a16c30bf
commit
edd0e0074a
1 changed files with 13 additions and 9 deletions
22
src/web.rs
22
src/web.rs
|
@ -56,10 +56,22 @@ async fn hooks_inner(req: Request<Incoming>, secret: &str) -> Result<Hook, Error
|
|||
return Err(Error::InvalidContentType);
|
||||
}
|
||||
|
||||
// Get payload and generate hmac signature
|
||||
// Get payload
|
||||
let mut payload: Vec<u8> = vec![];
|
||||
let whole_body = req.collect().await?.aggregate();
|
||||
whole_body.reader().read_to_end(&mut payload)?;
|
||||
|
||||
if let Some(val) = headers.get("X-Gitlab-Token") {
|
||||
debug!("Found Gitlab payload");
|
||||
if secret != val {
|
||||
return Err(Error::InvalidSecret);
|
||||
}
|
||||
|
||||
let hook: GitlabHook = serde_json::from_slice(&payload[..])?;
|
||||
return Ok(Hook::Gitlab(hook));
|
||||
}
|
||||
|
||||
// Generate hmac signature
|
||||
let mut mac = HmacSha256::new_from_slice(secret.as_bytes())?;
|
||||
mac.update(&payload);
|
||||
let result = mac.finalize().into_bytes();
|
||||
|
@ -76,14 +88,6 @@ async fn hooks_inner(req: Request<Incoming>, secret: &str) -> Result<Hook, Error
|
|||
let hook: ForgejoHook = serde_json::from_slice(&payload[..])?;
|
||||
return Ok(Hook::Forgejo(hook));
|
||||
debug!("Found Forgejo payload.");
|
||||
} else if let Some(val) = headers.get("X-Gitlab-Token") {
|
||||
debug!("Found Gitlab payload");
|
||||
if secret != val {
|
||||
return Err(Error::InvalidSecret);
|
||||
}
|
||||
|
||||
let hook: GitlabHook = serde_json::from_slice(&payload[..])?;
|
||||
return Ok(Hook::Gitlab(hook));
|
||||
}
|
||||
|
||||
// No match found for the payload
|
||||
|
|
Loading…
Reference in a new issue