shuffle integrations start
Taylor committed
Mar 28, 2024 at 16:52 UTC
cebf0c30a648dde0065a7897ae8600ab5a3e4807
4 files changed
+85
backend/app/connectors/shuffle/routes/integrations.py
new
+28
@@ -0,0 +1,28 @@
1
+from fastapi import APIRouter
2
+from fastapi import HTTPException
3
+from fastapi import Security
4
+from loguru import logger
5
+
6
+from app.auth.utils import AuthHandler
7
+from app.connectors.shuffle.schema.integrations import IntegrationRequest
8
+from app.connectors.shuffle.services.integrations import execute_integration
9
+
10
+shuffle_integrations_router = APIRouter()
11
+
12
+@shuffle_integrations_router.post(
13
+ "/execute",
14
+ description="Execute a Shuffle Integration.",
15
+ dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))],
16
+)
17
+async def execute_integration_route(request: IntegrationRequest):
18
+ """
19
+ Execute a workflow.
20
+
21
+ Args:
22
+ request (IntegrationRequest): The request object containing the workflow ID.
23
+
24
+ Returns:
25
+ dict: The response containing the execution ID.
26
+ """
27
+ logger.info("Executing workflow")
28
+ return await execute_integration(request)
backend/app/connectors/shuffle/schema/integrations.py
new
+26
@@ -0,0 +1,26 @@
1
+from typing import Any
2
+from typing import Dict
3
+from typing import List
4
+from typing import Optional
5
+
6
+from pydantic import BaseModel
7
+from pydantic import Field
8
+
9
+class IntegrationRequest(BaseModel):
10
+ app_name: str = Field(..., description="The name of the application", example="PagerDuty")
11
+ category: str = Field(..., description="The category of the application", example="cases")
12
+ label: str = Field(..., description="The label of the application", example="create_ticket")
13
+ fields: Optional[List[Dict[str, Any]]] = Field(
14
+ [],
15
+ description="The fields of the application",
16
+ example=[
17
+ {"key": "title", "value": "This is the title"},
18
+ {"key": "description", "value": "This is the description"},
19
+ {"key": "source", "value": "Shuffle"},
20
+ ],
21
+ )
22
+ skip_workflow: Optional[bool] = Field(
23
+ False,
24
+ description="Skip the workflow",
25
+ example=True,
26
+ )
backend/app/connectors/shuffle/services/integrations.py
new
+24
@@ -0,0 +1,24 @@
1
+import asyncio
2
+from typing import List
3
+
4
+from fastapi import HTTPException
5
+from loguru import logger
6
+
7
+from app.connectors.shuffle.schema.integrations import IntegrationRequest
8
+from app.connectors.shuffle.utils.universal import send_get_request
9
+from app.connectors.shuffle.utils.universal import send_post_request
10
+
11
+
12
+async def execute_integration(request: IntegrationRequest) -> dict:
13
+ """
14
+ Execute a workflow.
15
+
16
+ Args:
17
+ request (IntegrationRequest): The request object containing the workflow ID.
18
+
19
+ Returns:
20
+ dict: The response containing the execution ID.
21
+ """
22
+ logger.info(f"Executing integration: {request}")
23
+ response = await send_post_request("/api/v1/apps/categories/run", request.dict())
24
+ logger.info(f"Integration executed: {response}")
backend/app/routers/shuffle.py
+7
@@ -1,6 +1,7 @@
1
from fastapi import APIRouter
2
3
from app.connectors.shuffle.routes.workflows import shuffle_workflows_router
4
+from app.connectors.shuffle.routes.integrations import shuffle_integrations_router
5
6
# Instantiate the APIRouter
7
router = APIRouter()
@@ -11,3 +12,9 @@ router.include_router(
12
prefix="/workflows",
13
tags=["shuffle-workflows"],
14
)
15
+
16
+router.include_router(
17
+ shuffle_integrations_router,
18
+ prefix="/shuffle/integrations",
19
+ tags=["shuffle-integrations"],
20
+)