feat: enhance backend security and configuration
- Updated Dockerfile to improve security with a non-root user and added health checks. - Modified docker-compose.yml to set containers as read-only, restrict ports to localhost, and implement health checks. - Enhanced .env.example with additional environment variables for security and configuration. - Improved FastAPI application with middleware for security headers, CORS, and body size limits. - Refactored authentication flow in auth.py to include state validation and improved error handling. - Added rate limiting to various endpoints to prevent abuse. - Updated researcher and publication handling to ensure better validation and error management.
This commit is contained in:
@@ -2,13 +2,24 @@ from sqlalchemy.orm import Session
|
||||
from app.db.models import Researcher
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Repositorio de investigadores
|
||||
# ---------------------------------------------------------
|
||||
|
||||
class ResearcherRepository:
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Función auxiliar: obtener investigador por ORCID ID
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@staticmethod
|
||||
def get_by_orcid(db: Session, orcid_id: str):
|
||||
return db.query(Researcher).filter(Researcher.orcid_id == orcid_id).first()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Función auxiliar: crear un nuevo investigador
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@staticmethod
|
||||
def create(db: Session, orcid_id: str, name: str = None):
|
||||
researcher = Researcher(orcid_id=orcid_id, name=name)
|
||||
@@ -17,6 +28,10 @@ class ResearcherRepository:
|
||||
db.refresh(researcher)
|
||||
return researcher
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Función auxiliar: actualizar la última sincronización
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@staticmethod
|
||||
def update_last_sync(db: Session, researcher: Researcher):
|
||||
researcher.last_sync_at = func.now()
|
||||
|
||||
Reference in New Issue
Block a user