Configuration for an encryption key.
| 11 | |
| 12 | |
| 13 | class EncryptionKey(BaseModel): |
| 14 | """Configuration for an encryption key.""" |
| 15 | |
| 16 | id: str = Field(default_factory=lambda: base62.encodebytes(os.urandom(32))) |
| 17 | key: SecretStr |
| 18 | active: bool = True |
| 19 | notes: str | None = None |
| 20 | created_at: datetime.datetime = Field(default_factory=utc_now) |
| 21 | |
| 22 | @field_serializer('key') |
| 23 | def serialize_key(self, key: SecretStr, info: Any): |
| 24 | """Conditionally serialize the key based on context.""" |
| 25 | if info.context and info.context.get('expose_secrets'): |
| 26 | return key.get_secret_value() |
| 27 | return str(key) # Returns '**********' by default |
| 28 | |
| 29 | |
| 30 | def get_default_encryption_keys(workspace_dir: Path) -> list[EncryptionKey]: |
no outgoing calls