| 1 | from fastapi import HTTPException |
| 2 | from pydantic import BaseModel |
| 3 | from pydantic import Field |
| 4 | from pydantic import field_validator |
| 5 | |
| 6 | |
| 7 | class InvokeCatoRequest(BaseModel): |
| 8 | customer_code: str = Field( |
| 9 | ..., |
| 10 | description="The customer code.", |
| 11 | examples=["00002"], |
| 12 | ) |
| 13 | # ! CASE SENSITIVE ! # |
| 14 | integration_name: str = Field( |
| 15 | "CATO", |
| 16 | description="The integration name.", |
| 17 | examples=["CATO"], |
| 18 | ) |
| 19 | |
| 20 | |
| 21 | class CatoAuthKeys(BaseModel): |
| 22 | API_KEY: str = Field( |
| 23 | ..., |
| 24 | description="The API key.", |
| 25 | examples=["123456"], |
| 26 | ) |
| 27 | ACCOUNT_ID: int = Field( |
| 28 | ..., |
| 29 | description="The account ID.", |
| 30 | examples=[123456], |
| 31 | ) |
| 32 | EVENT_TYPES: str = Field( |
| 33 | ..., |
| 34 | description="The event types.", |
| 35 | examples=["Security"], |
| 36 | ) |
| 37 | EVENT_SUB_TYPES: str = Field( |
| 38 | ..., |
| 39 | description="The event sub types.", |
| 40 | examples=["NG Anti Malware,Anti Malware,IPS"], |
| 41 | ) |
| 42 | |
| 43 | |
| 44 | class InvokeCatoResponse(BaseModel): |
| 45 | success: bool = Field( |
| 46 | ..., |
| 47 | description="The success status.", |
| 48 | examples=[True], |
| 49 | ) |
| 50 | message: str = Field( |
| 51 | ..., |
| 52 | description="The message.", |
| 53 | examples=["cato Events collected successfully."], |
| 54 | ) |
| 55 | |
| 56 | |
| 57 | class CollectCato(BaseModel): |
| 58 | integration: str = Field(..., examples=["cato"]) |
| 59 | customer_code: str = Field(..., examples=["socfortress"]) |
| 60 | graylog_host: str = Field(..., examples=["127.0.0.1"]) |
| 61 | graylog_port: str = Field(..., examples=[12201]) |
| 62 | api_key: str = Field(..., examples=["1234567890"]) |
| 63 | account_id: int = Field(..., examples=[123456]) |
| 64 | event_types: str = Field(..., examples=["Security"]) |
| 65 | event_sub_types: str = Field(..., examples=["NG Anti Malware,Anti Malware,IPS"]) |
| 66 | |
| 67 | @field_validator("integration") |
| 68 | @classmethod |
| 69 | def check_integration(cls, v): |
| 70 | if v != "cato": |
| 71 | raise HTTPException( |
| 72 | status_code=400, |
| 73 | detail="Invalid integration. Only 'cato' is supported.", |
| 74 | ) |
| 75 | return v |