From 19a74de67553789d2a817dea5a28b23ed5703854 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 1 Apr 2020 00:10:48 +0200 Subject: [PATCH 1/2] port 80 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 03d458c..273e267 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,5 +9,5 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN pip3 install -r requirements.txt -EXPOSE 8000 -CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"] +EXPOSE 80 +CMD ["gunicorn", "-b", "0.0.0.0:80", "app:app"] -- 2.45.2 From 2c6ab3d96d784c7903efa7cb61d3528c463d041e Mon Sep 17 00:00:00 2001 From: marcsello Date: Fri, 17 Apr 2020 16:21:42 +0200 Subject: [PATCH 2/2] added saving producer ips to redis --- consumer_api/views/log_view.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index abfff93..d2a4d15 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -1,9 +1,31 @@ from flask import request, current_app, Response from flask_classful import FlaskView +from db import redis_client class LogView(FlaskView): def post(self): + # Record the IP address of the producer + remote_uuid = request.json['uuid'] + remote_ip = request.remote_addr + + prod_key = f"producer_{remote_uuid}" + + last_known_remote_ip = redis_client.get(prod_key) + if last_known_remote_ip: + last_known_remote_ip = last_known_remote_ip.decode('utf-8') + + if not last_known_remote_ip: + current_app.logger.info(f"New producer {remote_uuid} at {remote_ip}") + elif last_known_remote_ip != remote_ip: + current_app.logger.info(f"IP address of producer {remote_uuid} have changed: {last_known_remote_ip} -> {remote_ip}") + + # update expirity + redis_client.set(prod_key, remote_ip.encode('utf-8')) + redis_client.expire(prod_key, 240) + + # print out message current_app.logger.info(f"New message: {request.json['message']}") - return Response(status = 204) + + return Response(status=204) -- 2.45.2