Skip to content

Commit d6d5a32

Browse files
committed
Fix CI errors: clean up code quality issues
- Remove unused imports (chrono::Utc, Path) - Replace map_or with is_some_and for clarity - Remove unnecessary to_string() in format! macros - Replace redundant closures with direct function references - Improve code readability and performance
1 parent fc01099 commit d6d5a32

File tree

7 files changed

+122
-82
lines changed

7 files changed

+122
-82
lines changed

examples/audit_trail.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,17 @@ fn main() {
134134
// Display audit entries
135135
println!("\n=== Audit Trail Entries ===");
136136
for (i, entry) in audit_entries.iter().enumerate() {
137-
println!("\n[{}] {}", i + 1, entry.timestamp.format("%Y-%m-%d %H:%M:%S UTC"));
137+
println!(
138+
"\n[{}] {}",
139+
i + 1,
140+
entry.timestamp.format("%Y-%m-%d %H:%M:%S UTC")
141+
);
138142
println!(" Message: {}", entry.message);
139143
if let Some(metadata) = &entry.metadata {
140-
println!(" Metadata: {}", serde_json::to_string_pretty(metadata).unwrap());
144+
println!(
145+
" Metadata: {}",
146+
serde_json::to_string_pretty(metadata).unwrap()
147+
);
141148
}
142149
println!(" Integrity Hash: {}...", &entry.integrity_hash[..16]);
143150
println!(" Verified: {}", entry.verify_integrity());

examples/compliance_report.rs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Example: Generate compliance reports (SOX, PCI-DSS, GLBA)
22
3-
use rust_secure_logger::{SecureLogger, ComplianceReporter};
4-
use chrono::{Utc, Duration};
3+
use chrono::{Duration, Utc};
4+
use rust_secure_logger::{ComplianceReporter, SecureLogger};
55

66
fn main() {
77
println!("=== Compliance Reporting Example ===\n");
@@ -12,7 +12,7 @@ fn main() {
1212
// Simulate a day of operations
1313
logger.audit(
1414
"User login",
15-
Some(serde_json::json!({"user_id": "USR-001", "role": "admin"}))
15+
Some(serde_json::json!({"user_id": "USR-001", "role": "admin"})),
1616
);
1717

1818
logger.audit(
@@ -21,17 +21,17 @@ fn main() {
2121
"transaction_id": "TXN-12345",
2222
"amount": 10000.00,
2323
"type": "wire_transfer"
24-
}))
24+
})),
2525
);
2626

2727
logger.security_event(
2828
"Failed authentication attempt",
29-
Some(serde_json::json!({"username": "admin", "ip": "192.168.1.50"}))
29+
Some(serde_json::json!({"username": "admin", "ip": "192.168.1.50"})),
3030
);
3131

3232
logger.critical(
3333
"Unauthorized access attempt",
34-
Some(serde_json::json!({"resource": "/admin/users", "ip": "10.0.0.100"}))
34+
Some(serde_json::json!({"resource": "/admin/users", "ip": "10.0.0.100"})),
3535
);
3636

