Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,28 @@ def get_dashboard_task(task_id: str, database_manager: DatabaseManager = Depends
return task_to_task_info(task)


@app.delete(
"/v1/dashboard/tasks/{task_id}",
response_model=Message,
tags=["dashboard"],
)
def cancel_dashboard_task(
task_id: str,
crs_client: CRSClient = Depends(get_crs_client),
) -> Message | Error:
"""Cancel a task by forwarding a DELETE request to the task server."""
logger.info(f"Dashboard: cancelling task {task_id}")
response = crs_client.cancel_task(task_id)
if response.success:
return Message(
message=f"Task {task_id} cancellation requested",
color="success",
)
error_msg = response.get_user_friendly_error_message()
logger.error(f"Failed to cancel task {task_id}: {error_msg}")
return Error(message=f"Failed to cancel task: {error_msg}")


@app.get("/v1/dashboard/tasks/{task_id}/crs-status", tags=["dashboard"])
def get_task_crs_status(task_id: str, database_manager: DatabaseManager = Depends(get_database_manager)) -> dict:
"""Get detailed CRS submission status and error information for a specific task"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,44 @@ def submit_task(self, task: Task) -> CRSResponse:
logger.error(f"Error submitting task to CRS: {e}")
return CRSResponse(success=False, status_code=0, response_text=str(e), error_details={"exception": str(e)})

def cancel_task(self, task_id: str) -> CRSResponse:
"""Cancel a task by sending a DELETE request to the CRS.

Args:
task_id: UUID of the task to cancel

Returns:
CRSResponse object with detailed status and error information

"""
url = f"{self.crs_base_url}/v1/task/{task_id}/"

auth = None
if self.username and self.password:
auth = (self.username, self.password)

try:
logger.info(f"Cancelling task {task_id} via CRS at {url}")

response = requests.delete(
url,
auth=auth,
timeout=30,
)

crs_response = CRSResponse.from_response(response)
crs_response.log_detailed_response(logger, f"Task cancellation for {task_id}")
return crs_response

except Exception as e:
logger.error(f"Error cancelling task via CRS: {e}")
return CRSResponse(
success=False,
status_code=0,
response_text=str(e),
error_details={"exception": str(e)},
)

def submit_sarif_broadcast(self, broadcast: SARIFBroadcast) -> CRSResponse:
"""Submit a SARIF Broadcast to the CRS via POST /v1/sarif/ endpoint"""
url = f"{self.crs_base_url}/v1/sarif/"
Expand Down
34 changes: 34 additions & 0 deletions orchestrator/src/buttercup/orchestrator/ui/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<h1 class="nav-title">Buttercup CRS Dashboard</h1>
<div class="nav-buttons">
<button id="submit-task-btn" class="btn btn-primary">Submit Task</button>
<button id="submit-sarif-btn" class="btn btn-primary">Submit SARIF</button>
<button id="refresh-btn" class="btn btn-secondary">Refresh</button>
</div>
</div>
Expand Down Expand Up @@ -66,6 +67,7 @@ <h2>Tasks</h2>
<option value="active">Active</option>
<option value="expired">Expired</option>
<option value="failed">Failed</option>
<option value="cancelled">Cancelled</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -155,6 +157,8 @@ <h2>Submit New Task</h2>
placeholder="1800">
</div>
<div class="form-buttons">
<input type="file" id="load-json-input" accept=".json" style="display: none;">
<button type="button" id="load-json-btn" class="btn btn-secondary">Load from JSON</button>
<button type="button" id="fill-example-btn" class="btn btn-success">Fill example-libpng Values</button>
<button type="button" id="cancel-btn" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-primary">Submit Task</button>
Expand All @@ -176,6 +180,36 @@ <h2 id="detail-title">Task Details</h2>
</div>
</div>

<!-- SARIF Upload Modal -->
<div id="sarif-modal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Submit SARIF File</h2>
<span class="close" id="close-sarif-modal">&times;</span>
</div>
<form id="sarif-form">
<div class="form-group">
<label for="sarif-task-select">Task:</label>
<select id="sarif-task-select" required>
<option value="">Select a task...</option>
</select>
</div>
<div class="form-group">
<label for="sarif-file-input">SARIF File (.sarif or .json):</label>
<input type="file" id="sarif-file-input" accept=".sarif,.json" required>
</div>
<div id="sarif-preview" class="form-group" style="display: none;">
<label>Preview:</label>
<pre id="sarif-preview-content" style="max-height: 200px; overflow: auto; background: var(--bg-secondary); padding: 0.75rem; border-radius: 6px; font-size: 0.8rem;"></pre>
</div>
<div class="form-buttons">
<button type="button" id="cancel-sarif-btn" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-primary">Submit SARIF</button>
</div>
</form>
</div>
</div>

<!-- Notifications container -->
<div id="notifications"></div>

Expand Down
Loading
Loading