import datetime from typing import List from typing import Optional from sqlalchemy import LargeBinary from sqlmodel import Field from sqlmodel import Relationship from sqlmodel import SQLModel class DomainCertificateLink(SQLModel, table=True): fqdn: Optional[str] = Field(default=None, foreign_key="domain.fqdn", primary_key=True) fingerprint: Optional[str] = Field(default=None, foreign_key="certificate.fingerprint", primary_key=True) class Domain(SQLModel, table=True): fqdn: str = Field(primary_key=True) root: str tld: str certificates: Optional[List["Certificate"]] = Relationship( back_populates="domains", link_model=DomainCertificateLink ) class Certificate(SQLModel, table=True): fingerprint: str = Field(index=True, primary_key=True) version: int serial_number: str signature: bytes = Field(default_factory=LargeBinary) issuer: str not_valid_before: datetime.datetime not_valid_after: datetime.datetime subject: str subject_public_key_info: str raw_der_certificate: bytes = Field(default_factory=LargeBinary) domains: Optional[List[Domain]] = Relationship(back_populates="certificates", link_model=DomainCertificateLink)