Skip to content

Commit fa74035

Browse files
vsilentCopilot
andcommitted
fix: resolve all clippy warnings
- Remove unused imports across 17 files - Prefix unused variables/fields with underscore - Implement Default trait instead of inherent default() methods (dedup, threat_scorer) - Implement FromStr trait instead of inherent from_str() methods (AiProvider, LogSourceType) - Replace Iterator::last() with next_back() on DoubleEndedIterator - Derive Default for EbpfLoader instead of manual impl - Remove useless .into() conversion in database connection - Wrap too-many-arguments functions with param structs (SniffArgs, CreateLogSummaryParams) - Replace filter_map(Some(...)) with map(...) in build_readers - Replace manual find loop with Iterator::find - Collapse nested if-let in signature_matcher - Gate program_to_tracepoint with cfg for Linux+ebpf only - Move api module to library crate, fix binary to import from library - Fix pre-existing test_get_alerts_empty to init database - Use std::io::Error::other() instead of Error::new(Other, e) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4601763 commit fa74035

31 files changed

Lines changed: 329 additions & 361 deletions

src/alerting/dedup.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ pub struct DedupConfig {
1616
}
1717

1818
impl DedupConfig {
19-
/// Create default config
20-
pub fn default() -> Self {
19+
/// Create a new config with given values
20+
pub fn new(enabled: bool, window_seconds: u64, aggregation: bool) -> Self {
2121
Self {
22-
enabled: true,
23-
window_seconds: 300, // 5 minutes
24-
aggregation: true,
22+
enabled,
23+
window_seconds,
24+
aggregation,
2525
}
2626
}
2727

@@ -61,7 +61,7 @@ impl DedupConfig {
6161

6262
impl Default for DedupConfig {
6363
fn default() -> Self {
64-
Self::default()
64+
Self::new(true, 300, true)
6565
}
6666
}
6767

src/alerting/manager.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! Manages alert generation, storage, and lifecycle
44
55
use anyhow::Result;
6-
use chrono::{DateTime, Utc};
76
use std::collections::HashMap;
87
use std::sync::{Arc, RwLock};
98

@@ -129,7 +128,7 @@ impl AlertManager {
129128

130129
/// Get statistics
131130
pub fn get_stats(&self) -> AlertStats {
132-
let stats = self.stats.read().unwrap();
131+
let _stats = self.stats.read().unwrap();
133132

134133
// Calculate current counts from alerts
135134
let alerts = self.alerts.read().unwrap();

src/alerting/notifications.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! Notification channels for alert delivery
44
55
use anyhow::Result;
6-
use chrono::{DateTime, Utc};
76

87
use crate::alerting::alert::{Alert, AlertSeverity};
98

@@ -13,10 +12,10 @@ pub struct NotificationConfig {
1312
slack_webhook: Option<String>,
1413
smtp_host: Option<String>,
1514
smtp_port: Option<u16>,
16-
smtp_user: Option<String>,
17-
smtp_password: Option<String>,
15+
_smtp_user: Option<String>,
16+
_smtp_password: Option<String>,
1817
webhook_url: Option<String>,
19-
email_recipients: Vec<String>,
18+
_email_recipients: Vec<String>,
2019
}
2120

2221
impl NotificationConfig {
@@ -26,10 +25,10 @@ impl NotificationConfig {
2625
slack_webhook: None,
2726
smtp_host: None,
2827
smtp_port: None,
29-
smtp_user: None,
30-
smtp_password: None,
28+
_smtp_user: None,
29+
_smtp_password: None,
3130
webhook_url: None,
32-
email_recipients: Vec::new(),
31+
_email_recipients: Vec::new(),
3332
}
3433
}
3534

src/api/alerts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use crate::database::{
55
update_alert_status, AlertFilter, DbPool,
66
};
77
use actix_web::{web, HttpResponse, Responder};
8-
use chrono::Utc;
98
use serde::Deserialize;
10-
use uuid::Uuid;
119

1210
/// Query parameters for alert filtering
1311
#[derive(Debug, Deserialize)]
@@ -156,6 +154,7 @@ mod tests {
156154
#[actix_rt::test]
157155
async fn test_get_alerts_empty() {
158156
let pool = create_pool(":memory:").unwrap();
157+
crate::database::init_database(&pool).unwrap();
159158
let pool_data = web::Data::new(pool);
160159

161160
let app =

src/api/containers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Containers API endpoints
22
3-
use crate::database::models::ContainerCache;
43
use crate::database::DbPool;
54
use crate::docker::client::ContainerInfo;
65
use crate::docker::containers::ContainerManager;

src/api/security.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Security API endpoints
22
3+
use crate::models::api::security::SecurityStatusResponse;
34
use actix_web::{web, HttpResponse, Responder};
4-
use stackdog::models::api::security::SecurityStatusResponse;
55

66
/// Get overall security status
77
///

src/api/threats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Threats API endpoints
22
3+
use crate::models::api::threats::{ThreatResponse, ThreatStatisticsResponse};
34
use actix_web::{web, HttpResponse, Responder};
4-
use stackdog::models::api::threats::{ThreatResponse, ThreatStatisticsResponse};
55
use std::collections::HashMap;
66

77
/// Get all threats

src/collectors/ebpf/container.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! Detects container ID from cgroup and other sources
44
5-
use anyhow::{Context, Result};
5+
use anyhow::Result;
66

77
/// Container detector
88
pub struct ContainerDetector {
@@ -45,11 +45,11 @@ impl ContainerDetector {
4545
}
4646

4747
/// Detect container ID from cgroup file
48-
fn detect_from_cgroup(&self, pid: u32) -> Option<String> {
48+
fn detect_from_cgroup(&self, _pid: u32) -> Option<String> {
4949
#[cfg(target_os = "linux")]
5050
{
5151
// Read /proc/[pid]/cgroup
52-
let cgroup_path = format!("/proc/{}/cgroup", pid);
52+
let cgroup_path = format!("/proc/{}/cgroup", _pid);
5353
if let Ok(content) = std::fs::read_to_string(&cgroup_path) {
5454
for line in content.lines() {
5555
if let Some(id) = Self::parse_container_from_cgroup(line) {
@@ -114,7 +114,7 @@ impl ContainerDetector {
114114
// Look for /kubepods/.../container_id
115115
if path.contains("/kubepods/") {
116116
// Get last component
117-
let id = path.split('/').last()?;
117+
let id = path.split('/').next_back()?;
118118

119119
if Self::is_valid_container_id(id) {
120120
return Some(id.to_string());

src/collectors/ebpf/enrichment.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@ use anyhow::Result;
77

88
/// Event enricher
99
pub struct EventEnricher {
10-
// Cache for process information
11-
process_cache: std::collections::HashMap<u32, ProcessInfo>,
10+
_process_cache: std::collections::HashMap<u32, ProcessInfo>,
1211
}
1312

1413
#[derive(Debug, Clone)]
1514
struct ProcessInfo {
16-
pid: u32,
17-
ppid: u32,
18-
comm: Option<String>,
15+
_pid: u32,
16+
_ppid: u32,
17+
_comm: Option<String>,
1918
}
2019

2120
impl EventEnricher {
2221
/// Create a new event enricher
2322
pub fn new() -> Result<Self> {
2423
Ok(Self {
25-
process_cache: std::collections::HashMap::new(),
24+
_process_cache: std::collections::HashMap::new(),
2625
})
2726
}
2827

@@ -44,11 +43,11 @@ impl EventEnricher {
4443
}
4544

4645
/// Get parent PID for a process
47-
pub fn get_parent_pid(&self, pid: u32) -> Option<u32> {
46+
pub fn get_parent_pid(&self, _pid: u32) -> Option<u32> {
4847
#[cfg(target_os = "linux")]
4948
{
5049
// Read from /proc/[pid]/stat
51-
let stat_path = format!("/proc/{}/stat", pid);
50+
let stat_path = format!("/proc/{}/stat", _pid);
5251
if let Ok(content) = std::fs::read_to_string(&stat_path) {
5352
// Parse ppid from stat file (field 4)
5453
let parts: Vec<&str> = content.split_whitespace().collect();
@@ -64,11 +63,11 @@ impl EventEnricher {
6463
}
6564

6665
/// Get process command name
67-
pub fn get_process_comm(&self, pid: u32) -> Option<String> {
66+
pub fn get_process_comm(&self, _pid: u32) -> Option<String> {
6867
#[cfg(target_os = "linux")]
6968
{
7069
// Read from /proc/[pid]/comm
71-
let comm_path = format!("/proc/{}/comm", pid);
70+
let comm_path = format!("/proc/{}/comm", _pid);
7271
if let Ok(content) = std::fs::read_to_string(&comm_path) {
7372
return Some(content.trim().to_string());
7473
}
@@ -91,11 +90,11 @@ impl EventEnricher {
9190
}
9291

9392
/// Get process executable path
94-
pub fn get_process_exe(&self, pid: u32) -> Option<String> {
93+
pub fn get_process_exe(&self, _pid: u32) -> Option<String> {
9594
#[cfg(target_os = "linux")]
9695
{
9796
// Read symlink /proc/[pid]/exe
98-
let exe_path = format!("/proc/{}/exe", pid);
97+
let exe_path = format!("/proc/{}/exe", _pid);
9998
if let Ok(path) = std::fs::read_link(&exe_path) {
10099
return path.to_str().map(|s| s.to_string());
101100
}
@@ -105,11 +104,11 @@ impl EventEnricher {
105104
}
106105

107106
/// Get process working directory
108-
pub fn get_process_cwd(&self, pid: u32) -> Option<String> {
107+
pub fn get_process_cwd(&self, _pid: u32) -> Option<String> {
109108
#[cfg(target_os = "linux")]
110109
{
111110
// Read symlink /proc/[pid]/cwd
112-
let cwd_path = format!("/proc/{}/cwd", pid);
111+
let cwd_path = format!("/proc/{}/cwd", _pid);
113112
if let Ok(path) = std::fs::read_link(&cwd_path) {
114113
return path.to_str().map(|s| s.to_string());
115114
}

src/collectors/ebpf/loader.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
//! Note: This module is only available on Linux with the ebpf feature enabled
66
7-
use anyhow::{bail, Context, Result};
7+
use anyhow::Result;
88
use std::collections::HashMap;
99

1010
/// eBPF loader errors
@@ -36,6 +36,7 @@ pub enum LoadError {
3636
///
3737
/// Responsible for loading eBPF programs from ELF files
3838
/// and attaching them to kernel tracepoints
39+
#[derive(Default)]
3940
pub struct EbpfLoader {
4041
#[cfg(all(target_os = "linux", feature = "ebpf"))]
4142
bpf: Option<aya::Bpf>,
@@ -46,7 +47,7 @@ pub struct EbpfLoader {
4647

4748
#[derive(Debug, Clone)]
4849
struct ProgramInfo {
49-
name: String,
50+
_name: String,
5051
attached: bool,
5152
}
5253

@@ -160,7 +161,7 @@ impl EbpfLoader {
160161
self.loaded_programs.insert(
161162
_program_name.to_string(),
162163
ProgramInfo {
163-
name: _program_name.to_string(),
164+
_name: _program_name.to_string(),
164165
attached: true,
165166
},
166167
);
@@ -270,18 +271,8 @@ impl EbpfLoader {
270271
}
271272
}
272273

273-
impl Default for EbpfLoader {
274-
fn default() -> Self {
275-
Self {
276-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
277-
bpf: None,
278-
loaded_programs: HashMap::new(),
279-
kernel_version: None,
280-
}
281-
}
282-
}
283-
284274
/// Map program name to its tracepoint (category, name) for aya attachment.
275+
#[cfg(all(target_os = "linux", feature = "ebpf"))]
285276
fn program_to_tracepoint(name: &str) -> Option<(&'static str, &'static str)> {
286277
match name {
287278
"trace_execve" => Some(("syscalls", "sys_enter_execve")),

0 commit comments

Comments
 (0)