Create shuffle.py
taylor_socfortress committed
Jul 10, 2023 at 16:41 UTC
a818beaf606db9bbbe5fa3cb54ee05a1b66a39d4
1 file changed
+50
backend/app/routes/shuffle.py
new
+50
@@ -0,0 +1,50 @@
1
+from flask import Blueprint, jsonify, request
2
+from loguru import logger
3
+from app.models.connectors import Connector, WazuhManagerConnector
4
+
5
+from app.services.agents.agents import AgentService, AgentSyncService
6
+from app.services.Shuffle.workflows import WorkflowsService
7
+
8
+bp = Blueprint("shuffle", __name__)
9
+
10
+
11
+@bp.route("/shuffle/workflows", methods=["GET"])
12
+def get_workflows():
13
+ """
14
+ Endpoint to list all available Shuffle workflows.
15
+
16
+ Returns:
17
+ json: A JSON response containing the list of all configured Workflows.
18
+ """
19
+ service = WorkflowsService()
20
+ workflows = service.collect_workflows()
21
+ return workflows
22
+
23
+@bp.route("/shuffle/workflows/executions", methods=["GET"])
24
+def get_workflows_executions():
25
+ """
26
+ Endpoint to list all available Shuffle workflow execution status.
27
+
28
+ Returns:
29
+ json: A JSON response containing the list of all configured workflows last execution status.
30
+ """
31
+ service = WorkflowsService()
32
+ workflow_details = service.collect_workflow_details()
33
+ if "workflows" not in workflow_details:
34
+ message = "No workflows found"
35
+ return jsonify({"message": message, "success": False}), 500
36
+ for workflow in workflow_details["workflows"]:
37
+ workflow["status"] = service.collect_workflow_executions_status(workflow["workflow_id"])
38
+ return workflow_details
39
+
40
+@bp.route("/shuffle/workflows/executions/<workflow_id>", methods=["GET"])
41
+def get_workflow_executions(workflow_id):
42
+ """
43
+ Endpoint to list execution status of a specified Shuffle workflow.
44
+
45
+ Returns:
46
+ json: A JSON response containing the last execution status of the specified workflow.
47
+ """
48
+ service = WorkflowsService()
49
+ workflow_details = service.collect_workflow_executions_status(workflow_id)
50
+ return workflow_details