Fix clippy warnings
This commit is contained in:
parent
dd78835f17
commit
5d20366e5d
1 changed files with 11 additions and 11 deletions
22
src/main.rs
22
src/main.rs
|
@ -204,7 +204,7 @@ impl Hook {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
replace_parameters(&self.command, &request.headers(), data)
|
replace_parameters(&self.command, request.headers(), data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ impl Hooks {
|
||||||
|
|
||||||
let hooks = config.hooks.iter().filter(|(name, hook)| {
|
let hooks = config.hooks.iter().filter(|(name, hook)| {
|
||||||
if let Some(ip) = &hook.ip_filter {
|
if let Some(ip) = &hook.ip_filter {
|
||||||
return accept_ip(&name, &client_ip, &ip);
|
accept_ip(name, client_ip, ip)
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
"Allow hook `{}` from {}, no IP filter was configured",
|
"Allow hook `{}` from {}, no IP filter was configured",
|
||||||
|
@ -250,7 +250,7 @@ impl Hooks {
|
||||||
let secrets = hook
|
let secrets = hook
|
||||||
.secrets
|
.secrets
|
||||||
.iter()
|
.iter()
|
||||||
.map(|secret| validate_request(&secret, &signature, &buffer));
|
.map(|secret| validate_request(secret, signature, &buffer));
|
||||||
|
|
||||||
for secret in secrets {
|
for secret in secrets {
|
||||||
match secret {
|
match secret {
|
||||||
|
@ -263,7 +263,7 @@ impl Hooks {
|
||||||
serde_json::from_slice(&buffer).map_err(WebhookeyError::Serde)?;
|
serde_json::from_slice(&buffer).map_err(WebhookeyError::Serde)?;
|
||||||
|
|
||||||
match hook.filter.evaluate(request, &data) {
|
match hook.filter.evaluate(request, &data) {
|
||||||
Ok(true) => match hook.get_command(&hook_name, &request, &mut data) {
|
Ok(true) => match hook.get_command(hook_name, request, &mut data) {
|
||||||
Ok(command) => {
|
Ok(command) => {
|
||||||
info!("Filter for `{}` matched", &hook_name);
|
info!("Filter for `{}` matched", &hook_name);
|
||||||
result.insert(hook_name.to_string(), command);
|
result.insert(hook_name.to_string(), command);
|
||||||
|
@ -294,7 +294,7 @@ impl FromDataSimple for Hooks {
|
||||||
type Error = WebhookeyError;
|
type Error = WebhookeyError;
|
||||||
|
|
||||||
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, Self::Error> {
|
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, Self::Error> {
|
||||||
match Hooks::get_commands(&request, data) {
|
match Hooks::get_commands(request, data) {
|
||||||
Ok(hooks) => {
|
Ok(hooks) => {
|
||||||
if hooks.inner.is_empty() {
|
if hooks.inner.is_empty() {
|
||||||
let client_ip = &request
|
let client_ip = &request
|
||||||
|
@ -336,9 +336,9 @@ fn accept_ip(hook_name: &str, client_ip: &IpAddr, ip: &IpFilter) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_request(secret: &str, signature: &str, data: &[u8]) -> Result<()> {
|
fn validate_request(secret: &str, signature: &str, data: &[u8]) -> Result<()> {
|
||||||
let mut mac = Hmac::<Sha256>::new_varkey(&secret.as_bytes())
|
let mut mac = Hmac::<Sha256>::new_varkey(secret.as_bytes())
|
||||||
.map_err(|e| anyhow!("Could not create hasher with secret: {}", e))?;
|
.map_err(|e| anyhow!("Could not create hasher with secret: {}", e))?;
|
||||||
mac.update(&data);
|
mac.update(data);
|
||||||
let raw_signature = hex::decode(signature.as_bytes())?;
|
let raw_signature = hex::decode(signature.as_bytes())?;
|
||||||
mac.verify(&raw_signature).map_err(|e| anyhow!("{}", e))
|
mac.verify(&raw_signature).map_err(|e| anyhow!("{}", e))
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,7 @@ fn get_parameter(input: &str) -> Result<Vec<&str>> {
|
||||||
let parse: IResult<&str, Vec<&str>> = many0(alt((
|
let parse: IResult<&str, Vec<&str>> = many0(alt((
|
||||||
delimited(tag("{{"), take_until("}}"), tag("}}")),
|
delimited(tag("{{"), take_until("}}"), tag("}}")),
|
||||||
take_until("{{"),
|
take_until("{{"),
|
||||||
)))(&input);
|
)))(input);
|
||||||
|
|
||||||
let (_last, result) = parse
|
let (_last, result) = parse
|
||||||
.finish()
|
.finish()
|
||||||
|
@ -389,7 +389,7 @@ fn replace_parameters(
|
||||||
|
|
||||||
match expr.get(0) {
|
match expr.get(0) {
|
||||||
Some(&"header") => get_header_field(headers, &expr),
|
Some(&"header") => get_header_field(headers, &expr),
|
||||||
Some(pointer) => get_value_from_pointer(data, &pointer),
|
Some(pointer) => get_value_from_pointer(data, pointer),
|
||||||
None => bail!("Missing expression in `{}`", input),
|
None => bail!("Missing expression in `{}`", input),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -424,7 +424,7 @@ fn receive_hook<'a>(address: SocketAddr, hooks: Hooks) -> Result<Response<'a>> {
|
||||||
hooks.inner.iter().for_each(|(name, command)| {
|
hooks.inner.iter().for_each(|(name, command)| {
|
||||||
info!("Execute `{}` from hook `{}`", &command, &name);
|
info!("Execute `{}` from hook `{}`", &command, &name);
|
||||||
|
|
||||||
match run_script::run(&command, &vec![], &ScriptOptions::new()) {
|
match run_script::run(command, &vec![], &ScriptOptions::new()) {
|
||||||
Ok((status, stdout, stderr)) => {
|
Ok((status, stdout, stderr)) => {
|
||||||
info!("Command `{}` exited with return code: {}", &command, status);
|
info!("Command `{}` exited with return code: {}", &command, status);
|
||||||
trace!("Output of command `{}` on stdout: {:?}", &command, &stdout);
|
trace!("Output of command `{}` on stdout: {:?}", &command, &stdout);
|
||||||
|
@ -497,7 +497,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
trace!("Parsed configuration:\n{}", serde_yaml::to_string(&config)?);
|
trace!("Parsed configuration:\n{}", serde_yaml::to_string(&config)?);
|
||||||
|
|
||||||
if let Some(_) = cli.subcommand_matches("configtest") {
|
if cli.subcommand_matches("configtest").is_some() {
|
||||||
debug!("Configtest succeded.");
|
debug!("Configtest succeded.");
|
||||||
println!("Config is OK");
|
println!("Config is OK");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
Loading…
Reference in a new issue