Spaces:
Sleeping
Sleeping
| """ | |
| Configuration settings for Auth microservice. | |
| Loads environment variables and provides application settings. | |
| """ | |
| import os | |
| from typing import Optional, List | |
| from pydantic_settings import BaseSettings, SettingsConfigDict | |
| class Settings(BaseSettings): | |
| """Application settings loaded from environment variables""" | |
| # Application | |
| APP_NAME: str = "Auth Microservice" | |
| APP_VERSION: str = "1.0.0" | |
| DEBUG: bool = False | |
| # MongoDB Configuration | |
| MONGODB_URI: str = os.getenv("MONGODB_URI", "mongodb://localhost:27017") | |
| MONGODB_DB_NAME: str = os.getenv("MONGODB_DB_NAME", "auth_db") | |
| # Redis Configuration | |
| REDIS_HOST: str = os.getenv("REDIS_HOST", "localhost") | |
| REDIS_PORT: int = int(os.getenv("REDIS_PORT", "6379")) | |
| REDIS_PASSWORD: Optional[str] = os.getenv("REDIS_PASSWORD") | |
| REDIS_DB: int = int(os.getenv("REDIS_DB", "0")) | |
| # JWT Configuration | |
| SECRET_KEY: str = os.getenv("SECRET_KEY", "your-secret-key-change-in-production") | |
| ALGORITHM: str = os.getenv("ALGORITHM", "HS256") | |
| TOKEN_EXPIRATION_HOURS: int = int(os.getenv("TOKEN_EXPIRATION_HOURS", "8")) | |
| REFRESH_TOKEN_EXPIRE_DAYS: int = int(os.getenv("REFRESH_TOKEN_EXPIRE_DAYS", "7")) | |
| MAX_FAILED_LOGIN_ATTEMPTS: int = int(os.getenv("MAX_FAILED_LOGIN_ATTEMPTS", "5")) | |
| ACCOUNT_LOCK_DURATION_MINUTES: int = int(os.getenv("ACCOUNT_LOCK_DURATION_MINUTES", "15")) | |
| REMEMBER_ME_TOKEN_HOURS: int = int(os.getenv("REMEMBER_ME_TOKEN_HOURS", "24")) | |
| # Password Reset Configuration | |
| PASSWORD_RESET_TOKEN_EXPIRATION_MINUTES: int = int(os.getenv("PASSWORD_RESET_TOKEN_EXPIRATION_MINUTES", "60")) | |
| PASSWORD_RESET_BASE_URL: str = os.getenv("PASSWORD_RESET_BASE_URL", "http://localhost:3000/reset-password") | |
| # Password Rotation Policy Configuration | |
| PASSWORD_ROTATION_DAYS: int = int(os.getenv("PASSWORD_ROTATION_DAYS", "60")) | |
| PASSWORD_ROTATION_WARNING_DAYS: int = int(os.getenv("PASSWORD_ROTATION_WARNING_DAYS", "7")) | |
| ENFORCE_PASSWORD_ROTATION: bool = os.getenv("ENFORCE_PASSWORD_ROTATION", "true").lower() == "true" | |
| ALLOW_LOGIN_WITH_EXPIRED_PASSWORD: bool = os.getenv("ALLOW_LOGIN_WITH_EXPIRED_PASSWORD", "false").lower() == "true" | |
| # API Configuration | |
| MAX_PAGE_SIZE: int = int(os.getenv("MAX_PAGE_SIZE", "100")) | |
| # OTP Configuration | |
| OTP_TTL_SECONDS: int = int(os.getenv("OTP_TTL_SECONDS", "600")) | |
| OTP_RATE_LIMIT_MAX: int = int(os.getenv("OTP_RATE_LIMIT_MAX", "10")) | |
| OTP_RATE_LIMIT_WINDOW: int = int(os.getenv("OTP_RATE_LIMIT_WINDOW", "600")) | |
| # Twilio Configuration | |
| TWILIO_ACCOUNT_SID: Optional[str] = os.getenv("TWILIO_ACCOUNT_SID") | |
| TWILIO_AUTH_TOKEN: Optional[str] = os.getenv("TWILIO_AUTH_TOKEN") | |
| TWILIO_PHONE_NUMBER: Optional[str] = os.getenv("TWILIO_PHONE_NUMBER") | |
| # Notification template names (resolved by notification-ms dispatcher) | |
| NOTIFICATION_TEMPLATE_OTP_VERIFICATION: str = os.getenv("NOTIFICATION_TEMPLATE_OTP_VERIFICATION", "otp") | |
| NOTIFICATION_TEMPLATE_CREDENTIALS: str = os.getenv("NOTIFICATION_TEMPLATE_CREDENTIALS", "otp") | |
| NOTIFICATION_TEMPLATE_PASSWORD_RESET: str = os.getenv("NOTIFICATION_TEMPLATE_PASSWORD_RESET", "otp") | |
| # Logging | |
| LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO") | |
| # CORS | |
| CORS_ORIGINS: List[str] = [ | |
| "http://localhost:3000", | |
| "http://localhost:8000", | |
| "http://localhost:8002", | |
| ] | |
| # Pydantic v2 config | |
| model_config = SettingsConfigDict( | |
| env_file=".env", | |
| env_file_encoding="utf-8", | |
| case_sensitive=True, | |
| extra="allow", # allows extra environment variables without error | |
| ) | |
| # Global settings instance | |
| settings = Settings() |