fix(mt5-api): resolver 5 problemas críticos de auth, sesiones y deps#19
Open
victalejo wants to merge 2 commits into
Open
fix(mt5-api): resolver 5 problemas críticos de auth, sesiones y deps#19victalejo wants to merge 2 commits into
victalejo wants to merge 2 commits into
Conversation
…lity - Added URL configuration for the Django app. - Created MT5 login form and associated views for handling login and logout. - Implemented middleware to protect routes requiring MT5 authentication. - Developed dashboard view to display account information and open positions. - Created templates for login and dashboard pages with Bootstrap styling. - Established MT5 client API for robust interaction with the MT5 server. - Updated Dockerfile for the MT5 service to use Debian Bookworm and optimize package installations. - Introduced JWT-based authentication for the Flask MT5 API with session management. - Secured API routes with authentication middleware and updated Swagger documentation. - Adjusted docker-compose configuration for service port mapping.
…Y en la autenticación
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Corrige 5 problemas críticos detectados en el sistema de autenticación
MT5 y el setup de dependencias:
/logoutllamaba amt5.shutdown(), lo quedesconectaba el terminal MT5 para todos los usuarios concurrentes,
no solo el que cerraba sesión. Además, no había guardia contra logins
simultáneos con cuentas distintas (el
MetaTrader5singleton delproceso solo puede hospedar una cuenta a la vez).
SESSIONS = {}se perdía en cadarestart de Flask y no era compatible con más de 1 worker de gunicorn.
SECRET_KEYcon fallback inseguro: el código aceptaba arrancarcon
'your-super-secret-key-change-in-production'si la variable noestaba seteada, permitiendo firmar/verificar JWTs con una clave pública.
backend/django/requirements.txten UTF-16 LE:pip install -rfallaba en muchos entornos al no detectar la codificación.
datetime.now()naive: tokens y TTLsdependían de la TZ local del contenedor.
Cambios
routes/auth.py— sesiones movidas a Redis (DB 1) con TTL gestionadopor la propia Redis vía
SETEX/EXPIRE. Nueva clavemt5:current_loginpara marcar qué
login"posee" el terminal en cada momento. El/loginrechaza con
409 Conflictsi ya hay otra cuenta activa, salvo que sepase
"force": true. El/logoutya no llama amt5.shutdown():solo borra la sesión y libera el marcador
current_loginsi era suyo.Todas las marcas temporales pasan a
datetime.now(timezone.utc).app.py— validaSECRET_KEYal arrancar; lanzaRuntimeErrorcon instrucciones si falta o es un placeholder conocido. Inicializa
el store de sesiones vía
init_session_store(REDIS_URL).backend/mt5/app/requirements.txt— añaderedis==5.2.0.backend/django/requirements.txt— re-codificado a UTF-8; seañade
PyJWT==2.8.0(lo importabamt5_client.pypero faltaba).docker-compose.yml—mt5ahora declaradepends_on: redis..env.example—SECRET_KEYdocumentada como obligatoria concomando de generación; se añade
REDIS_URL=redis://redis:6379/1.