Spaces:
Sleeping
Sleeping
Mansi Dwivedi commited on
Commit ·
5592a41
1
Parent(s): 9469b45
mock executor logic fix
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import json
|
|
| 3 |
import uuid
|
| 4 |
import httpx
|
| 5 |
import asyncio
|
| 6 |
-
import requests
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
from flask import Flask, request, jsonify
|
| 9 |
from flask_jwt_extended import (
|
|
@@ -349,13 +348,15 @@ def execute_action(action_id):
|
|
| 349 |
f"Running runbook for {action['type']}",
|
| 350 |
)
|
| 351 |
|
| 352 |
-
#
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
|
|
|
|
|
|
| 356 |
)
|
| 357 |
|
| 358 |
-
if
|
| 359 |
action["status"] = "SUCCESS"
|
| 360 |
add_audit_log(
|
| 361 |
action["case_id"],
|
|
@@ -373,19 +374,30 @@ def execute_action(action_id):
|
|
| 373 |
|
| 374 |
|
| 375 |
# ---------------------------------------------------------
|
| 376 |
-
#
|
| 377 |
# ---------------------------------------------------------
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
def mock_executor():
|
| 381 |
-
data = request.json
|
| 382 |
import time
|
| 383 |
|
| 384 |
time.sleep(2)
|
| 385 |
print(
|
| 386 |
f"[MOCK EXECUTOR] Successfully applied {data.get('type')}: {data.get('action')}"
|
| 387 |
)
|
| 388 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
|
| 390 |
|
| 391 |
# ---------------------------------------------------------
|
|
|
|
| 3 |
import uuid
|
| 4 |
import httpx
|
| 5 |
import asyncio
|
|
|
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
from flask import Flask, request, jsonify
|
| 8 |
from flask_jwt_extended import (
|
|
|
|
| 348 |
f"Running runbook for {action['type']}",
|
| 349 |
)
|
| 350 |
|
| 351 |
+
# perform the mock execution directly rather than via HTTP
|
| 352 |
+
result, status_code = mock_executor_logic(
|
| 353 |
+
{
|
| 354 |
+
"action": action["action"],
|
| 355 |
+
"type": action["type"],
|
| 356 |
+
}
|
| 357 |
)
|
| 358 |
|
| 359 |
+
if status_code == 200 and result.get("status") == "OK":
|
| 360 |
action["status"] = "SUCCESS"
|
| 361 |
add_audit_log(
|
| 362 |
action["case_id"],
|
|
|
|
| 374 |
|
| 375 |
|
| 376 |
# ---------------------------------------------------------
|
| 377 |
+
# helper for mock execution logic (used by both the API handler and direct calls)
|
| 378 |
# ---------------------------------------------------------
|
| 379 |
+
def mock_executor_logic(data: dict):
|
| 380 |
+
"""Simulate performing an action. Returns tuple (response_dict, status_code)."""
|
|
|
|
|
|
|
| 381 |
import time
|
| 382 |
|
| 383 |
time.sleep(2)
|
| 384 |
print(
|
| 385 |
f"[MOCK EXECUTOR] Successfully applied {data.get('type')}: {data.get('action')}"
|
| 386 |
)
|
| 387 |
+
return {"status": "OK", "run_id": f"RUN-{uuid.uuid4().hex[:6]}"}, 200
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
# ---------------------------------------------------------
|
| 391 |
+
# 5. Mock HTTP Executor
|
| 392 |
+
# ---------------------------------------------------------
|
| 393 |
+
@app.route("/api/mock_executor", methods=["POST"])
|
| 394 |
+
@jwt_required()
|
| 395 |
+
def mock_executor():
|
| 396 |
+
# this route is retained for compatibility but now simply invokes the
|
| 397 |
+
# shared logic rather than duplicating it or being called by other
|
| 398 |
+
# endpoints.
|
| 399 |
+
result, status_code = mock_executor_logic(request.json or {})
|
| 400 |
+
return jsonify(result), status_code
|
| 401 |
|
| 402 |
|
| 403 |
# ---------------------------------------------------------
|