Complete backend
This commit is contained in:
@ -1,26 +1,25 @@
|
||||
"""Settings management."""
|
||||
|
||||
import os
|
||||
from typing import override
|
||||
from pathlib import Path
|
||||
from pydantic import BaseModel
|
||||
from dotenv import load_dotenv
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
SettingsConfigDict,
|
||||
)
|
||||
|
||||
|
||||
DEFAULT_DATABASE = "sshecret.db"
|
||||
|
||||
|
||||
load_dotenv()
|
||||
class BackendSettings(BaseSettings):
|
||||
"""Backend settings."""
|
||||
|
||||
model_config = SettingsConfigDict(env_file=".backend.env", env_prefix="sshecret_")
|
||||
|
||||
class BackendSettings(BaseModel):
|
||||
"""Backend Settings."""
|
||||
|
||||
db_file: Path
|
||||
regenerate_tokens: bool = False
|
||||
db_file: Path = Field(default=Path(DEFAULT_DATABASE).absolute())
|
||||
|
||||
|
||||
def get_settings() -> BackendSettings:
|
||||
"""Get settings."""
|
||||
db_filename = os.getenv("SSHECRET_DATABASE") or DEFAULT_DATABASE
|
||||
db_file = Path(db_filename).absolute()
|
||||
|
||||
return BackendSettings(db_file=db_file)
|
||||
return BackendSettings()
|
||||
|
||||
Reference in New Issue
Block a user