Files
romm/backend/endpoints/tasks.py
Michael Manganiello beeb9f0c31 misc: Create enum for authorization scopes
Instead of using just strings, this change converts the scopes to a
`StrEnum`, to be compatible with places where a string is expected. This
avoids typos when using these scopes, simplifies searching for usages,
and improves type hints.

An extra change was the fix to the Firmware download endpoint, which
wasn't respecting the `DISABLE_DOWNLOAD_ENDPOINT_AUTH` flag.
2024-10-18 23:57:42 -03:00

39 lines
1.1 KiB
Python

from decorators.auth import protected_route
from endpoints.responses import MessageResponse
from fastapi import Request
from handler.auth.base_handler import Scope
from tasks.update_switch_titledb import update_switch_titledb_task
from utils.router import APIRouter
router = APIRouter()
@protected_route(router.post, "/tasks/run", [Scope.TASKS_RUN])
async def run_tasks(request: Request) -> MessageResponse:
"""Run all tasks endpoint
Args:
request (Request): Fastapi Request object
Returns:
RunTasksResponse: Standard message response
"""
await update_switch_titledb_task.run()
return {"msg": "All tasks ran successfully!"}
@protected_route(router.post, "/tasks/{task}/run", [Scope.TASKS_RUN])
async def run_task(request: Request, task: str) -> MessageResponse:
"""Run all tasks endpoint
Args:
request (Request): Fastapi Request object
Returns:
RunTasksResponse: Standard message response
"""
tasks = {"switch_titledb": update_switch_titledb_task}
await tasks[task].run()
return {"msg": f"Task {task} run successfully!"}