mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Fix all clippy warnings in the Rust backend
Addresses all 31 warnings emitted by cargo clippy: redundant field names in struct initialisers, unnecessary unwrap after is_some checks (replaced with if-let), needless borrows, filter+next replaced with find, iter().count() replaced with len(), clone on Copy type, and manual match-to-Option replaced with .ok(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
44d593fccc
commit
cb2b3c6af7
+16
-19
@@ -21,54 +21,51 @@ pub fn list_devices(
|
|||||||
// Prepare SQL and parameters
|
// Prepare SQL and parameters
|
||||||
let mut sql_statement = "SELECT mac_address, ipv4_address, vendor, last_seen, is_registered, owner, device_type FROM devices WHERE 1=1 ".to_string();
|
let mut sql_statement = "SELECT mac_address, ipv4_address, vendor, last_seen, is_registered, owner, device_type FROM devices WHERE 1=1 ".to_string();
|
||||||
let mut params: Vec<rusqlite::types::Value> = Vec::new();
|
let mut params: Vec<rusqlite::types::Value> = Vec::new();
|
||||||
if is_registered.is_some() {
|
if let Some(is_registered) = is_registered {
|
||||||
debug!("Adding filter is_registered={}", is_registered.unwrap());
|
debug!("Adding filter is_registered={}", is_registered);
|
||||||
sql_statement.push_str("AND is_registered=? ");
|
sql_statement.push_str("AND is_registered=? ");
|
||||||
|
params.push(is_registered.into());
|
||||||
params.push(is_registered.unwrap().into());
|
|
||||||
};
|
};
|
||||||
if last_seen_from.is_some() {
|
if let Some(last_seen_from) = last_seen_from {
|
||||||
debug!(
|
debug!(
|
||||||
"Adding filter last_seen>={}",
|
"Adding filter last_seen>={}",
|
||||||
last_seen_from.unwrap().format("%Y-%m-%d %H:%M:%S")
|
last_seen_from.format("%Y-%m-%d %H:%M:%S")
|
||||||
);
|
);
|
||||||
sql_statement.push_str("AND last_seen>=? ");
|
sql_statement.push_str("AND last_seen>=? ");
|
||||||
params.push(
|
params.push(
|
||||||
last_seen_from
|
last_seen_from
|
||||||
.unwrap()
|
|
||||||
.format("%Y-%m-%d %H:%M:%S")
|
.format("%Y-%m-%d %H:%M:%S")
|
||||||
.to_string()
|
.to_string()
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
if last_seen_to.is_some() {
|
if let Some(last_seen_to) = last_seen_to {
|
||||||
debug!(
|
debug!(
|
||||||
"Adding filter last_seen<={}",
|
"Adding filter last_seen<={}",
|
||||||
last_seen_to.unwrap().format("%Y-%m-%d %H:%M:%S")
|
last_seen_to.format("%Y-%m-%d %H:%M:%S")
|
||||||
);
|
);
|
||||||
sql_statement.push_str("AND last_seen<=? ");
|
sql_statement.push_str("AND last_seen<=? ");
|
||||||
params.push(
|
params.push(
|
||||||
last_seen_to
|
last_seen_to
|
||||||
.unwrap()
|
|
||||||
.format("%Y-%m-%d %H:%M:%S")
|
.format("%Y-%m-%d %H:%M:%S")
|
||||||
.to_string()
|
.to_string()
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
if owner.is_some() {
|
if let Some(owner) = owner {
|
||||||
debug!("Adding filter owner={}", owner.clone().unwrap());
|
debug!("Adding filter owner={}", owner);
|
||||||
sql_statement.push_str("AND owner=? ");
|
sql_statement.push_str("AND owner=? ");
|
||||||
params.push(owner.unwrap().into());
|
params.push(owner.into());
|
||||||
};
|
};
|
||||||
if device_type.is_some() {
|
if let Some(device_type) = device_type {
|
||||||
debug!("Adding filter device_type={}", device_type.clone().unwrap());
|
debug!("Adding filter device_type={}", device_type);
|
||||||
sql_statement.push_str("AND device_type=? ");
|
sql_statement.push_str("AND device_type=? ");
|
||||||
params.push(device_type.unwrap().into());
|
params.push(device_type.into());
|
||||||
}
|
}
|
||||||
if vendor.is_some() {
|
if let Some(vendor) = vendor {
|
||||||
debug!("Adding filter vendor={}", vendor.clone().unwrap());
|
debug!("Adding filter vendor={}", vendor);
|
||||||
sql_statement.push_str("AND vendor=? ");
|
sql_statement.push_str("AND vendor=? ");
|
||||||
params.push(vendor.unwrap().into());
|
params.push(vendor.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut stmt = conn.prepare(sql_statement.as_str())?;
|
let mut stmt = conn.prepare(sql_statement.as_str())?;
|
||||||
|
|||||||
@@ -20,27 +20,26 @@ pub fn list(
|
|||||||
let mut params: Vec<rusqlite::types::Value> = Vec::new();
|
let mut params: Vec<rusqlite::types::Value> = Vec::new();
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
if is_new.is_some() {
|
if let Some(is_new) = is_new {
|
||||||
debug!("Adding filter is_new={}", is_new.unwrap());
|
debug!("Adding filter is_new={}", is_new);
|
||||||
sql_statement.push_str(" AND is_new=?");
|
sql_statement.push_str(" AND is_new=?");
|
||||||
|
params.push(is_new.into());
|
||||||
params.push(is_new.unwrap().into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List order
|
// List order
|
||||||
sql_statement.push_str(" ORDER BY created_on DESC");
|
sql_statement.push_str(" ORDER BY created_on DESC");
|
||||||
|
|
||||||
// Paging
|
// Paging
|
||||||
if page_offset.is_some() && page_limit.is_some() {
|
if let (Some(page_offset), Some(page_limit)) = (page_offset, page_limit) {
|
||||||
debug!(
|
debug!(
|
||||||
"Adding paging to list with offset={} and limit={}",
|
"Adding paging to list with offset={} and limit={}",
|
||||||
page_offset.unwrap(),
|
page_offset,
|
||||||
page_limit.unwrap()
|
page_limit
|
||||||
);
|
);
|
||||||
sql_statement.push_str(" LIMIT ? OFFSET ?");
|
sql_statement.push_str(" LIMIT ? OFFSET ?");
|
||||||
|
|
||||||
params.push(page_limit.unwrap().into());
|
params.push(page_limit.into());
|
||||||
params.push(page_offset.unwrap().into());
|
params.push(page_offset.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut stmt = conn.prepare(sql_statement.as_str())?;
|
let mut stmt = conn.prepare(sql_statement.as_str())?;
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ pub async fn find(interface: String) -> Result<Vec<Device>, Box<dyn std::error::
|
|||||||
let network_interface: NetworkInterface = match datalink::interfaces()
|
let network_interface: NetworkInterface = match datalink::interfaces()
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|el| el.is_up())
|
.filter(|el| el.is_up())
|
||||||
.filter(|el| el.name == interface)
|
.find(|el| el.name == interface)
|
||||||
.next()
|
|
||||||
{
|
{
|
||||||
Some(value) => value.clone(),
|
Some(value) => value.clone(),
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ pub async fn send_packet(
|
|||||||
ethernet_packet.set_payload(arp_packet.packet_mut());
|
ethernet_packet.set_payload(arp_packet.packet_mut());
|
||||||
|
|
||||||
tx.send_to(
|
tx.send_to(
|
||||||
ðernet_packet.to_immutable().packet(),
|
ethernet_packet.to_immutable().packet(),
|
||||||
Some(interface.clone()),
|
Some(interface.clone()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ lazy_static! {
|
|||||||
let mut database = HashMap::new();
|
let mut database = HashMap::new();
|
||||||
let data = include_str!("../data/mac-vendors-export.json");
|
let data = include_str!("../data/mac-vendors-export.json");
|
||||||
|
|
||||||
let json: Vec<MacRecord> = match serde_json::from_str(&data) {
|
let json: Vec<MacRecord> = match serde_json::from_str(data) {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
error!(
|
error!(
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ impl Device {
|
|||||||
last_seen: DateTime<Utc>,
|
last_seen: DateTime<Utc>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
mac_address: mac_address,
|
mac_address,
|
||||||
ipv4_address: ipv4_address,
|
ipv4_address,
|
||||||
vendor: vendor,
|
vendor,
|
||||||
last_seen: last_seen,
|
last_seen,
|
||||||
is_registered: false,
|
is_registered: false,
|
||||||
owner: "".to_string(),
|
owner: "".to_string(),
|
||||||
device_type: "".to_string(),
|
device_type: "".to_string(),
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ impl Notification {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: -1,
|
id: -1,
|
||||||
created_on: created_on,
|
created_on,
|
||||||
notification_type: notification_type,
|
notification_type,
|
||||||
title: title,
|
title,
|
||||||
body: body,
|
body,
|
||||||
is_new: is_new,
|
is_new,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub async fn scan() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
device_finders::arp::find(get_settings().networking.interface.to_string()).await?;
|
device_finders::arp::find(get_settings().networking.interface.to_string()).await?;
|
||||||
|
|
||||||
info!("Done with ARP probes");
|
info!("Done with ARP probes");
|
||||||
info!("Found {} online devices", devices.iter().count());
|
info!("Found {} online devices", devices.len());
|
||||||
|
|
||||||
// Process found devices
|
// Process found devices
|
||||||
for device in devices.iter() {
|
for device in devices.iter() {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ pub fn serialize<S: Serializer>(
|
|||||||
datetime: &DateTime<Utc>,
|
datetime: &DateTime<Utc>,
|
||||||
serializer: S,
|
serializer: S,
|
||||||
) -> Result<S::Ok, S::Error> {
|
) -> Result<S::Ok, S::Error> {
|
||||||
time_to_json(datetime.clone()).serialize(serializer)
|
time_to_json(*datetime).serialize(serializer)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<DateTime<Utc>, D::Error> {
|
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<DateTime<Utc>, D::Error> {
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ pub fn parse_parameter_bool(params: &HashMap<String, String>, name: &str) -> Opt
|
|||||||
if params.contains_key(name) {
|
if params.contains_key(name) {
|
||||||
let param_value = params.get(name).unwrap().as_str();
|
let param_value = params.get(name).unwrap().as_str();
|
||||||
debug!("Found parameter {name} with value {}", param_value);
|
debug!("Found parameter {name} with value {}", param_value);
|
||||||
match param_value.parse::<bool>() {
|
param_value.parse::<bool>().ok()
|
||||||
Ok(value) => Some(value),
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -20,10 +17,7 @@ pub fn parse_parameter_int(params: &HashMap<String, String>, name: &str) -> Opti
|
|||||||
if params.contains_key(name) {
|
if params.contains_key(name) {
|
||||||
let param_value = params.get(name).unwrap().as_str();
|
let param_value = params.get(name).unwrap().as_str();
|
||||||
debug!("Found parameter {name} with value {}", param_value);
|
debug!("Found parameter {name} with value {}", param_value);
|
||||||
match param_value.parse::<i64>() {
|
param_value.parse::<i64>().ok()
|
||||||
Ok(value) => Some(value),
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user