Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion tasky/src/handler/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub async fn handle_create_multipart(
db: &mut DB,
mut assignment: Assignment,
) -> Result<Assignment, ApiError> {
// TODO: Validate runner config
validate_runner_config(&form.runner_config)?;

let mut file_structure = form.file_structure.0;
if !file_structure_contains_files(&file_structure) {
return Err(ApiError::BadRequest {
Expand Down Expand Up @@ -87,6 +88,8 @@ pub async fn handle_update_multipart(
db: &mut DB,
mut assignment: Assignment,
) -> Result<Assignment, ApiError> {
validate_runner_config(&form.runner_config)?;

let mut new_file_structure = form.file_structure.0;
if !file_structure_contains_files(&new_file_structure) {
return Err(ApiError::BadRequest {
Expand Down Expand Up @@ -176,3 +179,23 @@ async fn create_files_and_update_ids(
file.object_id = Some(mongo_files.get(i).unwrap().to_hex());
}
}

/// Validates the runner config
fn validate_runner_config(config: &RunnerData) -> Result<(), ApiError> {
if ![".5", "1"].contains(&config.runner_cpu.as_str()) {
return Err(ApiError::BadRequest {
message: "You entered an unallowed CPU value".to_string(),
});
}
if !["50m", "100m", "200m", "300m", "500m"].contains(&config.runner_memory.as_str()) {
return Err(ApiError::BadRequest {
message: "You entered an unallowed memory value".to_string(),
});
}
if !["20s", "60s", "120s", "180s", "240s", "300s"].contains(&config.runner_timeout.as_str()) {
return Err(ApiError::BadRequest {
message: "You entered an unallowed timeout value".to_string(),
});
}
Ok(())
}