Fix clippy warnings: remove unused imports/variables/functions, derive Default, fix comparisons
This commit is contained in:
@ -12,9 +12,9 @@ use serde::{Deserialize, Serialize};
|
||||
use tracing::{error, info, warn};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::jobs::manager::{Job, JobManager, JobOperation, JobStatus};
|
||||
use crate::jobs::manager::{Job, JobManager, JobStatus};
|
||||
|
||||
use super::packages::{ApiResponse, JobResponseData};
|
||||
use super::packages::ApiResponse;
|
||||
|
||||
/// Job list response data
|
||||
#[derive(Debug, Serialize)]
|
||||
@ -110,7 +110,7 @@ pub async fn list_jobs(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
|
||||
let status_filter = query.status.as_ref().and_then(|s| parse_job_status(s));
|
||||
let limit = query.limit.unwrap_or(50);
|
||||
@ -141,7 +141,7 @@ pub async fn get_job(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
let job_id_str = path.into_inner();
|
||||
|
||||
info!(request_id = %request_id, job_id = %job_id_str, "Getting job details");
|
||||
@ -185,7 +185,7 @@ pub async fn rollback_job(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
let job_id_str = path.into_inner();
|
||||
|
||||
info!(request_id = %request_id, job_id = %job_id_str, "Initiating job rollback");
|
||||
@ -253,7 +253,7 @@ pub async fn delete_job(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
let job_id_str = path.into_inner();
|
||||
|
||||
info!(request_id = %request_id, job_id = %job_id_str, "Deleting job from history");
|
||||
|
||||
@ -7,13 +7,13 @@
|
||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||
use chrono::Utc;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::{error, info, warn};
|
||||
use tracing::{error, info};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::jobs::manager::{JobManager, JobOperation, JobStatus};
|
||||
use crate::packages::PackageManagerBackend;
|
||||
|
||||
use super::packages::{ApiError, ApiResponse, JobResponseData};
|
||||
use super::packages::{ApiResponse, JobResponseData};
|
||||
|
||||
/// Patch list response data
|
||||
#[derive(Debug, Serialize)]
|
||||
@ -41,7 +41,7 @@ pub async fn list_patches(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
|
||||
info!(request_id = %request_id, "Listing available patches");
|
||||
|
||||
@ -84,7 +84,7 @@ pub async fn apply_patches(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
let packages_count = body.packages.as_ref().map(|p| p.len()).unwrap_or(0);
|
||||
|
||||
info!(
|
||||
|
||||
@ -8,40 +8,15 @@
|
||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||
use chrono::Utc;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::{error, info, warn};
|
||||
use tracing::{error, info};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::packages::{ApiResponse, JobResponseData};
|
||||
use super::packages::ApiResponse;
|
||||
use crate::jobs::manager::{JobManager, JobOperation, JobStatus};
|
||||
use crate::packages::PackageManagerBackend;
|
||||
|
||||
/// Normalize and validate file paths to prevent path traversal attacks (VULN-002)
|
||||
/// Returns None if path contains traversal patterns
|
||||
fn normalize_path(path: &str) -> Option<String> {
|
||||
// Reject obvious traversal patterns
|
||||
if path.contains("..") || path.contains("//") {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Decode common URL-encoded traversal attempts
|
||||
let decoded = path
|
||||
.replace("%2e", ".")
|
||||
.replace("%2E", ".")
|
||||
.replace("%2f", "/")
|
||||
.replace("%2F", "/")
|
||||
.replace("%5c", "\\")
|
||||
.replace("%5C", "\\");
|
||||
|
||||
// Check decoded path for traversal
|
||||
if decoded.contains("..") || decoded.contains("//") || decoded.contains("\\") {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Ensure path starts with expected prefix or is relative
|
||||
Some(path.to_string())
|
||||
}
|
||||
|
||||
/// Validate path input for traversal attacks
|
||||
fn validate_path_no_traversal(path: &str) -> bool {
|
||||
normalize_path(path).is_some()
|
||||
}
|
||||
@ -82,7 +57,7 @@ pub async fn get_system_info(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
|
||||
info!(request_id = %request_id, "Getting system information");
|
||||
|
||||
@ -116,8 +91,8 @@ pub async fn get_system_info(
|
||||
|
||||
/// Health check endpoint
|
||||
pub async fn health_check(_req: HttpRequest) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _request_id = Uuid::new_v4().to_string();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
|
||||
// Calculate uptime from /proc/uptime
|
||||
let uptime_seconds = std::fs::read_to_string("/proc/uptime")
|
||||
@ -150,7 +125,7 @@ pub async fn reboot_system(
|
||||
_req: HttpRequest,
|
||||
) -> impl Responder {
|
||||
let request_id = Uuid::new_v4().to_string();
|
||||
let timestamp = Utc::now().to_rfc3339();
|
||||
let _timestamp = Utc::now().to_rfc3339();
|
||||
let delay = body.delay_seconds;
|
||||
let force = body.force;
|
||||
|
||||
|
||||
@ -2,11 +2,10 @@
|
||||
//!
|
||||
//! Aggregates all endpoint routes and configures the Actix-web application.
|
||||
|
||||
use actix_web::{http::Method, web, HttpResponse};
|
||||
use actix_web::{web, HttpResponse};
|
||||
use tracing::info;
|
||||
|
||||
use crate::jobs::manager::JobManager;
|
||||
use crate::packages::create_backend;
|
||||
|
||||
use super::handlers::{jobs, packages, patches, system, websocket};
|
||||
|
||||
|
||||
@ -3,12 +3,11 @@
|
||||
//! Provides mutual TLS authentication middleware for Actix-web.
|
||||
//! Non-mTLS connections are silently dropped (no response).
|
||||
|
||||
use actix_web::http::header;
|
||||
use actix_web::{
|
||||
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
|
||||
Error, HttpMessage,
|
||||
};
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use chrono::{DateTime, Utc};
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
use rustls::{
|
||||
server::{ServerConfig, WebPkiClientVerifier},
|
||||
@ -19,9 +18,8 @@ use std::{
|
||||
fs::File,
|
||||
io::BufReader,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tracing::{debug, info, warn};
|
||||
use tracing::{info, warn};
|
||||
|
||||
/// Check for duplicate critical headers (VULN-006)
|
||||
/// Returns true if duplicate headers are detected
|
||||
@ -275,7 +273,7 @@ where
|
||||
|
||||
// All checks passed - call the service
|
||||
let fut = self.service.call(req);
|
||||
Box::pin(async move { fut.await })
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::Duration;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
/// Whitelist entry types
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
@ -193,7 +193,7 @@ impl WhitelistManager {
|
||||
/// Set up file watcher for auto-reload
|
||||
fn setup_watcher(&mut self) -> Result<()> {
|
||||
let config_path = self.config_path.clone();
|
||||
let entries = self.entries.clone();
|
||||
let _entries = self.entries.clone();
|
||||
|
||||
let watcher = RecommendedWatcher::new(
|
||||
move |res: Result<Event, notify::Error>| {
|
||||
|
||||
@ -203,7 +203,7 @@ mod tests {
|
||||
let result = AppConfig::load("tests/fixtures/valid_config.yaml");
|
||||
assert!(result.is_ok());
|
||||
let config = result.unwrap();
|
||||
assert!(config.server.port >= 1 && config.server.port <= 65535);
|
||||
assert!(config.server.port >= 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::process::Command;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use tracing::{info, warn};
|
||||
|
||||
/// Package status
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
@ -33,20 +33,12 @@ pub struct Package {
|
||||
}
|
||||
|
||||
/// Package installation options
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct InstallOptions {
|
||||
pub force: bool,
|
||||
pub no_recommends: bool,
|
||||
}
|
||||
|
||||
impl Default for InstallOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
force: false,
|
||||
no_recommends: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Patch information
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -191,7 +183,7 @@ impl PackageManagerBackend for AptBackend {
|
||||
// Check if installed
|
||||
let dpkg_output = self.run_dpkg(&["-s", name]);
|
||||
|
||||
if let Err(_) = dpkg_output {
|
||||
if dpkg_output.is_err() {
|
||||
// Package not installed, check if available
|
||||
let list_output = self.run_apt(&["list", name])?;
|
||||
if list_output.contains(name) {
|
||||
@ -227,7 +219,7 @@ impl PackageManagerBackend for AptBackend {
|
||||
let mut status = PackageStatus::Installed;
|
||||
let mut description = String::new();
|
||||
let mut dependencies = Vec::new();
|
||||
let mut install_date = None;
|
||||
let install_date = None;
|
||||
let mut size_installed = None;
|
||||
|
||||
for line in dpkg_info.lines() {
|
||||
@ -244,7 +236,7 @@ impl PackageManagerBackend for AptBackend {
|
||||
.trim_start_matches("Depends:")
|
||||
.trim()
|
||||
.split(',')
|
||||
.map(|s| s.trim().split_whitespace().next().unwrap_or("").to_string())
|
||||
.map(|s| s.split_whitespace().next().unwrap_or("").to_string())
|
||||
.collect();
|
||||
} else if line.starts_with("Installed-Size:") {
|
||||
size_installed = Some(format!(
|
||||
@ -507,8 +499,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_apt_backend_creation() {
|
||||
let backend = AptBackend::new();
|
||||
assert!(std::path::Path::new("/usr/bin/apt").exists() || true); // Test passes regardless
|
||||
let _backend = AptBackend::new();
|
||||
assert!(true); // Test passes regardless
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user