| 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 ConfigDict |
| 8 | from pydantic import Field |
| 9 | from pydantic import model_validator |
| 10 | |
| 11 | |
| 12 | class ProvisionDarktraceRequest(BaseModel): |
| 13 | customer_code: str = Field( |
| 14 | ..., |
| 15 | description="The customer code.", |
| 16 | examples=["00002"], |
| 17 | ) |
| 18 | time_interval: int = Field( |
| 19 | 15, |
| 20 | description="The time interval for the scheduler.", |
| 21 | examples=[15], |
| 22 | ) |
| 23 | integration_name: str = Field( |
| 24 | "Darktrace", |
| 25 | description="The integration name.", |
| 26 | examples=["Darktrace"], |
| 27 | ) |
| 28 | |
| 29 | # ensure the `integration_name` is always set to "Mimecast" |
| 30 | @model_validator(mode="before") |
| 31 | @classmethod |
| 32 | def set_integration_name(cls, values: Dict[str, Any]) -> Dict[str, Any]: |
| 33 | values["integration_name"] = "Darktrace" |
| 34 | return values |
| 35 | |
| 36 | |
| 37 | class ProvisionDarktraceResponse(BaseModel): |
| 38 | success: bool |
| 39 | message: str |
| 40 | |
| 41 | |
| 42 | # ! STREAMS ! # |
| 43 | class StreamRule(BaseModel): |
| 44 | field: str |
| 45 | type: int |
| 46 | inverted: bool |
| 47 | value: str |
| 48 | |
| 49 | |
| 50 | class DarktraceEventStream(BaseModel): |
| 51 | title: str = Field(..., description="Title of the stream") |
| 52 | description: str = Field(..., description="Description of the stream") |
| 53 | index_set_id: str = Field(..., description="ID of the associated index set") |
| 54 | rules: List[StreamRule] = Field(..., description="List of rules for the stream") |
| 55 | matching_type: str = Field(..., description="Matching type for the rules") |
| 56 | remove_matches_from_default_stream: bool = Field( |
| 57 | ..., |
| 58 | description="Whether to remove matches from the default stream", |
| 59 | ) |
| 60 | content_pack: Optional[str] = Field( |
| 61 | None, |
| 62 | description="Associated content pack, if any", |
| 63 | ) |
| 64 | model_config = ConfigDict( |
| 65 | json_schema_extra={ |
| 66 | "example": { |
| 67 | "title": "Darktrace SIEM EVENTS - Example Company", |
| 68 | "description": "Darktrace SIEM EVENTS - Example Company", |
| 69 | "index_set_id": "12345", |
| 70 | "rules": [ |
| 71 | { |
| 72 | "field": "customer_code", |
| 73 | "type": 1, |
| 74 | "inverted": False, |
| 75 | "value": "ExampleCode", |
| 76 | }, |
| 77 | { |
| 78 | "field": "integration", |
| 79 | "type": 1, |
| 80 | "inverted": False, |
| 81 | "value": "darktrace", |
| 82 | }, |
| 83 | ], |
| 84 | "matching_type": "AND", |
| 85 | "remove_matches_from_default_stream": True, |
| 86 | "content_pack": None, |
| 87 | }, |
| 88 | }, |
| 89 | ) |