Spaces:
Sleeping
Sleeping
| """Configuration management for PageSpeed Insights analyzer.""" | |
| import os | |
| from typing import Optional | |
| class Config: | |
| """Configuration class for managing environment variables and settings.""" | |
| def __init__(self): | |
| self._openai_api_key = None | |
| self._pagespeed_api_key = None | |
| self.openai_model = os.environ.get("OPENAI_MODEL", "o1-preview") | |
| def openai_api_key(self) -> Optional[str]: | |
| """Get OpenAI API key from environment variables.""" | |
| if self._openai_api_key is None: | |
| self._openai_api_key = os.environ.get("OPENAI_API_KEY") | |
| return self._openai_api_key | |
| def pagespeed_api_key(self) -> Optional[str]: | |
| """Get PageSpeed Insights API key from environment variables.""" | |
| if self._pagespeed_api_key is None: | |
| self._pagespeed_api_key = os.environ.get("PAGE_SPEED_API_KEY") | |
| return self._pagespeed_api_key | |
| def get_missing_vars(self) -> list[str]: | |
| """Get list of missing environment variables.""" | |
| missing = [] | |
| if not self.openai_api_key: | |
| missing.append("OPENAI_API_KEY") | |
| if not os.environ.get("GOOGLE_SERVICE_ACCOUNT_JSON"): | |
| missing.append("GOOGLE_SERVICE_ACCOUNT_JSON") | |
| return missing | |
| def validate(self) -> bool: | |
| """Validate that all required configuration is available.""" | |
| # Only Google Service Account is mandatory | |
| return bool(os.environ.get("GOOGLE_SERVICE_ACCOUNT_JSON")) | |
| config = Config() |