You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
823 B
31 lines
823 B
from flask import Response
|
|
from flask import blueprints
|
|
from flask import request
|
|
from flask_api import status
|
|
|
|
from .command_execution import enqueue_command
|
|
from .commands import CommandId
|
|
from .commands import get_command_id_from_name
|
|
from .commands import get_request_class
|
|
|
|
bp = blueprints.Blueprint("command", __name__)
|
|
|
|
|
|
@bp.route("/command", methods=["POST", "GET"])
|
|
def command():
|
|
arguments = dict(request.args)
|
|
|
|
cmd = arguments.pop("cmd")
|
|
try:
|
|
command_id = CommandId(int(cmd))
|
|
except ValueError:
|
|
command_id = get_command_id_from_name(cmd)
|
|
|
|
try:
|
|
command = get_request_class(command_id=command_id)(**arguments)
|
|
except Exception:
|
|
return Response(status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
enqueue_command(command)
|
|
|
|
return Response(status=status.HTTP_200_OK)
|
|
|