Improve teh securty of teh DB

This commit is contained in:
Urtzi Alfaro
2025-10-19 19:22:37 +02:00
parent 62971c07d7
commit 05da20357d
87 changed files with 7998 additions and 932 deletions

View File

@@ -226,27 +226,39 @@ class SSEService:
error=str(e))
async def get_active_items(self, tenant_id: str) -> list:
"""Fetch active alerts and recommendations from database"""
"""
Fetch active alerts and recommendations from Redis cache.
NOTE: We use Redis as the source of truth for active alerts to maintain
microservices architecture. The alert_processor service caches active alerts
in Redis when they are created, and we read from that cache here.
This avoids direct database coupling between services.
"""
try:
# This would integrate with the actual database
# For now, return empty list as placeholder
# In real implementation, this would query the alerts table
# Example query:
# query = """
# SELECT id, item_type, alert_type, severity, title, message,
# actions, metadata, created_at, status
# FROM alerts
# WHERE tenant_id = $1
# AND status = 'active'
# ORDER BY severity_weight DESC, created_at DESC
# LIMIT 50
# """
return [] # Placeholder
if not self.redis:
logger.warning("Redis not available, returning empty list", tenant_id=tenant_id)
return []
# Try to get cached active alerts for this tenant from Redis
cache_key = f"active_alerts:{tenant_id}"
cached_data = await self.redis.get(cache_key)
if cached_data:
active_items = json.loads(cached_data)
logger.info("Fetched active alerts from Redis cache",
tenant_id=tenant_id,
count=len(active_items))
return active_items
else:
logger.info("No cached alerts found for tenant",
tenant_id=tenant_id)
return []
except Exception as e:
logger.error("Error fetching active items", tenant_id=tenant_id, error=str(e))
logger.error("Error fetching active items from Redis",
tenant_id=tenant_id,
error=str(e),
exc_info=True)
return []
def get_metrics(self) -> Dict[str, Any]: