chore: rustfmt the workspace and make clippy -D warnings pass

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 19:19:21 +07:00
parent d7fe99edd7
commit f13f0e6953
46 changed files with 6606 additions and 1496 deletions

View File

@@ -12,7 +12,8 @@ use base64::Engine;
use sha2::{Digest, Sha256};
use std::{net::SocketAddr, pin::Pin, time::Duration};
use tessera_core::job::{
CaptureEvent, CaptureFormat, CaptureJob, CaptureLease, CaptureProfile, CaptureReport, ResticCaptureCommit,
CaptureEvent, CaptureFormat, CaptureJob, CaptureLease, CaptureProfile, CaptureReport,
ResticCaptureCommit,
};
use tessera_core::{restore::DatabaseIdentity, SnapshotManifest};
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
@@ -42,7 +43,12 @@ async fn profiles(
let actor = authenticate(&state, peer, &headers, false)?;
let visible = super::gate::visible(&state, &actor, Permission::OrbitRead)?;
let profiles = state.db.capture_profiles().map_err(internal)?;
Ok(Json(profiles.into_iter().filter(|profile| visible.contains(profile.orbit_id)).collect()))
Ok(Json(
profiles
.into_iter()
.filter(|profile| visible.contains(profile.orbit_id))
.collect(),
))
}
async fn register_profile(
@@ -120,7 +126,10 @@ async fn history(
let actor = authenticate(&state, peer, &headers, false)?;
let visible = super::gate::visible(&state, &actor, Permission::OrbitRead)?;
if let Some(application) = filter.application_id {
let orbit = state.db.orbit_of_application(application).map_err(internal)?;
let orbit = state
.db
.orbit_of_application(application)
.map_err(internal)?;
if !orbit.is_some_and(|orbit| visible.contains(orbit)) {
return Err(StatusCode::NOT_FOUND);
}
@@ -145,7 +154,11 @@ async fn history(
}
/// A capture job, if the caller may read its orbit; otherwise 404.
fn job_in_scope(state: &HubState, actor: &super::routes::OperatorActor, id: Uuid) -> Result<CaptureJob, StatusCode> {
fn job_in_scope(
state: &HubState,
actor: &super::routes::OperatorActor,
id: Uuid,
) -> Result<CaptureJob, StatusCode> {
let job = state.db.capture_job(id).map_err(internal)?;
match job {
Some(job) => {
@@ -186,10 +199,18 @@ async fn claim(
Path(application): Path<Uuid>,
) -> Result<Json<Option<CaptureLease>>, StatusCode> {
let outpost = outpost(&state, &headers)?;
let mut lease = state.db.claim_capture(outpost, application, now()).map_err(internal)?;
let mut lease = state
.db
.claim_capture(outpost, application, now())
.map_err(internal)?;
if let Some(lease) = &mut lease {
lease.restic |= lease.profile.format == CaptureFormat::Filesystem
|| state.vault.read().await.outpost_repository_configured(lease.profile.orbit_id).map_err(internal)?;
|| state
.vault
.read()
.await
.outpost_repository_configured(lease.profile.orbit_id)
.map_err(internal)?;
}
Ok(Json(lease))
}
@@ -227,8 +248,16 @@ async fn upload(
.map_err(internal)?
.ok_or(StatusCode::CONFLICT)?;
if job.profile.format == CaptureFormat::Filesystem
|| state.db.restic_required(job.profile.orbit_id).map_err(internal)?
|| state.vault.read().await.outpost_repository_configured(job.profile.orbit_id).map_err(internal)?
|| state
.db
.restic_required(job.profile.orbit_id)
.map_err(internal)?
|| state
.vault
.read()
.await
.outpost_repository_configured(job.profile.orbit_id)
.map_err(internal)?
{
return Err(StatusCode::CONFLICT);
}
@@ -240,7 +269,12 @@ async fn upload(
.map_err(|_| StatusCode::BAD_REQUEST)?;
let identity: DatabaseIdentity =
serde_json::from_slice(&decoded).map_err(|_| StatusCode::BAD_REQUEST)?;
if !job.profile.format.engine().is_some_and(|engine| identity.valid(engine)) {
if !job
.profile
.format
.engine()
.is_some_and(|engine| identity.valid(engine))
{
return Err(StatusCode::BAD_REQUEST);
}
Ok(identity)
@@ -301,16 +335,23 @@ async fn commit_restic(
Json(commit): Json<ResticCaptureCommit>,
) -> Result<Json<serde_json::Value>, StatusCode> {
let outpost = outpost(&state, &headers)?;
let job = state.db.capture_upload(outpost, id, commit.lease_id, now())
.map_err(internal)?.ok_or(StatusCode::CONFLICT)?;
let job = state
.db
.capture_upload(outpost, id, commit.lease_id, now())
.map_err(internal)?
.ok_or(StatusCode::CONFLICT)?;
if let Some(snapshot) = job.snapshot_id {
return Ok(Json(serde_json::json!({ "snapshot_id": snapshot })));
}
let engine = job.profile.format.engine();
if commit.identity.as_ref().is_some_and(|identity| !engine.is_some_and(|engine| identity.valid(engine)))
|| (engine.is_some() && !commit.sha256.as_ref().is_some_and(|hash| {
hash.len() == 64 && hash.bytes().all(|byte| byte.is_ascii_hexdigit())
}))
if commit
.identity
.as_ref()
.is_some_and(|identity| !engine.is_some_and(|engine| identity.valid(engine)))
|| (engine.is_some()
&& !commit.sha256.as_ref().is_some_and(|hash| {
hash.len() == 64 && hash.bytes().all(|byte| byte.is_ascii_hexdigit())
}))
|| (engine.is_none() && commit.sha256.is_some())
{
return Err(StatusCode::BAD_REQUEST);
@@ -328,7 +369,11 @@ async fn commit_restic(
}
Ok(())
})
}).await.map_err(internal)?.map_err(internal)?.ok_or(StatusCode::CONFLICT)?;
})
.await
.map_err(internal)?
.map_err(internal)?
.ok_or(StatusCode::CONFLICT)?;
if created && state.prune_orbit(orbit_id).await.is_err() {
tracing::warn!(%id, %orbit_id, "could not apply capture retention");
}
@@ -437,10 +482,27 @@ pub(super) fn outpost(state: &HubState, headers: &HeaderMap) -> Result<Uuid, Sta
use crate::auth::{AuditAction, AuditOutcome, AuditResource, Principal};
let result = authenticate_outpost(state, headers);
let (actor, resource, outcome) = match result {
Ok(id) => (Principal::Outpost(id), AuditResource::Outpost(id), AuditOutcome::Allowed),
Err(_) => (Principal::Anonymous, AuditResource::Api, AuditOutcome::Denied),
Ok(id) => (
Principal::Outpost(id),
AuditResource::Outpost(id),
AuditOutcome::Allowed,
),
Err(_) => (
Principal::Anonymous,
AuditResource::Api,
AuditOutcome::Denied,
),
};
state.db.audit_event(&actor, AuditAction::Authentication, resource, outcome, Uuid::new_v4()).map_err(internal)?;
state
.db
.audit_event(
&actor,
AuditAction::Authentication,
resource,
outcome,
Uuid::new_v4(),
)
.map_err(internal)?;
result
}