| 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 InvokeDarktraceRequest(BaseModel): |
| 8 | customer_code: str = Field( |
| 9 | ..., |
| 10 | description="The customer code.", |
| 11 | examples=["00002"], |
| 12 | ) |
| 13 | integration_name: str = Field( |
| 14 | "Darktrace", |
| 15 | description="The integration name.", |
| 16 | examples=["Darktrace"], |
| 17 | ) |
| 18 | |
| 19 | |
| 20 | class DarktraceAuthKeys(BaseModel): |
| 21 | PUBLIC_TOKEN: str = Field( |
| 22 | ..., |
| 23 | description="The API key.", |
| 24 | examples=["123456"], |
| 25 | ) |
| 26 | PRIVATE_TOKEN: str = Field( |
| 27 | ..., |
| 28 | description="The integration key.", |
| 29 | examples=["123456"], |
| 30 | ) |
| 31 | HOST: str = Field( |
| 32 | ..., |
| 33 | description="The secret key.", |
| 34 | examples=["123456"], |
| 35 | ) |
| 36 | PORT: str = Field( |
| 37 | ..., |
| 38 | description="The secret key.", |
| 39 | examples=["123456"], |
| 40 | ) |
| 41 | |
| 42 | |
| 43 | class InvokeDarktraceResponse(BaseModel): |
| 44 | success: bool = Field( |
| 45 | ..., |
| 46 | description="The success status.", |
| 47 | examples=[True], |
| 48 | ) |
| 49 | message: str = Field( |
| 50 | ..., |
| 51 | description="The message.", |
| 52 | examples=["Darktrace Events collected successfully."], |
| 53 | ) |
| 54 | |
| 55 | |
| 56 | class CollectDarktrace(BaseModel): |
| 57 | integration: str = Field(..., examples=["darktrace"]) |
| 58 | customer_code: str = Field(..., examples=["socfortress"]) |
| 59 | graylog_host: str = Field(..., examples=["127.0.0.1"]) |
| 60 | graylog_port: str = Field(..., examples=[12201]) |
| 61 | public_token: str = Field(..., examples=["public_token"]) |
| 62 | private_token: str = Field(..., examples=["private_token"]) |
| 63 | darktrace_host: str = Field(..., examples=["https://darktrace.local"]) |
| 64 | darktrace_port: str = Field(..., examples=[2026]) |
| 65 | timeframe: str = Field(..., examples=["15m"]) |
| 66 | |
| 67 | @field_validator("integration") |
| 68 | @classmethod |
| 69 | def check_integration(cls, v): |
| 70 | if v != "darktrace": |
| 71 | raise HTTPException( |
| 72 | status_code=400, |
| 73 | detail="Invalid integration. Only 'darktrace' is supported.", |
| 74 | ) |
| 75 | return v |
| 76 | |
| 77 | @field_validator("timeframe") |
| 78 | @classmethod |
| 79 | def validate_range(cls, v): |
| 80 | if not v.endswith(("m", "h", "d")): |
| 81 | raise HTTPException( |
| 82 | status_code=400, |
| 83 | detail="Invalid range. Use 'm' for minutes, 'h' for hours, or 'd' for days.", |
| 84 | ) |
| 85 | return v |