""" SSH Key Pydantic schemas. """ from typing import Optional from pydantic import BaseModel, Field, field_validator class SshKeyCreate(BaseModel): """ Schema for creating a new SSH key. """ name: str = Field(..., min_length=1, max_length=100, description="SSH key name") private_key: str = Field(..., min_length=1, description="SSH private key content") @field_validator("name") @classmethod def name_must_not_be_empty(cls, v: str) -> str: """Validate that name is not empty or whitespace only.""" if not v or not v.strip(): raise ValueError("name must not be empty") return v.strip() @field_validator("private_key") @classmethod def private_key_must_not_be_empty(cls, v: str) -> str: """Validate that private_key is not empty or whitespace only.""" if not v or not v.strip(): raise ValueError("private_key must not be empty") return v.strip() model_config = { "json_schema_extra": { "examples": [ { "name": "my-git-key", "private_key": "-----BEGIN OPENSSH PRIVATE KEY-----\n...\n-----END OPENSSH PRIVATE KEY-----" } ] } } class SshKeyResponse(BaseModel): """ Schema for SSH key response. """ id: int = Field(description="SSH key ID") name: str = Field(description="SSH key name") fingerprint: Optional[str] = Field(default=None, description="SSH key fingerprint") created_at: int = Field(description="Creation timestamp (Unix timestamp)") model_config = { "json_schema_extra": { "examples": [ { "id": 1, "name": "my-git-key", "fingerprint": "SHA256:abc123...", "created_at": 1711804800 } ] } }