diff --git a/src/server/web/api.rs b/src/server/web/api.rs index 8939857..4c17ed5 100644 --- a/src/server/web/api.rs +++ b/src/server/web/api.rs @@ -12,6 +12,7 @@ use axum::{ }; use sqlx::SqlitePool; use time::OffsetDateTime; +use tracing::debug; use crate::{ config::Config, @@ -24,7 +25,7 @@ use crate::{ }; async fn post_status( - TypedHeader(auth): TypedHeader>, + auth: Option>>, State(config): State<&'static Config>, State(db): State, State(bench_repo): State>, @@ -62,6 +63,8 @@ async fn post_status( let abort_work = guard.should_abort_work(&name); drop(guard); + // TODO Insert finished work into DB + // Find new work let work = if let Some(hash) = work { let bench = match bench_repo { @@ -78,14 +81,16 @@ async fn post_status( None }; + debug!("Received status update from {name}"); Ok(Json(ServerResponse { work, abort_work }).into_response()) } pub fn router(server: &Server) -> Router { if server.repo.is_none() { - return Router::new().route("/api/runner/status", post(post_status)); + return Router::new(); } - // TODO Add routes - Router::new() + // TODO Get repo tar + // TODO Get bench repo tar + Router::new().route("/api/runner/status", post(post_status)) } diff --git a/src/server/web/api/auth.rs b/src/server/web/api/auth.rs index bf32fb0..03ee919 100644 --- a/src/server/web/api/auth.rs +++ b/src/server/web/api/auth.rs @@ -3,6 +3,7 @@ use axum::{ headers::{authorization::Basic, Authorization}, http::{header, HeaderValue, StatusCode}, response::Response, + TypedHeader, }; use crate::config::Config; @@ -23,10 +24,12 @@ fn is_password_valid(password: &str, config: &'static Config) -> bool { pub fn authenticate( config: &'static Config, - auth: Authorization, + auth: Option>>, ) -> Result { - if is_username_valid(auth.username()) && is_password_valid(auth.password(), config) { - return Ok(auth.username().to_string()); + if let Some(auth) = auth { + if is_username_valid(auth.username()) && is_password_valid(auth.password(), config) { + return Ok(auth.username().to_string()); + } } Err(( diff --git a/src/shared.rs b/src/shared.rs index 262229a..35b4e04 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -23,7 +23,7 @@ pub struct Measurement { } #[derive(Clone, Serialize, Deserialize)] -#[serde(rename = "snake_case")] +#[serde(rename_all = "snake_case")] #[serde(tag = "type")] pub enum Line { Stdout(String), @@ -41,7 +41,7 @@ pub struct FinishedRun { } #[derive(Clone, Serialize, Deserialize)] -#[serde(rename = "snake_case")] +#[serde(rename_all = "snake_case")] #[serde(tag = "type")] pub enum RunnerStatus { /// The runner is not performing any work. @@ -74,6 +74,7 @@ pub struct RunnerRequest { /// /// If the server has a commit available, it should respond with a non-null /// [`Response::work`]. + #[serde(default)] pub request_work: bool, /// The runner has finished a run and wants to submit the results. @@ -81,7 +82,7 @@ pub struct RunnerRequest { } #[derive(Clone, Serialize, Deserialize)] -#[serde(rename = "snake_case")] +#[serde(rename_all = "snake_case")] #[serde(tag = "type")] pub enum BenchMethod { /// Use internal (deterministic) benchmarking code.