talk2me/check_services.py
Adolfo Delorenzo fa951c3141 Add comprehensive database integration, authentication, and admin dashboard
This commit introduces major enhancements to Talk2Me:

## Database Integration
- PostgreSQL support with SQLAlchemy ORM
- Redis integration for caching and real-time analytics
- Automated database initialization scripts
- Migration support infrastructure

## User Authentication System
- JWT-based API authentication
- Session-based web authentication
- API key authentication for programmatic access
- User roles and permissions (admin/user)
- Login history and session tracking
- Rate limiting per user with customizable limits

## Admin Dashboard
- Real-time analytics and monitoring
- User management interface (create, edit, delete users)
- System health monitoring
- Request/error tracking
- Language pair usage statistics
- Performance metrics visualization

## Key Features
- Dual authentication support (token + user accounts)
- Graceful fallback for missing services
- Non-blocking analytics middleware
- Comprehensive error handling
- Session management with security features

## Bug Fixes
- Fixed rate limiting bypass for admin routes
- Added missing email validation method
- Improved error handling for missing database tables
- Fixed session-based authentication for API endpoints

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-03 18:21:56 -06:00

48 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""
Check if Redis and PostgreSQL are available
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def check_redis():
"""Check if Redis is available"""
try:
import redis
r = redis.Redis.from_url(os.environ.get('REDIS_URL', 'redis://localhost:6379/0'))
r.ping()
return True
except:
return False
def check_postgresql():
"""Check if PostgreSQL is available"""
try:
from sqlalchemy import create_engine, text
db_url = os.environ.get('DATABASE_URL', 'postgresql://localhost/talk2me')
engine = create_engine(db_url, pool_pre_ping=True)
with engine.connect() as conn:
result = conn.execute(text("SELECT 1"))
result.fetchone()
return True
except Exception as e:
print(f"PostgreSQL connection error: {e}")
return False
if __name__ == '__main__':
redis_ok = check_redis()
postgres_ok = check_postgresql()
print(f"Redis: {'✓ Available' if redis_ok else '✗ Not available'}")
print(f"PostgreSQL: {'✓ Available' if postgres_ok else '✗ Not available'}")
if redis_ok and postgres_ok:
print("\nAll services available - use full admin module")
sys.exit(0)
else:
print("\nSome services missing - use simple admin module")
sys.exit(1)