37 lines
973 B
Python
37 lines
973 B
Python
import os
|
|
from pathlib import Path
|
|
from pydantic import field_validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
# Project directories
|
|
ROOT_DIR = Path(__file__).parent.parent.parent.resolve()
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# Project info
|
|
PROJECT_NAME: str = "One-Time Secret Sharing Service"
|
|
API_V1_STR: str = "/api/v1"
|
|
|
|
# Database
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
# Secret settings
|
|
DEFAULT_SECRET_TTL_HOURS: int = 24
|
|
MAX_SECRET_TTL_HOURS: int = 168 # 7 days
|
|
|
|
# Security
|
|
SECRET_KEY: str = os.environ.get("SECRET_KEY", "development_secret_key")
|
|
|
|
@field_validator("DB_DIR")
|
|
def create_db_dir(cls, db_dir: Path) -> Path:
|
|
db_dir.mkdir(parents=True, exist_ok=True)
|
|
return db_dir
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
case_sensitive = True
|
|
|
|
|
|
# Create global settings instance
|
|
settings = Settings() |