Fix clippy warnings

Especially https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string was a bit
more involved, review requested.
pull/230/head^2
Matěj Laitl 2022-07-29 10:12:43 +02:00
parent 986a47fab3
commit 144c2f654e
4 changed files with 31 additions and 26 deletions

View File

@ -725,7 +725,7 @@ fn delete_cidr(
let cidr_id = prompts::delete_cidr(&cidrs, &peers, &sub_opts)?; let cidr_id = prompts::delete_cidr(&cidrs, &peers, &sub_opts)?;
println!("Deleting CIDR..."); println!("Deleting CIDR...");
let _ = api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?; api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?;
println!("CIDR deleted."); println!("CIDR deleted.");
@ -801,7 +801,7 @@ fn rename_peer(
.next() .next()
.ok_or_else(|| anyhow!("Peer not found."))?; .ok_or_else(|| anyhow!("Peer not found."))?;
let _ = api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?; api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?;
log::info!("Peer renamed."); log::info!("Peer renamed.");
} else { } else {
log::info!("exited without renaming peer."); log::info!("exited without renaming peer.");

View File

@ -357,7 +357,7 @@ fn rename_peer(
.into_iter() .into_iter()
.find(|p| p.name == old_name) .find(|p| p.name == old_name)
.ok_or_else(|| anyhow!("Peer not found."))?; .ok_or_else(|| anyhow!("Peer not found."))?;
let _peer = db_peer.update(&conn, peer_request)?; db_peer.update(&conn, peer_request)?;
} else { } else {
println!("exited without creating peer."); println!("exited without creating peer.");
} }
@ -408,7 +408,7 @@ fn delete_cidr(
let cidr_id = prompts::delete_cidr(&cidrs, &peers, &args)?; let cidr_id = prompts::delete_cidr(&cidrs, &peers, &args)?;
println!("Deleting CIDR..."); println!("Deleting CIDR...");
let _ = DatabaseCidr::delete(&conn, cidr_id)?; DatabaseCidr::delete(&conn, cidr_id)?;
println!("CIDR deleted."); println!("CIDR deleted.");

View File

@ -34,7 +34,7 @@ macro_rules! get_nla_value {
}; };
} }
impl<'a> TryFrom<WgAllowedIp> for AllowedIp { impl TryFrom<WgAllowedIp> for AllowedIp {
type Error = io::Error; type Error = io::Error;
fn try_from(attrs: WgAllowedIp) -> Result<Self, Self::Error> { fn try_from(attrs: WgAllowedIp) -> Result<Self, Self::Error> {
@ -88,7 +88,7 @@ impl PeerConfigBuilder {
} }
} }
impl<'a> TryFrom<WgPeer> for PeerInfo { impl TryFrom<WgPeer> for PeerInfo {
type Error = io::Error; type Error = io::Error;
fn try_from(attrs: WgPeer) -> Result<Self, Self::Error> { fn try_from(attrs: WgPeer) -> Result<Self, Self::Error> {

View File

@ -1,8 +1,7 @@
use crate::{Backend, Device, DeviceUpdate, InterfaceName, PeerConfig, PeerInfo, PeerStats}; use crate::{Backend, Device, DeviceUpdate, InterfaceName, Key, PeerConfig, PeerInfo, PeerStats};
use crate::Key;
use std::{ use std::{
fmt::Write as _,
fs, fs,
io::{self, prelude::*, BufReader}, io::{self, prelude::*, BufReader},
os::unix::net::UnixStream, os::unix::net::UnixStream,
@ -311,55 +310,61 @@ pub fn apply(builder: &DeviceUpdate, iface: &InterfaceName) -> io::Result<()> {
let mut request = String::from("set=1\n"); let mut request = String::from("set=1\n");
if let Some(ref k) = builder.private_key { if let Some(ref k) = builder.private_key {
request.push_str(&format!("private_key={}\n", hex::encode(k.as_bytes()))); writeln!(request, "private_key={}", hex::encode(k.as_bytes())).ok();
} }
if let Some(f) = builder.fwmark { if let Some(f) = builder.fwmark {
request.push_str(&format!("fwmark={}\n", f)); writeln!(request, "fwmark={}", f).ok();
} }
if let Some(f) = builder.listen_port { if let Some(f) = builder.listen_port {
request.push_str(&format!("listen_port={}\n", f)); writeln!(request, "listen_port={}", f).ok();
} }
if builder.replace_peers { if builder.replace_peers {
request.push_str("replace_peers=true\n"); writeln!(request, "replace_peers=true").ok();
} }
for peer in &builder.peers { for peer in &builder.peers {
request.push_str(&format!( writeln!(
"public_key={}\n", request,
"public_key={}",
hex::encode(peer.public_key.as_bytes()) hex::encode(peer.public_key.as_bytes())
)); )
.ok();
if peer.replace_allowed_ips { if peer.replace_allowed_ips {
request.push_str("replace_allowed_ips=true\n"); writeln!(request, "replace_allowed_ips=true").ok();
} }
if peer.remove_me { if peer.remove_me {
request.push_str("remove=true\n"); writeln!(request, "remove=true").ok();
} }
if let Some(ref k) = peer.preshared_key { if let Some(ref k) = peer.preshared_key {
request.push_str(&format!("preshared_key={}\n", hex::encode(k.as_bytes()))); writeln!(request, "preshared_key={}", hex::encode(k.as_bytes())).ok();
} }
if let Some(endpoint) = peer.endpoint { if let Some(endpoint) = peer.endpoint {
request.push_str(&format!("endpoint={}\n", endpoint)); writeln!(request, "endpoint={}", endpoint).ok();
} }
if let Some(keepalive_interval) = peer.persistent_keepalive_interval { if let Some(keepalive_interval) = peer.persistent_keepalive_interval {
request.push_str(&format!( writeln!(
"persistent_keepalive_interval={}\n", request,
"persistent_keepalive_interval={}",
keepalive_interval keepalive_interval
)); )
.ok();
} }
for allowed_ip in &peer.allowed_ips { for allowed_ip in &peer.allowed_ips {
request.push_str(&format!( writeln!(
"allowed_ip={}/{}\n", request,
"allowed_ip={}/{}",
allowed_ip.address, allowed_ip.cidr allowed_ip.address, allowed_ip.cidr
)); )
.ok();
} }
} }