3737
logger.info("Daily backup completed");
@@ -45,15 +45,24 @@ fn main() {
4545
println!("SOX COMPLIANCE REPORT");
4646
println!("{}", "=".repeat(80));
4747
let sox_report = logger.generate_sox_report(period_start, period_end);
48-
println!("Report Period: {} to {}", sox_report.period_start, sox_report.period_end);
48+
println!(
49+
"Report Period: {} to {}",
50+
sox_report.period_start, sox_report.period_end
51+
);
4952
println!("Total Events: {}", sox_report.total_events);
5053
println!("Audit Events: {}", sox_report.audit_events);
5154
println!("Security Events: {}", sox_report.security_events);
5255
println!("Critical Events: {}", sox_report.critical_events);
5356
println!("Integrity Verified: {}", sox_report.integrity_verified);
5457
println!("\nFindings:");
5558
for (i, finding) in sox_report.findings.iter().enumerate() {
56-
println!(" {}. [{:?}] {} - {}", i + 1, finding.severity, finding.control_area, finding.description);
59+
println!(
60+
" {}. [{:?}] {} - {}",
61+
i + 1,
62+
finding.severity,
63+
finding.control_area,
64+
finding.description
65+
);
5766
}
5867
println!();
5968

@@ -70,10 +79,23 @@ fn main() {
7079
let pci_report = logger.generate_pci_report(period_start, period_end);
7180
println!("Total Events: {}", pci_report.total_events);
7281
println!("Audit Events (Req 10.2): {}", pci_report.audit_events);
73-
println!("Integrity Status (Req 10.5): {}", if pci_report.integrity_verified { "PASS" } else { "FAIL" });
82+
println!(
83+
"Integrity Status (Req 10.5): {}",
84+
if pci_report.integrity_verified {
85+
"PASS"
86+
} else {
87+
"FAIL"
88+
}
89+
);
7490
println!("\nFindings:");
7591
for (i, finding) in pci_report.findings.iter().enumerate() {
76-
println!(" {}. [{:?}] {} - {}", i + 1, finding.severity, finding.control_area, finding.description);
92+
println!(
93+
" {}. [{:?}] {} - {}",
94+
i + 1,
95+
finding.severity,
96+
finding.control_area,
97+
finding.description
98+
);
7799
}
78100
println!();
79101

@@ -82,10 +104,19 @@ fn main() {
82104
println!("{}", "=".repeat(80));
83105
let glba_report = logger.generate_glba_report(period_start, period_end);
84106
println!("Total Events: {}", glba_report.total_events);
85-
println!("Safeguards Rule - Audit Events: {}", glba_report.audit_events);
107+
println!(
108+
"Safeguards Rule - Audit Events: {}",
109+
glba_report.audit_events
110+
);
86111
println!("\nFindings:");
87112
for (i, finding) in glba_report.findings.iter().enumerate() {
88-
println!(" {}. [{:?}] {} - {}", i + 1, finding.severity, finding.control_area, finding.description);
113+
println!(
114+
" {}. [{:?}] {} - {}",
115+
i + 1,
116+
finding.severity,
117+
finding.control_area,
118+
finding.description
119+
);
89120
}
90121
println!();
91122

examples/siem_integration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
"ip_address": "192.168.1.100",
1818
"attempt_count": 3
1919
})),
20-
"authentication"
20+
"authentication",
2121
);
2222

2323
logger.log_with_category(
@@ -28,7 +28,7 @@ fn main() {
2828
"query": "SELECT * FROM users WHERE id=1' OR '1'='1",
2929
"blocked": true
3030
})),
31-
"web_attack"
31+
"web_attack",
3232
);
3333

3434
logger.audit(
@@ -39,7 +39,7 @@ fn main() {
3939
"currency": "USD",
4040
"from_account": "****1234",
4141
"to_account": "****5678"
42-
}))
42+
})),
4343
);
4444

4545
// Export to CEF format (for ArcSight)

