41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
import threading
|
|
|
|
from flask import Blueprint, current_app, jsonify, request
|
|
|
|
from api.http_client import create_client
|
|
from runner import run_tests, get_status, load_config, save_config
|
|
|
|
bp = Blueprint("api", __name__)
|
|
|
|
|
|
@bp.route("/api/run", methods=["POST"])
|
|
def api_run():
|
|
token = current_app.config["NUBES_API_TOKEN"]
|
|
result = create_client(token, current_app.config["NUBES_API_ENDPOINT"])
|
|
if not result:
|
|
return jsonify({"error": "Не удалось определить стенд"}), 500
|
|
client, endpoint = result
|
|
t = threading.Thread(
|
|
target=run_tests,
|
|
args=(endpoint, token),
|
|
daemon=True,
|
|
)
|
|
t.start()
|
|
return jsonify({"ok": True})
|
|
|
|
|
|
@bp.route("/api/status")
|
|
def api_status():
|
|
return jsonify(get_status() or {})
|
|
|
|
|
|
@bp.route("/api/config", methods=["GET"])
|
|
def api_config_get():
|
|
return jsonify(load_config())
|
|
|
|
|
|
@bp.route("/api/config", methods=["POST"])
|
|
def api_config_save():
|
|
save_config(request.get_json())
|
|
return jsonify({"ok": True})
|