Spaces:
Runtime error
Runtime error
| """Configuration management for ClassLens backend.""" | |
| from __future__ import annotations | |
| import os | |
| from pathlib import Path | |
| from functools import lru_cache | |
| from dotenv import load_dotenv | |
| from pydantic import BaseModel | |
| # Load .env file from the chatkit directory (parent of backend) | |
| env_path = Path(__file__).parent.parent.parent / ".env" | |
| load_dotenv(env_path) | |
| class Settings(BaseModel): | |
| """Application settings loaded from environment variables.""" | |
| # OpenAI | |
| openai_api_key: str = "" | |
| # Google OAuth | |
| google_client_id: str = "" | |
| google_client_secret: str = "" | |
| google_redirect_uri: str = "http://localhost:8000/auth/callback" | |
| # SendGrid | |
| sendgrid_api_key: str = "" | |
| sendgrid_from_email: str = "classlens@example.com" | |
| # Database | |
| database_url: str = "sqlite+aiosqlite:///./classlens.db" | |
| # Encryption key for tokens (32 bytes, base64 encoded) | |
| encryption_key: str = "" | |
| # Frontend URL for redirects | |
| frontend_url: str = "http://localhost:3000" | |
| class Config: | |
| env_file = ".env" | |
| def get_settings() -> Settings: | |
| """Get cached settings instance.""" | |
| return Settings( | |
| openai_api_key=os.getenv("OPENAI_API_KEY", ""), | |
| google_client_id=os.getenv("GOOGLE_CLIENT_ID", ""), | |
| google_client_secret=os.getenv("GOOGLE_CLIENT_SECRET", ""), | |
| google_redirect_uri=os.getenv("GOOGLE_REDIRECT_URI", "http://localhost:8000/auth/callback"), | |
| sendgrid_api_key=os.getenv("SENDGRID_API_KEY", ""), | |
| sendgrid_from_email=os.getenv("SENDGRID_FROM_EMAIL", "classlens@example.com"), | |
| database_url=os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./classlens.db"), | |
| encryption_key=os.getenv("ENCRYPTION_KEY", ""), | |
| frontend_url=os.getenv("FRONTEND_URL", "http://localhost:3000"), | |
| ) | |
| # Google OAuth scopes required for the application | |
| # Note: drive.readonly is sensitive scope; spreadsheets.readonly is less restricted | |
| GOOGLE_SCOPES = [ | |
| "https://www.googleapis.com/auth/spreadsheets.readonly", | |
| "https://www.googleapis.com/auth/userinfo.email", | |
| "openid", | |
| ] | |