Fix clippy warnings

This commit is contained in:
finga 2021-06-30 23:52:19 +02:00
parent dd78835f17
commit 5d20366e5d

View file

@ -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)| {
if let Some(ip) = &hook.ip_filter {
return accept_ip(&name, &client_ip, &ip);
accept_ip(name, client_ip, ip)
} else {
info!(
"Allow hook `{}` from {}, no IP filter was configured",
@ -250,7 +250,7 @@ impl Hooks {
let secrets = hook
.secrets
.iter()
.map(|secret| validate_request(&secret, &signature, &buffer));
.map(|secret| validate_request(secret, signature, &buffer));
for secret in secrets {
match secret {
@ -263,7 +263,7 @@ impl Hooks {
serde_json::from_slice(&buffer).map_err(WebhookeyError::Serde)?;
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) => {
info!("Filter for `{}` matched", &hook_name);
result.insert(hook_name.to_string(), command);
@ -294,7 +294,7 @@ impl FromDataSimple for Hooks {
type Error = WebhookeyError;
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) => {
if hooks.inner.is_empty() {
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<()> {
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))?;
mac.update(&data);
mac.update(data);
let raw_signature = hex::decode(signature.as_bytes())?;
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((
delimited(tag("{{"), take_until("}}"), tag("}}")),
take_until("{{"),
)))(&input);
)))(input);
let (_last, result) = parse
.finish()
@ -389,7 +389,7 @@ fn replace_parameters(
match expr.get(0) {
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),
}
},
@ -424,7 +424,7 @@ fn receive_hook<'a>(address: SocketAddr, hooks: Hooks) -> Result<Response<'a>> {
hooks.inner.iter().for_each(|(name, command)| {
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)) => {
info!("Command `{}` exited with return code: {}", &command, status);
trace!("Output of command `{}` on stdout: {:?}", &command, &stdout);
@ -497,7 +497,7 @@ fn main() -> Result<()> {
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.");
println!("Config is OK");
return Ok(());