44 lines
1.3 KiB
Python

import os
from pathlib import Path
from pydantic import field_validator, BaseModel
# Project directories
ROOT_DIR = Path(__file__).parent.parent.parent.resolve()
class Settings(BaseModel):
# Project info
PROJECT_NAME: str = "One-Time Secret Sharing Service"
API_V1_STR: str = "/api/v1"
# Database
# Check if /app directory exists (container) or use local path
DB_DIR: Path = Path("/app" if os.path.exists("/app/storage") else ROOT_DIR) / "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)
# Ensure directory is writable
if not os.access(db_dir, os.W_OK):
try:
os.chmod(db_dir, 0o777)
except Exception:
print(f"Warning: Could not set permissions on {db_dir}")
return db_dir
model_config = {
"env_file": ".env",
"case_sensitive": True,
}
# Create global settings instance
settings = Settings()