First release #3

Manually merged
marcsello merged 12 commits from dev into master 2020-04-01 01:52:15 +02:00
5 changed files with 41 additions and 7 deletions

View File

@ -9,5 +9,5 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
EXPOSE 8000 EXPOSE 80
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"] CMD ["gunicorn", "-b", "0.0.0.0:80", "app:app"]

View File

@ -18,6 +18,7 @@ sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10")
app = Flask(__name__) app = Flask(__name__)
app.config['REDIS_URL'] = os.environ['REDIS_URL'] app.config['REDIS_URL'] = os.environ['REDIS_URL']
app.config['LOCAL_UUID'] = os.environ['LOCAL_UUID']
redis_client.init_app(app) redis_client.init_app(app)

View File

@ -1,7 +1,13 @@
import json
from db import redis_client
from flask import jsonify, current_app
from flask_classful import FlaskView from flask_classful import FlaskView
class ConsumersView(FlaskView): class ConsumersView(FlaskView):
def get(self): def get(self):
return "ConsumersView" consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8'))
current_app.logger.warning(jsonify([v['ip'] for k, v in consumer_list.items()]))
return jsonify([v['ip'] for k, v in consumer_list.items()])

View File

@ -1,7 +1,9 @@
from flask import request, current_app, Response
from flask_classful import FlaskView from flask_classful import FlaskView
class LogView(FlaskView): class LogView(FlaskView):
def get(self): def post(self):
return "LogView" current_app.logger.info(f"New message: {request.json['message']}")
return Response(status = 204)

View File

@ -1,7 +1,32 @@
import json
from flask import request, current_app, jsonify
from flask_classful import FlaskView from flask_classful import FlaskView
from db import redis_client # ez nagyon otvar
class SyncView(FlaskView): class SyncView(FlaskView):
def get(self): def post(self):
return "SyncView" 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)