Refactor database layer and auditing
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
"""Settings management."""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Any
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic import Field
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
SettingsConfigDict,
|
||||
ForceDecode,
|
||||
)
|
||||
from sqlalchemy import URL
|
||||
|
||||
@ -22,24 +20,19 @@ class BackendSettings(BaseSettings):
|
||||
)
|
||||
|
||||
database: str = Field(default=DEFAULT_DATABASE)
|
||||
generate_initial_tokens: Annotated[bool, ForceDecode] = Field(default=False)
|
||||
|
||||
@field_validator("generate_initial_tokens", mode="before")
|
||||
@classmethod
|
||||
def cast_bool(cls, value: Any) -> bool:
|
||||
"""Ensure we catch the boolean."""
|
||||
if isinstance(value, str):
|
||||
if value.lower() in ("1", "true", "on"):
|
||||
return True
|
||||
if value.lower() in ("0", "false", "off"):
|
||||
return False
|
||||
return bool(value)
|
||||
admin_token: str | None = Field(default=None, alias="sshecret_admin_backend_token")
|
||||
sshd_token: str | None = Field(default=None, alias="sshecret_sshd_backend_token")
|
||||
|
||||
@property
|
||||
def db_url(self) -> URL:
|
||||
"""Construct database url."""
|
||||
return URL.create(drivername="sqlite", database=self.database)
|
||||
|
||||
@property
|
||||
def async_db_url(self) -> URL:
|
||||
"""Construct database url with sync handling."""
|
||||
return URL.create(drivername="sqlite+aiosqlite", database=self.database)
|
||||
|
||||
@property
|
||||
def db_exists(self) -> bool:
|
||||
"""Check if databatase exists."""
|
||||
|
||||
Reference in New Issue
Block a user