import json from flask import request, current_app, jsonify from flask_classful import FlaskView from db import redis_client # ez nagyon otvar class SyncView(FlaskView): def post(self): remote_uuid = request.json['uuid'] remote_ip = request.remote_addr consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) # Log something about it if remote_uuid not in consumer_list.keys(): current_app.logger.info(f"New consumer registered (unknown UUID): {remote_uuid} at {remote_ip}") else: # known if consumer_list[remote_uuid]['ip'] != remote_ip: current_app.logger.info(f"Address of consumer {remote_uuid} changed to {remote_ip}") consumer_list.update( {remote_uuid: {"ip": remote_ip}} ) redis_client.set("consumer_list", json.dumps(consumer_list).encode('utf-8')) response = { "uuid": current_app.config['LOCAL_UUID'] } return jsonify(response)