| 1 | import datetime |
| 2 | from typing import List |
| 3 | from typing import Optional |
| 4 | |
| 5 | from sqlmodel import Field |
| 6 | from sqlmodel import Relationship |
| 7 | from sqlmodel import SQLModel |
| 8 | |
| 9 | |
| 10 | class FlaggedRule(SQLModel, table=True): |
| 11 | id: Optional[int] = Field(default=None, primary_key=True) |
| 12 | rule_id: str |
| 13 | name: str |
| 14 | severity: Optional[str] = Field( |
| 15 | None, |
| 16 | description="Severity level of the flagged rule", |
| 17 | ) |
| 18 | tags: str |
| 19 | sublime_alert_id: int = Field(foreign_key="sublimealerts.id") |
| 20 | |
| 21 | # Relationship attribute |
| 22 | sublime_alert: "SublimeAlerts" = Relationship(back_populates="flagged_rules") |
| 23 | |
| 24 | |
| 25 | class Mailbox(SQLModel, table=True): |
| 26 | id: Optional[int] = Field(default=None, primary_key=True) |
| 27 | external_id: Optional[str] = Field( |
| 28 | None, |
| 29 | description="External identifier for the mailbox", |
| 30 | ) |
| 31 | mailbox_id: str |
| 32 | sublime_alert_id: int = Field(foreign_key="sublimealerts.id") |
| 33 | |
| 34 | # Relationship attribute |
| 35 | sublime_alert: "SublimeAlerts" = Relationship(back_populates="mailbox") |
| 36 | |
| 37 | |
| 38 | class TriggeredAction(SQLModel, table=True): |
| 39 | id: Optional[int] = Field(default=None, primary_key=True) |
| 40 | action_id: str |
| 41 | name: str |
| 42 | type: str |
| 43 | sublime_alert_id: int = Field(foreign_key="sublimealerts.id") |
| 44 | |
| 45 | # Relationship attribute |
| 46 | sublime_alert: "SublimeAlerts" = Relationship(back_populates="triggered_actions") |
| 47 | |
| 48 | |
| 49 | class Sender(SQLModel, table=True): |
| 50 | id: Optional[int] = Field(default=None, primary_key=True) |
| 51 | email: str |
| 52 | name: Optional[str] = Field(None, description="Name of the sender") |
| 53 | sublime_alert_id: int = Field(foreign_key="sublimealerts.id") |
| 54 | |
| 55 | # Relationship attribute |
| 56 | sublime_alert: "SublimeAlerts" = Relationship(back_populates="sender") |
| 57 | |
| 58 | |
| 59 | class Recipient(SQLModel, table=True): |
| 60 | id: Optional[int] = Field(default=None, primary_key=True) |
| 61 | email: str |
| 62 | name: Optional[str] = Field(None, description="Name of the recipient") |
| 63 | sublime_alert_id: int = Field(foreign_key="sublimealerts.id") |
| 64 | |
| 65 | # Relationship attribute |
| 66 | sublime_alert: "SublimeAlerts" = Relationship(back_populates="recipients") |
| 67 | |
| 68 | |
| 69 | class SublimeAlerts(SQLModel, table=True): |
| 70 | id: Optional[int] = Field(default=None, primary_key=True) |
| 71 | api_version: str |
| 72 | created_at: str |
| 73 | event_id: str |
| 74 | type: str |
| 75 | message_id: str |
| 76 | canonical_id: str |
| 77 | external_id: str |
| 78 | message_source_id: str |
| 79 | timestamp: datetime.datetime = datetime.datetime.now() |
| 80 | |
| 81 | flagged_rules: List[FlaggedRule] = Relationship(back_populates="sublime_alert") |
| 82 | mailbox: List[Mailbox] = Relationship(back_populates="sublime_alert") |
| 83 | triggered_actions: List[TriggeredAction] = Relationship( |
| 84 | back_populates="sublime_alert", |
| 85 | ) |
| 86 | sender: List[Sender] = Relationship(back_populates="sublime_alert") |
| 87 | recipients: List[Recipient] = Relationship(back_populates="sublime_alert") |