Skip to content

Commit

Permalink
shuffle integrations start
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorwalton committed Mar 28, 2024
1 parent 41ad992 commit cebf0c3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/app/connectors/shuffle/routes/integrations.py
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions backend/app/connectors/shuffle/schema/integrations.py
Original file line number Diff line number Diff line change
@@ -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,
)
24 changes: 24 additions & 0 deletions backend/app/connectors/shuffle/services/integrations.py
Original file line number Diff line number Diff line change
@@ -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}")
7 changes: 7 additions & 0 deletions backend/app/routers/shuffle.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -11,3 +12,9 @@
prefix="/workflows",
tags=["shuffle-workflows"],
)

router.include_router(
shuffle_integrations_router,
prefix="/shuffle/integrations",
tags=["shuffle-integrations"],
)

0 comments on commit cebf0c3

Please sign in to comment.