42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import os
|
|
from pathlib import Path
|
|
from pydantic import field_validator, BaseModel
|
|
|
|
# Get project root directory
|
|
if '/app/repo' in str(Path.cwd()):
|
|
# When running in the container
|
|
ROOT_DIR = Path('/app/repo')
|
|
else:
|
|
# When running in development
|
|
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
|
|
DB_DIR: Path = 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)
|
|
return db_dir
|
|
|
|
model_config = {
|
|
"env_file": ".env",
|
|
"case_sensitive": True,
|
|
}
|
|
|
|
|
|
# Create global settings instance
|
|
settings = Settings() |