af1b8e9956
- 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.
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
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)
|
|
db.add(researcher)
|
|
db.commit()
|
|
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()
|
|
db.commit()
|
|
db.refresh(researcher)
|
|
return researcher
|