src/compliance.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ impl ComplianceReporter {
9696
.filter(|e| e.level == SecurityLevel::Critical)
9797
.count();
9898

99-
let integrity_failures = filtered
100-
.iter()
101-
.filter(|e| !e.verify_integrity())
102-
.count();
99+
let integrity_failures = filtered.iter().filter(|e| !e.verify_integrity()).count();
103100
let integrity_verified = integrity_failures == 0;
104101

105102
let mut findings = Vec::new();
@@ -180,10 +177,7 @@ impl ComplianceReporter {
180177
.filter(|e| e.level == SecurityLevel::Critical)
181178
.count();
182179

183-
let integrity_failures = filtered
184-
.iter()
185-
.filter(|e| !e.verify_integrity())
186-
.count();
180+
let integrity_failures = filtered.iter().filter(|e| !e.verify_integrity()).count();
187181
let integrity_verified = integrity_failures == 0;
188182

189183
let mut findings = Vec::new();
@@ -262,10 +256,7 @@ impl ComplianceReporter {
262256
.filter(|e| e.level == SecurityLevel::Critical)
263257
.count();
264258

265-
let integrity_failures = filtered
266-
.iter()
267-
.filter(|e| !e.verify_integrity())
268-
.count();
259+
let integrity_failures = filtered.iter().filter(|e| !e.verify_integrity()).count();
269260
let integrity_verified = integrity_failures == 0;
270261

271262
let mut findings = Vec::new();
@@ -274,7 +265,7 @@ impl ComplianceReporter {
274265
let access_events = filtered
275266
.iter()
276267
.filter(|e| {
277-
e.category.as_ref().map_or(false, |c| {
268+
e.category.as_ref().is_some_and(|c| {
278269
c.contains("authentication") || c.contains("access")
279270
})
280271
})
@@ -320,8 +311,14 @@ impl ComplianceReporter {
320311
csv.push_str(&format!("Audit Events,{}\n", report.audit_events));
321312
csv.push_str(&format!("Security Events,{}\n", report.security_events));
322313
csv.push_str(&format!("Critical Events,{}\n", report.critical_events));
323-
csv.push_str(&format!("Integrity Verified,{}\n", report.integrity_verified));
324-
csv.push_str(&format!("Integrity Failures,{}\n", report.integrity_failures));
314+
csv.push_str(&format!(
315+
"Integrity Verified,{}\n",
316+
report.integrity_verified
317+
));
318+
csv.push_str(&format!(
319+
"Integrity Failures,{}\n",
320+
report.integrity_failures
321+
));
325322
csv.push_str(&format!("Total Findings,{}\n", report.findings.len()));
326323
csv
327324
}

src/formats.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! SIEM export formats (CEF, LEEF, Syslog)
22
33
use crate::entry::{LogEntry, SecurityLevel};
4-
use chrono::Utc;
54

65
/// Common Event Format (CEF) - ArcSight standard
76
pub struct CEFFormatter;
@@ -30,7 +29,7 @@ impl CEFFormatter {
3029
}
3130

3231
if let Some(ref meta) = entry.metadata {
33-
extensions.push(format!("cs1={}", meta.to_string()));
32+
extensions.push(format!("cs1={}", meta));
3433
extensions.push("cs1Label=metadata".to_string());
3534
}
3635

@@ -87,7 +86,7 @@ impl LEEFFormatter {
8786
}
8887

8988
if let Some(ref meta) = entry.metadata {
90-
fields.push(format!("usrName={}", meta.to_string()));
89+
fields.push(format!("usrName={}", meta));
9190
}
9291

9392
format!(
@@ -128,7 +127,10 @@ impl SyslogFormatter {
128127

129128
// Structured data
130129
let structured_data = if let Some(ref meta) = entry.metadata {
131-
format!("[metadata@32473 data=\"{}\"]", meta.to_string().replace('"', "\\\""))
130+
format!(
131+
"[metadata@32473 data=\"{}\"]",
132+
meta.to_string().replace('"', "\\\"")
133+
)
132134
} else {
133135
"-".to_string()
134136
};
@@ -151,11 +153,11 @@ impl SyslogFormatter {
151153
// Facility: 16 (local use 0)
152154
// Severity mapping
153155
let severity = match level {
154-
SecurityLevel::Info => 6, // Informational
155-
SecurityLevel::Warning => 4, // Warning
156+
SecurityLevel::Info => 6, // Informational
157+
SecurityLevel::Warning => 4, // Warning
156158
SecurityLevel::SecurityEvent => 2, // Critical
157-
SecurityLevel::Critical => 1, // Alert
158-
SecurityLevel::Audit => 5, // Notice
159+
SecurityLevel::Critical => 1, // Alert
160+
SecurityLevel::Audit => 5, // Notice
159161
};
160162
(16 * 8) + severity
161163
}

0 commit comments

Comments
 (0)