treewide: format with nightly rustfmt; auto-fix Clippy lints

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I15d9215ab506b37954468d99746098326a6a6964
This commit is contained in:
raf 2026-02-08 02:15:06 +03:00
commit 73919f2f9e
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
30 changed files with 144 additions and 151 deletions

View file

@ -77,7 +77,7 @@ pub async fn require_api_key(
{
// Check session expiry (24 hours)
if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60)
< std::time::Duration::from_hours(24)
{
// Insert both user and session data
if let Some(ref user) = session.user {
@ -87,11 +87,10 @@ pub async fn require_api_key(
request.extensions_mut().insert(api_key.clone());
}
return Ok(next.run(request).await);
} else {
// Expired, remove it
drop(session);
state.sessions.remove(&session_id);
}
// Expired, remove it
drop(session);
state.sessions.remove(&session_id);
}
// Try legacy API key session (fc_session cookie)
@ -100,17 +99,16 @@ pub async fn require_api_key(
{
// Check session expiry (24 hours)
if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60)
< std::time::Duration::from_hours(24)
{
if let Some(ref api_key) = session.api_key {
request.extensions_mut().insert(api_key.clone());
}
return Ok(next.run(request).await);
} else {
// Expired, remove it
drop(session);
state.sessions.remove(&session_id);
}
// Expired, remove it
drop(session);
state.sessions.remove(&session_id);
}
}
@ -138,7 +136,7 @@ impl FromRequestParts<AppState> for RequireAdmin {
&& user.role == "admin"
{
// Create a synthetic API key for compatibility
return Ok(RequireAdmin(ApiKey {
return Ok(Self(ApiKey {
id: user.id,
name: user.username.clone(),
key_hash: String::new(),
@ -157,7 +155,7 @@ impl FromRequestParts<AppState> for RequireAdmin {
.ok_or(StatusCode::UNAUTHORIZED)?;
if key.role == "admin" {
Ok(RequireAdmin(key))
Ok(Self(key))
} else {
Err(StatusCode::FORBIDDEN)
}
@ -216,7 +214,7 @@ pub async fn extract_session(
.headers()
.get("cookie")
.and_then(|v| v.to_str().ok())
.map(|s| s.to_string());
.map(std::string::ToString::to_string);
if let Some(cookie_header) = cookie_header {
// Try user session first
@ -225,7 +223,7 @@ pub async fn extract_session(
{
// Check session expiry
if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60)
< std::time::Duration::from_hours(24)
{
if let Some(ref user) = session.user {
request.extensions_mut().insert(user.clone());
@ -245,7 +243,7 @@ pub async fn extract_session(
{
// Check session expiry
if session.created_at.elapsed()
< std::time::Duration::from_secs(24 * 60 * 60)
< std::time::Duration::from_hours(24)
{
if let Some(ref api_key) = session.api_key {
request.extensions_mut().insert(api_key.clone());

View file

@ -9,7 +9,7 @@ pub struct ApiError(pub CiError);
impl From<CiError> for ApiError {
fn from(err: CiError) -> Self {
ApiError(err)
Self(err)
}
}
@ -45,12 +45,11 @@ impl IntoResponse for ApiError {
StatusCode::INSUFFICIENT_STORAGE,
"DISK_FULL",
format!(
"{}\n\nDISK SPACE ISSUE DETECTED:\nThe server has run out of \
"{msg}\n\nDISK SPACE ISSUE DETECTED:\nThe server has run out of \
disk space. Please free up space:\n- Run `nix-collect-garbage \
-d` to clean the Nix store\n- Clear the evaluator work \
directory: `rm -rf /tmp/fc-evaluator/*`\n- Clear build logs if \
configured",
msg
configured"
),
)
} else {
@ -66,11 +65,10 @@ impl IntoResponse for ApiError {
StatusCode::INSUFFICIENT_STORAGE,
"DISK_FULL",
format!(
"{}\n\nDISK SPACE ISSUE:\nThe server is running low on disk \
"{msg}\n\nDISK SPACE ISSUE:\nThe server is running low on disk \
space. Please free up space:\n- Run `nix-collect-garbage -d` to \
clean the Nix store\n- Clear the evaluator work directory\n- \
Clear build logs if configured",
msg
Clear build logs if configured"
),
)
},
@ -92,9 +90,8 @@ impl IntoResponse for ApiError {
StatusCode::INSUFFICIENT_STORAGE,
"DISK_FULL",
format!(
"Database error: {}\n\nDISK SPACE ISSUE:\nThe server is running \
low on disk space.",
e
"Database error: {e}\n\nDISK SPACE ISSUE:\nThe server is running \
low on disk space."
),
)
} else {
@ -133,12 +130,11 @@ impl IntoResponse for ApiError {
StatusCode::INSUFFICIENT_STORAGE,
"DISK_FULL",
format!(
"IO error: {}\n\nDISK SPACE ISSUE DETECTED:\nThe server has run \
"IO error: {msg}\n\nDISK SPACE ISSUE DETECTED:\nThe server has run \
out of disk space. Please free up space:\n- Run \
`nix-collect-garbage -d` to clean the Nix store\n- Clear the \
evaluator work directory: `rm -rf /tmp/fc-evaluator/*`\n- \
Clear build logs if configured",
msg
Clear build logs if configured"
),
)
} else {
@ -160,9 +156,8 @@ impl IntoResponse for ApiError {
StatusCode::INSUFFICIENT_STORAGE,
"DISK_FULL",
format!(
"{}\n\nDISK SPACE ISSUE:\nThe server is running low on disk \
space. Please free up space.",
msg
"{msg}\n\nDISK SPACE ISSUE:\nThe server is running low on disk \
space. Please free up space."
),
)
} else {

View file

@ -29,6 +29,7 @@ pub struct ApiKeyInfo {
pub last_used_at: Option<chrono::DateTime<chrono::Utc>>,
}
#[must_use]
pub fn hash_api_key(key: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(key.as_bytes());

View file

@ -10,7 +10,7 @@ use tokio::process::Command;
use crate::{error::ApiError, state::AppState};
/// Serve NARInfo for a store path hash.
/// Serve `NARInfo` for a store path hash.
/// GET /nix-cache/{hash}.narinfo
async fn narinfo(
State(state): State<AppState>,
@ -68,7 +68,7 @@ async fn narinfo(
};
let nar_hash = entry.get("narHash").and_then(|v| v.as_str()).unwrap_or("");
let nar_size = entry.get("narSize").and_then(|v| v.as_u64()).unwrap_or(0);
let nar_size = entry.get("narSize").and_then(serde_json::Value::as_u64).unwrap_or(0);
let store_path = entry
.get("path")
.and_then(|v| v.as_str())

View file

@ -186,7 +186,9 @@ async fn compare_evaluations(
// Jobs in both: compare derivation paths
for (name, from_build) in &from_map {
if let Some(to_build) = to_map.get(name) {
if from_build.drv_path != to_build.drv_path {
if from_build.drv_path == to_build.drv_path {
unchanged_count += 1;
} else {
changed_jobs.push(JobChange {
job_name: name.to_string(),
system: to_build.system.clone(),
@ -195,8 +197,6 @@ async fn compare_evaluations(
old_status: format!("{:?}", from_build.status),
new_status: format!("{:?}", to_build.status),
});
} else {
unchanged_count += 1;
}
}
}

View file

@ -93,12 +93,9 @@ async fn stream_build_log(
if active_path.exists() { active_path.clone() } else { final_path.clone() }
};
let file = match tokio::fs::File::open(&path).await {
Ok(f) => f,
Err(_) => {
yield Ok(Event::default().data("Failed to open log file"));
return;
}
let file = if let Ok(f) = tokio::fs::File::open(&path).await { f } else {
yield Ok(Event::default().data("Failed to open log file"));
return;
};
let mut reader = BufReader::new(file);

View file

@ -130,7 +130,7 @@ async fn prometheus_metrics(State(state): State<AppState>) -> Response {
output
.push_str("\n# HELP fc_evaluations_total Total number of evaluations\n");
output.push_str("# TYPE fc_evaluations_total gauge\n");
output.push_str(&format!("fc_evaluations_total {}\n", eval_count));
output.push_str(&format!("fc_evaluations_total {eval_count}\n"));
output.push_str("\n# HELP fc_evaluations_by_status Evaluations by status\n");
output.push_str("# TYPE fc_evaluations_by_status gauge\n");

View file

@ -270,8 +270,7 @@ async fn github_callback(
""
};
let clear_state = format!(
"fc_oauth_state=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0{}",
secure_flag
"fc_oauth_state=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0{secure_flag}"
);
let session_cookie = format!(
"fc_user_session={}; HttpOnly; SameSite=Lax; Path=/; Max-Age={}{}",

View file

@ -130,8 +130,8 @@ struct SearchRequest {
eval_before: Option<DateTime<Utc>>,
// Sorting
/// Sort builds by: created_at, job_name, status, priority (default:
/// created_at)
/// Sort builds by: `created_at`, `job_name`, status, priority (default:
/// `created_at`)
#[serde(rename = "build_sort")]
build_sort: Option<String>,
@ -139,12 +139,12 @@ struct SearchRequest {
#[serde(rename = "order")]
order: Option<String>,
/// Sort projects by: name, created_at (default: name)
/// Sort projects by: name, `created_at` (default: name)
#[serde(rename = "project_sort")]
project_sort: Option<String>,
}
fn default_limit() -> i64 {
const fn default_limit() -> i64 {
20
}

View file

@ -45,7 +45,7 @@ pub struct UserResponse {
impl From<User> for UserResponse {
fn from(u: User) -> Self {
UserResponse {
Self {
id: u.id,
username: u.username,
email: u.email,

View file

@ -403,35 +403,32 @@ async fn handle_gitea_push(
.map_err(ApiError)?;
// Fall back to the other type if not found
let webhook_config = match webhook_config {
Some(c) => c,
None => {
let alt = if forge_type == "gitea" {
"forgejo"
} else {
"gitea"
};
match repo::webhook_configs::get_by_project_and_forge(
&state.pool,
project_id,
alt,
)
.await
.map_err(ApiError)?
{
Some(c) => c,
None => {
return Ok((
StatusCode::NOT_FOUND,
Json(WebhookResponse {
accepted: false,
message: "No Gitea/Forgejo webhook configured for this project"
.to_string(),
}),
));
},
}
},
let webhook_config = if let Some(c) = webhook_config { c } else {
let alt = if forge_type == "gitea" {
"forgejo"
} else {
"gitea"
};
match repo::webhook_configs::get_by_project_and_forge(
&state.pool,
project_id,
alt,
)
.await
.map_err(ApiError)?
{
Some(c) => c,
None => {
return Ok((
StatusCode::NOT_FOUND,
Json(WebhookResponse {
accepted: false,
message: "No Gitea/Forgejo webhook configured for this project"
.to_string(),
}),
));
},
}
};
// Verify signature if configured

View file

@ -17,6 +17,7 @@ pub struct SessionData {
impl SessionData {
/// Check if the session has admin role
#[must_use]
pub fn is_admin(&self) -> bool {
if let Some(ref user) = self.user {
user.role == "admin"
@ -28,6 +29,7 @@ impl SessionData {
}
/// Check if the session has a specific role
#[must_use]
pub fn has_role(&self, role: &str) -> bool {
if self.is_admin() {
return true;
@ -42,6 +44,7 @@ impl SessionData {
}
/// Get the display name for the session (username or api key name)
#[must_use]
pub fn display_name(&self) -> String {
if let Some(ref user) = self.user {
user.username.clone()
@ -53,7 +56,8 @@ impl SessionData {
}
/// Check if this is a user session (not just API key)
pub fn is_user_session(&self) -> bool {
#[must_use]
pub const fn is_user_session(&self) -> bool {
self.user.is_some()
}
}