diff --git a/backend/app/connectors/shuffle/routes/integrations.py b/backend/app/connectors/shuffle/routes/integrations.py new file mode 100644 index 00000000..15339da5 --- /dev/null +++ b/backend/app/connectors/shuffle/routes/integrations.py @@ -0,0 +1,28 @@ +from fastapi import APIRouter +from fastapi import HTTPException +from fastapi import Security +from loguru import logger + +from app.auth.utils import AuthHandler +from app.connectors.shuffle.schema.integrations import IntegrationRequest +from app.connectors.shuffle.services.integrations import execute_integration + +shuffle_integrations_router = APIRouter() + +@shuffle_integrations_router.post( + "/execute", + description="Execute a Shuffle Integration.", + dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], +) +async def execute_integration_route(request: IntegrationRequest): + """ + Execute a workflow. + + Args: + request (IntegrationRequest): The request object containing the workflow ID. + + Returns: + dict: The response containing the execution ID. + """ + logger.info("Executing workflow") + return await execute_integration(request) diff --git a/backend/app/connectors/shuffle/schema/integrations.py b/backend/app/connectors/shuffle/schema/integrations.py new file mode 100644 index 00000000..506d51a2 --- /dev/null +++ b/backend/app/connectors/shuffle/schema/integrations.py @@ -0,0 +1,26 @@ +from typing import Any +from typing import Dict +from typing import List +from typing import Optional + +from pydantic import BaseModel +from pydantic import Field + +class IntegrationRequest(BaseModel): + app_name: str = Field(..., description="The name of the application", example="PagerDuty") + category: str = Field(..., description="The category of the application", example="cases") + label: str = Field(..., description="The label of the application", example="create_ticket") + fields: Optional[List[Dict[str, Any]]] = Field( + [], + description="The fields of the application", + example=[ + {"key": "title", "value": "This is the title"}, + {"key": "description", "value": "This is the description"}, + {"key": "source", "value": "Shuffle"}, + ], + ) + skip_workflow: Optional[bool] = Field( + False, + description="Skip the workflow", + example=True, + ) diff --git a/backend/app/connectors/shuffle/services/integrations.py b/backend/app/connectors/shuffle/services/integrations.py new file mode 100644 index 00000000..3056dcf0 --- /dev/null +++ b/backend/app/connectors/shuffle/services/integrations.py @@ -0,0 +1,24 @@ +import asyncio +from typing import List + +from fastapi import HTTPException +from loguru import logger + +from app.connectors.shuffle.schema.integrations import IntegrationRequest +from app.connectors.shuffle.utils.universal import send_get_request +from app.connectors.shuffle.utils.universal import send_post_request + + +async def execute_integration(request: IntegrationRequest) -> dict: + """ + Execute a workflow. + + Args: + request (IntegrationRequest): The request object containing the workflow ID. + + Returns: + dict: The response containing the execution ID. + """ + logger.info(f"Executing integration: {request}") + response = await send_post_request("/api/v1/apps/categories/run", request.dict()) + logger.info(f"Integration executed: {response}") diff --git a/backend/app/routers/shuffle.py b/backend/app/routers/shuffle.py index b833dc48..575230e2 100644 --- a/backend/app/routers/shuffle.py +++ b/backend/app/routers/shuffle.py @@ -1,6 +1,7 @@ from fastapi import APIRouter from app.connectors.shuffle.routes.workflows import shuffle_workflows_router +from app.connectors.shuffle.routes.integrations import shuffle_integrations_router # Instantiate the APIRouter router = APIRouter() @@ -11,3 +12,9 @@ prefix="/workflows", tags=["shuffle-workflows"], ) + +router.include_router( + shuffle_integrations_router, + prefix="/shuffle/integrations", + tags=["shuffle-integrations"], +)