Clippy on src/
This commit is contained in:
parent
d78cea8ca9
commit
72cf39b411
23
src/rules.rs
23
src/rules.rs
|
@ -69,7 +69,7 @@ pub(crate) async fn delete(db: &Db, rule_id: &str) -> Result<Rule, anyhow::Error
|
|||
|
||||
let rule = tree
|
||||
.remove(rule_id.as_bytes())?
|
||||
.ok_or(anyhow::anyhow!("No rule with id {}", rule_id))?;
|
||||
.ok_or_else(|| anyhow::anyhow!("No rule with id {}", rule_id))?;
|
||||
|
||||
tree.flush_async().await?;
|
||||
|
||||
|
@ -147,17 +147,16 @@ async fn set_rule(
|
|||
{
|
||||
let has_nat_subnet = interfaces.nats.iter().any(|nat_iface| {
|
||||
*nat_iface == iface.interface
|
||||
|| *nat_iface != iface.interface
|
||||
&& interfaces
|
||||
.internal
|
||||
.iter()
|
||||
.chain(&interfaces.tunnel)
|
||||
.chain(&interfaces.vlan)
|
||||
.any(|other_iface| {
|
||||
*nat_iface == other_iface.interface
|
||||
&& other_iface.ip == iface.ip
|
||||
&& other_iface.mask == iface.mask
|
||||
})
|
||||
|| interfaces
|
||||
.internal
|
||||
.iter()
|
||||
.chain(&interfaces.tunnel)
|
||||
.chain(&interfaces.vlan)
|
||||
.any(|other_iface| {
|
||||
*nat_iface == other_iface.interface
|
||||
&& other_iface.ip == iface.ip
|
||||
&& other_iface.mask == iface.mask
|
||||
})
|
||||
});
|
||||
|
||||
if !has_nat_subnet {
|
||||
|
|
|
@ -125,18 +125,20 @@ impl Interfaces {
|
|||
|
||||
let external = parse_interface_info(&output, &config.interface.external)?
|
||||
.next()
|
||||
.ok_or(anyhow!(
|
||||
"Failed to parse IP for interface {}",
|
||||
config.interface.external,
|
||||
))?;
|
||||
.ok_or_else(|| {
|
||||
anyhow!(
|
||||
"Failed to parse IP for interface {}",
|
||||
config.interface.external,
|
||||
)
|
||||
})?;
|
||||
|
||||
let mut internal = Vec::new();
|
||||
|
||||
for iface in &config.interface.internal {
|
||||
internal.extend(parse_interface_info(&output, &iface)?);
|
||||
internal.extend(parse_interface_info(&output, iface)?);
|
||||
}
|
||||
|
||||
if internal.len() == 0 {
|
||||
if internal.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"No internal interfaces found for {:?}",
|
||||
config.interface.internal
|
||||
|
@ -146,13 +148,13 @@ impl Interfaces {
|
|||
let mut vlan = Vec::new();
|
||||
|
||||
for iface in &config.interface.vlan {
|
||||
vlan.extend(parse_interface_info(&output, &iface)?);
|
||||
vlan.extend(parse_interface_info(&output, iface)?);
|
||||
}
|
||||
|
||||
let mut tunnel = Vec::new();
|
||||
|
||||
for iface in &config.interface.tunnel {
|
||||
tunnel.extend(parse_interface_info(&output, &iface)?);
|
||||
tunnel.extend(parse_interface_info(&output, iface)?);
|
||||
}
|
||||
|
||||
Ok(Interfaces {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::startup::Interfaces;
|
||||
|
||||
static UNIVERSE: &'static str = "0.0.0.0/0";
|
||||
static UNIVERSE: &str = "0.0.0.0/0";
|
||||
|
||||
pub(crate) fn firewall_rules(interfaces: &Interfaces) -> String {
|
||||
filter(interfaces) + "\n" + &nat(interfaces)
|
||||
|
|
Loading…
Reference in a new issue