Skip to content

Commit

Permalink
feat(rest): add flag submission endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLE committed Oct 6, 2024
1 parent b300c79 commit 55ed551
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/kriger_common/src/models/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ use serde::{Deserialize, Serialize};
pub struct FlagHintQuery {
pub service: String,
}

#[derive(Serialize, Deserialize)]
pub struct FlagSubmitRequest {
pub flags: Vec<String>,
}
1 change: 1 addition & 0 deletions crates/kriger_rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub async fn main(runtime: AppRuntime, config: Config) -> eyre::Result<()> {
"/exploits/:name/execute",
post(routes::exploits::execute_exploit),
)
.route("/flags", post(routes::flags::submit_flags))
.route(
"/competition/services",
get(routes::competition::get_services),
Expand Down
28 changes: 28 additions & 0 deletions crates/kriger_rest/src/routes/flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::support::{AppError, AppJson};
use crate::AppState;
use axum::response::IntoResponse;
use axum::{extract::State, Json};
use kriger_common::messaging::model;
use kriger_common::models;
use std::sync::Arc;

pub(crate) async fn submit_flags(
state: State<Arc<AppState>>,
AppJson(request): AppJson<models::requests::FlagSubmitRequest>,
) -> Result<impl IntoResponse, AppError> {
let flags_svc = state.runtime.messaging.flags();

// FIXME: Probably parallelize this, but whatever
for flag in request.flags {
flags_svc
.submit_flag(&model::FlagSubmission {
flag,
team_id: None,
service: None,
exploit: None,
})
.await?;
}

Ok(Json(models::responses::AppResponse::Ok(())))
}
1 change: 1 addition & 0 deletions crates/kriger_rest/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub(crate) mod competition;
pub(crate) mod config;
pub(crate) mod exploits;
pub(crate) mod flags;

0 comments on commit 55ed551

Please sign in to comment.