- Replace subprocess.run() with Popen for cancellable processes - Add cancel() method to SneakyScanner with process termination - Track running scanners in registry for stop signal delivery - Handle ScanCancelledError to set scan status to 'cancelled' - Add POST /api/scans/<id>/stop endpoint - Add 'cancelled' as valid scan status - Add Stop button to scans list and detail views - Show cancelled status with warning badge in UI
32 lines
830 B
Python
32 lines
830 B
Python
"""
|
|
Input validation utilities for SneakyScanner web application.
|
|
|
|
Provides validation functions for API inputs and data integrity.
|
|
"""
|
|
|
|
from typing import Optional
|
|
|
|
|
|
def validate_scan_status(status: str) -> tuple[bool, Optional[str]]:
|
|
"""
|
|
Validate scan status value.
|
|
|
|
Args:
|
|
status: Status string to validate
|
|
|
|
Returns:
|
|
Tuple of (is_valid, error_message)
|
|
|
|
Examples:
|
|
>>> validate_scan_status('running')
|
|
(True, None)
|
|
>>> validate_scan_status('invalid')
|
|
(False, 'Invalid status: invalid. Must be one of: running, completed, failed')
|
|
"""
|
|
valid_statuses = ['running', 'completed', 'failed', 'cancelled']
|
|
|
|
if status not in valid_statuses:
|
|
return False, f'Invalid status: {status}. Must be one of: {", ".join(valid_statuses)}'
|
|
|
|
return True, None
|