style: Apply rustfmt with stable-only config
Some checks failed
CI Pipeline / Clippy Lints (push) Failing after 0s
CI Pipeline / Rust Unit Tests (push) Failing after 0s
CI Pipeline / Rust Format Check (push) Successful in 4s
CI Pipeline / Frontend Lint & Type Check (push) Failing after 0s
CI Pipeline / Security Audit (push) Failing after 3s
CI Pipeline / Build .deb & Release (push) Has been skipped
Some checks failed
CI Pipeline / Clippy Lints (push) Failing after 0s
CI Pipeline / Rust Unit Tests (push) Failing after 0s
CI Pipeline / Rust Format Check (push) Successful in 4s
CI Pipeline / Frontend Lint & Type Check (push) Failing after 0s
CI Pipeline / Security Audit (push) Failing after 3s
CI Pipeline / Build .deb & Release (push) Has been skipped
- Fixed rustfmt.toml to only use stable options (removed nightly-only) - Applied cargo fmt --all to fix formatting violations - Stable options: edition=2021, max_width=100, reorder_imports/modules, match_block_trailing_comma
This commit is contained in:
@ -101,8 +101,15 @@ pub async fn log_event(
|
||||
request_id: Option<&str>,
|
||||
) {
|
||||
let result = write_audit_row(
|
||||
pool, action, actor_user_id, actor_username,
|
||||
target_type, target_id, details, ip_address, request_id,
|
||||
pool,
|
||||
action,
|
||||
actor_user_id,
|
||||
actor_username,
|
||||
target_type,
|
||||
target_id,
|
||||
details,
|
||||
ip_address,
|
||||
request_id,
|
||||
)
|
||||
.await;
|
||||
|
||||
@ -123,11 +130,10 @@ async fn write_audit_row(
|
||||
request_id: Option<&str>,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
// Fetch previous hash for chain
|
||||
let prev_hash: Option<String> = sqlx::query_scalar(
|
||||
"SELECT row_hash FROM audit_log ORDER BY id DESC LIMIT 1",
|
||||
)
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
let prev_hash: Option<String> =
|
||||
sqlx::query_scalar("SELECT row_hash FROM audit_log ORDER BY id DESC LIMIT 1")
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
|
||||
let prev = prev_hash.unwrap_or_default();
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
@ -245,7 +251,7 @@ pub async fn verify_integrity(pool: &PgPool) -> IntegrityResult {
|
||||
rows_checked: 0,
|
||||
errors: vec![],
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let mut errors = Vec::new();
|
||||
@ -273,10 +279,7 @@ pub async fn verify_integrity(pool: &PgPool) -> IntegrityResult {
|
||||
.unwrap_or_default();
|
||||
let ip_str = row.ip_address.as_deref().unwrap_or("");
|
||||
let rid = row.request_id.as_deref().unwrap_or("");
|
||||
let created_str = row
|
||||
.created_at
|
||||
.map(|c| c.to_rfc3339())
|
||||
.unwrap_or_default();
|
||||
let created_str = row.created_at.map(|c| c.to_rfc3339()).unwrap_or_default();
|
||||
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(row.prev_hash.as_bytes());
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use config::{Config, ConfigError, Environment, File};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Top-level application configuration.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::config::DatabaseConfig;
|
||||
use sqlx::postgres::{PgPool, PgPoolOptions};
|
||||
use std::time::Duration;
|
||||
use crate::config::DatabaseConfig;
|
||||
|
||||
/// Initialize and return a PostgreSQL connection pool.
|
||||
pub async fn init_pool(cfg: &DatabaseConfig) -> Result<PgPool, sqlx::Error> {
|
||||
@ -59,11 +59,9 @@ pub async fn run_migrations(pool: &PgPool) -> Result<(), sqlx::migrate::MigrateE
|
||||
/// Check that the database schema is at the expected version.
|
||||
/// Used by the worker to wait until migrations have been applied.
|
||||
pub async fn check_schema_version(pool: &PgPool) -> Result<i64, sqlx::Error> {
|
||||
let row: (i64,) = sqlx::query_as(
|
||||
"SELECT COUNT(*) FROM _sqlx_migrations WHERE success = true",
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
let row: (i64,) = sqlx::query_as("SELECT COUNT(*) FROM _sqlx_migrations WHERE success = true")
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
|
||||
Ok(row.0)
|
||||
}
|
||||
|
||||
@ -86,9 +86,11 @@ impl IntoResponse for AppError {
|
||||
AppError::Forbidden(msg) => (StatusCode::FORBIDDEN, "forbidden", msg.clone()),
|
||||
AppError::BadRequest(msg) => (StatusCode::BAD_REQUEST, "bad_request", msg.clone()),
|
||||
AppError::Conflict(msg) => (StatusCode::CONFLICT, "conflict", msg.clone()),
|
||||
AppError::UnprocessableEntity(msg) => {
|
||||
(StatusCode::UNPROCESSABLE_ENTITY, "unprocessable_entity", msg.clone())
|
||||
}
|
||||
AppError::UnprocessableEntity(msg) => (
|
||||
StatusCode::UNPROCESSABLE_ENTITY,
|
||||
"unprocessable_entity",
|
||||
msg.clone(),
|
||||
),
|
||||
AppError::Database(e) => {
|
||||
tracing::error!(error = %e, "Database error");
|
||||
(
|
||||
@ -96,7 +98,7 @@ impl IntoResponse for AppError {
|
||||
"internal_error",
|
||||
"An internal error occurred".to_string(),
|
||||
)
|
||||
}
|
||||
},
|
||||
AppError::Internal(e) => {
|
||||
tracing::error!(error = %e, "Internal error");
|
||||
(
|
||||
@ -104,7 +106,7 @@ impl IntoResponse for AppError {
|
||||
"internal_error",
|
||||
"An internal error occurred".to_string(),
|
||||
)
|
||||
}
|
||||
},
|
||||
AppError::Config(msg) => {
|
||||
tracing::error!(error = %msg, "Configuration error");
|
||||
(
|
||||
@ -112,7 +114,7 @@ impl IntoResponse for AppError {
|
||||
"config_error",
|
||||
"Server configuration error".to_string(),
|
||||
)
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let body = ErrorResponse::new(code, message);
|
||||
|
||||
@ -1,20 +1,19 @@
|
||||
pub mod audit;
|
||||
pub mod config;
|
||||
pub mod db;
|
||||
pub mod error;
|
||||
pub mod logging;
|
||||
pub mod models;
|
||||
pub mod audit;
|
||||
pub mod request_id;
|
||||
|
||||
// Re-export commonly used types
|
||||
pub use error::{AppError, ErrorResponse};
|
||||
pub use config::AppConfig;
|
||||
pub use error::{AppError, ErrorResponse};
|
||||
pub use models::{
|
||||
Host, HostSummary, HostHealthStatus, CreateHostRequest,
|
||||
Group, CreateGroupRequest, UpdateGroupRequest,
|
||||
User, UserRole as DbUserRole, AuthProvider, CreateUserRequest, UpdateUserRequest,
|
||||
DiscoveryResult, DiscoveryCidrRequest, RegisterDiscoveredRequest,
|
||||
AuthProvider, CreateGroupRequest, CreateHostRequest, CreateUserRequest, DiscoveryCidrRequest,
|
||||
DiscoveryResult, Group, Host, HostHealthStatus, HostSummary, RegisterDiscoveredRequest,
|
||||
UpdateGroupRequest, UpdateUserRequest, User, UserRole as DbUserRole,
|
||||
};
|
||||
|
||||
// Re-export audit integrity types
|
||||
pub use audit::{verify_integrity, IntegrityResult, IntegrityError};
|
||||
pub use audit::{verify_integrity, IntegrityError, IntegrityResult};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||
use crate::config::LoggingConfig;
|
||||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||
|
||||
/// Initialize the global tracing subscriber.
|
||||
///
|
||||
@ -10,8 +10,7 @@ use crate::config::LoggingConfig;
|
||||
/// Log level is controlled by `cfg.level` (e.g. `"info"`, `"debug"`).
|
||||
/// The `RUST_LOG` environment variable overrides `cfg.level`.
|
||||
pub fn init(cfg: &LoggingConfig) {
|
||||
let filter = EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| EnvFilter::new(&cfg.level));
|
||||
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&cfg.level));
|
||||
|
||||
match cfg.format.as_str() {
|
||||
"json" => {
|
||||
@ -19,13 +18,13 @@ pub fn init(cfg: &LoggingConfig) {
|
||||
.with(filter)
|
||||
.with(fmt::layer().json().with_current_span(true))
|
||||
.init();
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
tracing_subscriber::registry()
|
||||
.with(filter)
|
||||
.with(fmt::layer().pretty())
|
||||
.init();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
tracing::info!(format = %cfg.format, level = %cfg.level, "Logging initialized");
|
||||
|
||||
@ -211,11 +211,11 @@ pub enum JobStatus {
|
||||
impl std::fmt::Display for JobStatus {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Queued => write!(f, "queued"),
|
||||
Self::Pending => write!(f, "pending"),
|
||||
Self::Running => write!(f, "running"),
|
||||
Self::Queued => write!(f, "queued"),
|
||||
Self::Pending => write!(f, "pending"),
|
||||
Self::Running => write!(f, "running"),
|
||||
Self::Succeeded => write!(f, "succeeded"),
|
||||
Self::Failed => write!(f, "failed"),
|
||||
Self::Failed => write!(f, "failed"),
|
||||
Self::Cancelled => write!(f, "cancelled"),
|
||||
}
|
||||
}
|
||||
@ -321,9 +321,9 @@ pub enum WindowRecurrence {
|
||||
impl std::fmt::Display for WindowRecurrence {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Once => write!(f, "once"),
|
||||
Self::Daily => write!(f, "daily"),
|
||||
Self::Weekly => write!(f, "weekly"),
|
||||
Self::Once => write!(f, "once"),
|
||||
Self::Daily => write!(f, "daily"),
|
||||
Self::Weekly => write!(f, "weekly"),
|
||||
Self::Monthly => write!(f, "monthly"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
use axum::{
|
||||
extract::Request,
|
||||
http::HeaderValue,
|
||||
middleware::Next,
|
||||
response::Response,
|
||||
};
|
||||
use axum::{extract::Request, http::HeaderValue, middleware::Next, response::Response};
|
||||
use ulid::Ulid;
|
||||
|
||||
/// HTTP header name for request correlation IDs.
|
||||
|
||||
Reference in New Issue
Block a user