Initial commit: HabitForge - habit tracking application with FastAPI backend, React frontend, and Zepp integration
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Core module for configuration and security."""
|
||||
@@ -0,0 +1,61 @@
|
||||
"""Configuration module using pydantic_settings for environment-based configuration."""
|
||||
from secrets import token_urlsafe
|
||||
from typing import List, Union
|
||||
from pydantic import field_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings loaded from environment variables."""
|
||||
|
||||
# Security
|
||||
SECRET_KEY: str = token_urlsafe(32)
|
||||
ALGORITHM: str = "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
||||
|
||||
# Database
|
||||
DATABASE_URL: str = "sqlite:///./data/habitforge.db"
|
||||
|
||||
# CORS
|
||||
CORS_ORIGINS: Union[List[str], str] = ["http://localhost:8000", "http://localhost:3000"]
|
||||
CORS_ALLOW_CREDENTIALS: bool = True
|
||||
CORS_ALLOW_METHODS: Union[List[str], str] = ["*"]
|
||||
CORS_ALLOW_HEADERS: Union[List[str], str] = ["*"]
|
||||
|
||||
# Google OAuth
|
||||
GOOGLE_CLIENT_ID: str = ""
|
||||
GOOGLE_CLIENT_SECRET: str = ""
|
||||
GOOGLE_REDIRECT_URI: str = "http://localhost:8000/api/google/callback"
|
||||
|
||||
# Rate Limiting
|
||||
RATE_LIMIT_ENABLED: bool = True
|
||||
RATE_LIMIT_TIMES: int = 60
|
||||
RATE_LIMIT_SECONDS: int = 60
|
||||
|
||||
# Application
|
||||
APP_NAME: str = "HabitForge API"
|
||||
APP_VERSION: str = "1.0.0"
|
||||
DEBUG: bool = True
|
||||
|
||||
# Health Data Provider Selection
|
||||
# Options: "google_fit", "health_connect", "dual" (both for comparison)
|
||||
HEALTH_PROVIDER: str = "google_fit"
|
||||
|
||||
@field_validator("CORS_ORIGINS", "CORS_ALLOW_METHODS", "CORS_ALLOW_HEADERS", mode="before")
|
||||
@classmethod
|
||||
def assemble_cors_list(cls, v: Union[str, List[str]]) -> List[str]:
|
||||
"""Convert a comma-separated string into a list of strings if necessary."""
|
||||
if isinstance(v, str) and not v.startswith("["):
|
||||
return [i.strip() for i in v.split(",") if i.strip()]
|
||||
return v
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=True,
|
||||
extra="ignore"
|
||||
)
|
||||
|
||||
|
||||
# Global settings instance
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user