38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from pathlib import Path
|
|
from typing import Any, Dict, Optional
|
|
|
|
from pydantic import field_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", case_sensitive=True)
|
|
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "One-Time Secret Manager API"
|
|
|
|
# Security
|
|
SECRET_KEY: str
|
|
ALGORITHM: str = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
|
|
|
# Database
|
|
DB_DIR: Path = Path("/app/storage/db")
|
|
SQLALCHEMY_DATABASE_URL: Optional[str] = None
|
|
|
|
@field_validator("SQLALCHEMY_DATABASE_URL", mode="before")
|
|
def assemble_db_url(cls, v: Optional[str], info: Dict[str, Any]) -> str:
|
|
if isinstance(v, str):
|
|
return v
|
|
|
|
# Ensure the database directory exists
|
|
db_dir = info.data.get("DB_DIR")
|
|
if db_dir:
|
|
db_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
return f"sqlite:///{db_dir}/db.sqlite"
|
|
|
|
|
|
settings = Settings(
|
|
SECRET_KEY="insecurekeyfordevonly" # For development only, should be overridden in production
|
|
) |