Spaces:
Runtime error
Runtime error
File size: 2,125 Bytes
e5c2788 054d73a e5c2788 054d73a e5c2788 054d73a e5c2788 054d73a 5ee5085 054d73a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | """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"
@lru_cache
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",
]
|