From b04d0d60d071ab5749e2c401d1d0b843f39f38df Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 16:32:33 +0200 Subject: [PATCH 1/7] consumer and log views --- consumer_api/views/consumers_view.py | 6 +++++- consumer_api/views/log_view.py | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/consumer_api/views/consumers_view.py b/consumer_api/views/consumers_view.py index feb59ef..5f0c6f5 100644 --- a/consumer_api/views/consumers_view.py +++ b/consumer_api/views/consumers_view.py @@ -1,7 +1,11 @@ +import json +from flask import request, current_app, jsonify +from db import redis_client from flask_classful import FlaskView class ConsumersView(FlaskView): def get(self): - return "ConsumersView" + consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) + return [v['ip'] for k, v in consumer_list.items()] diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index fc589f4..eda8437 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -1,7 +1,9 @@ from flask_classful import FlaskView - +from flask import request, current_app, jsonify class LogView(FlaskView): def get(self): - return "LogView" \ No newline at end of file + remote_uuid = request.json['uuid'] + current_app.logger.info(f"New message from {remote_uuid}: {request.message}") + return jsonify(success = True) -- 2.45.2 From 244b779107e3c3e7aa9654d0992a8b567a875fdc Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 16:35:54 +0200 Subject: [PATCH 2/7] return 200 --- consumer_api/views/log_view.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index eda8437..99c762e 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -6,4 +6,5 @@ class LogView(FlaskView): def get(self): remote_uuid = request.json['uuid'] current_app.logger.info(f"New message from {remote_uuid}: {request.message}") - return jsonify(success = True) + return 200 + \ No newline at end of file -- 2.45.2 From 0c3161ef034116b6e6c692efce6ad18256fbaf9f Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 16:36:33 +0200 Subject: [PATCH 3/7] 204 --- consumer_api/views/log_view.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index 99c762e..1ce37d1 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -1,10 +1,9 @@ from flask_classful import FlaskView -from flask import request, current_app, jsonify +from flask import request, current_app, Response class LogView(FlaskView): def get(self): remote_uuid = request.json['uuid'] current_app.logger.info(f"New message from {remote_uuid}: {request.message}") - return 200 - \ No newline at end of file + return Response(status=204) -- 2.45.2 From 3c8229238c9e9f110486966a05ce40cfc7d84f5c Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 16:37:12 +0200 Subject: [PATCH 4/7] jsonify --- consumer_api/views/consumers_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consumer_api/views/consumers_view.py b/consumer_api/views/consumers_view.py index 5f0c6f5..d8d9fa1 100644 --- a/consumer_api/views/consumers_view.py +++ b/consumer_api/views/consumers_view.py @@ -8,4 +8,4 @@ class ConsumersView(FlaskView): def get(self): consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) - return [v['ip'] for k, v in consumer_list.items()] + return jsonify([v['ip'] for k, v in consumer_list.items()]) -- 2.45.2 From 68e2eaffcba9023b9befeff266545d92a2a5eaa4 Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 16:52:15 +0200 Subject: [PATCH 5/7] message --- consumer_api/views/log_view.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index 1ce37d1..808c98e 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -4,6 +4,5 @@ from flask import request, current_app, Response class LogView(FlaskView): def get(self): - remote_uuid = request.json['uuid'] - current_app.logger.info(f"New message from {remote_uuid}: {request.message}") + current_app.logger.info(f"New message from: {request.json['message']}") return Response(status=204) -- 2.45.2 From 0c18cf9bf1552afb0c1c43b938aeae0ba8366799 Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 16:56:29 +0200 Subject: [PATCH 6/7] message --- consumer_api/views/log_view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index 808c98e..c63e682 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -3,6 +3,6 @@ from flask import request, current_app, Response class LogView(FlaskView): - def get(self): - current_app.logger.info(f"New message from: {request.json['message']}") + def post(self): + current_app.logger.info(f"New message: {request.json['message']}") return Response(status=204) -- 2.45.2 From f8feb4072350520e94df185a68e888ee68756270 Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 17:00:59 +0200 Subject: [PATCH 7/7] minor --- consumer_api/views/consumers_view.py | 3 ++- consumer_api/views/log_view.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/consumer_api/views/consumers_view.py b/consumer_api/views/consumers_view.py index d8d9fa1..c12739c 100644 --- a/consumer_api/views/consumers_view.py +++ b/consumer_api/views/consumers_view.py @@ -1,6 +1,7 @@ import json -from flask import request, current_app, jsonify + from db import redis_client +from flask import jsonify from flask_classful import FlaskView diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index c63e682..abfff93 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -1,8 +1,9 @@ -from flask_classful import FlaskView from flask import request, current_app, Response +from flask_classful import FlaskView + class LogView(FlaskView): def post(self): current_app.logger.info(f"New message: {request.json['message']}") - return Response(status=204) + return Response(status = 204) -- 2.45.2