mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-03-21 17:54:09 -05:00
Added Elasticsearch Handler for better Log output/visibility of error messages and infos.
Reformated API endpoints to be in a better order. Updated .gitignore to exclude config. Added requirments.txt Removed handler.py
This commit is contained in:
parent
827179d80e
commit
808268bf8f
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
.idea
|
||||
test/
|
||||
src/test/
|
||||
src/config/api_config.yaml
|
||||
3
requirments.txt
Normal file
3
requirments.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
flask
|
||||
yaml
|
||||
elasticsearch==7.14
|
||||
2
src/config/example_config.yaml
Normal file
2
src/config/example_config.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
elasticsearch:
|
||||
host: http://IP:PORT
|
||||
14
src/logic/Elasticsearch_handler.py
Normal file
14
src/logic/Elasticsearch_handler.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from datetime import datetime, date
|
||||
from elasticsearch import Elasticsearch
|
||||
import json
|
||||
|
||||
|
||||
def es_upload(server, index, log_message):
|
||||
if type(log_message) is not dict:
|
||||
log_message = {"steam_key": log_message}
|
||||
log_message["timestamp"] = datetime.utcnow().isoformat()
|
||||
es = Elasticsearch(server)
|
||||
data = json.dumps(log_message)
|
||||
response = es.index(index=index, body=data, headers={'Content-Type': 'application/json;charset=UTF-8'})
|
||||
document_id = response['_id']
|
||||
print("Uploaded dictionary with ID:", document_id)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
def post_handler(data):
|
||||
print("Post respond:")
|
||||
print(data)
|
||||
print("END OF RESPOND")
|
||||
|
|
@ -1,34 +1,51 @@
|
|||
"""
|
||||
|
||||
"""
|
||||
# ------------------------------------------------------- #
|
||||
# imports
|
||||
# ------------------------------------------------------- #
|
||||
from flask import Flask, send_from_directory, request, jsonify
|
||||
from threading import Thread
|
||||
from logic.handler import post_handler
|
||||
import os
|
||||
import yaml
|
||||
|
||||
from logic.Elasticsearch_handler import es_upload
|
||||
|
||||
|
||||
# ------------------------------------------------------- #
|
||||
# functions
|
||||
# ------------------------------------------------------- #
|
||||
def load_config():
|
||||
with open('config//api_config.yaml', 'r') as f:
|
||||
config_file = yaml.safe_load(f)
|
||||
return config_file
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def root():
|
||||
return "<p>Development Server for Death Garden API!</p>"
|
||||
|
||||
|
||||
@app.route('/favicon.ico')
|
||||
def favicon():
|
||||
return send_from_directory(os.path.join(app.root_path, 'image'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def hello_world():
|
||||
return "<p>Development Server for Death Garden API!</p>"
|
||||
|
||||
|
||||
@app.route("/api/v1/services/tex")
|
||||
def one():
|
||||
print("Responded to tex api call GET")
|
||||
return jsonify({"status": "success", "online": "true", "Version": "te-18f25613-36778-ue4-374f864b",
|
||||
"ProjectID": "F72FA5E64FA43E878DC72896AD677FB5",
|
||||
"DefaultFactoryName": "HttpNetworkReplayStreaming", "ServeMatchDelayInMin": "30.0f"})
|
||||
|
||||
|
||||
@app.route("/metrics/client/event", methods=["POST"])
|
||||
def receive_event():
|
||||
print("Responded to Metrics api call POST")
|
||||
data = request.get_json()
|
||||
post_handler(data)
|
||||
es_upload(server=es_server, index="client_event", log_message=data)
|
||||
return jsonify({"status": "success"})
|
||||
|
||||
|
||||
@app.route("/metrics/httplog/event", methods=["POST"])
|
||||
def metrics_httplog_event():
|
||||
data = request.get_json()
|
||||
es_upload(server=es_server, index="metrics_httplog_event", log_message=data)
|
||||
return jsonify({"status": "success"})
|
||||
|
||||
|
||||
|
|
@ -37,19 +54,19 @@ def healthcheck():
|
|||
return jsonify({"status": "success", "online": "true"})
|
||||
|
||||
|
||||
@app.route("/metrics/httplog/event", methods=["POST"])
|
||||
def receive_event2():
|
||||
print("Responded to httplog api call POST")
|
||||
data = request.get_json()
|
||||
post_handler(data)
|
||||
return jsonify({"status": "success"})
|
||||
@app.route("/api/v1/services/tex")
|
||||
def services_tex():
|
||||
print("Responded to tex api call GET")
|
||||
return jsonify({"status": "success", "online": "true", "Version": "te-18f25613-36778-ue4-374f864b",
|
||||
"ProjectID": "F72FA5E64FA43E878DC72896AD677FB5",
|
||||
"DefaultFactoryName": "HttpNetworkReplayStreaming", "ServeMatchDelayInMin": "30.0f"})
|
||||
|
||||
|
||||
@app.route("/api/v1/gameDataAnalytics", methods=["POST"])
|
||||
def analytics_post():
|
||||
print("Responded to analytics api call POST")
|
||||
data = request.get_json()
|
||||
post_handler(data)
|
||||
es_upload(server=es_server, index="game_data_analytics", log_message=data)
|
||||
return jsonify({"status": "success"})
|
||||
|
||||
|
||||
|
|
@ -57,25 +74,24 @@ def analytics_post():
|
|||
def analytics_batch_post():
|
||||
print("Responded to analytics batch api call POST")
|
||||
data = request.get_json()
|
||||
post_handler(data)
|
||||
es_upload(server=es_server, index="game_data_analytics_batch", log_message=data)
|
||||
return jsonify({"status": "success"})
|
||||
|
||||
|
||||
@app.route("/api/v1/auth/provider/steam/login", methods=["POST"])
|
||||
def steam_login():
|
||||
steam_token = request.args.get('token')
|
||||
es_upload(server=es_server, index="steam_login", log_message=steam_token)
|
||||
# return jsonify({"clientData":{"catalogId": "3.6.0_281460live", "consentId": "3.6.0_281460live"}})
|
||||
return jsonify({"clientData": "3.0.1"})
|
||||
|
||||
|
||||
# [Backend]
|
||||
@app.route("/tex", methods=["GET"])
|
||||
def tex_get():
|
||||
return jsonify({"status": "success"})
|
||||
|
||||
|
||||
@app.route("/api/v1/auth/provider/steam/login", methods=["POST"])
|
||||
def steam_login():
|
||||
# here we want to get the value of user (i.e. ?user=some-value)
|
||||
steam_token = request.args.get('token')
|
||||
print(steam_token)
|
||||
# return jsonify({"clientData":{"catalogId": "3.6.0_281460live", "consentId": "3.6.0_281460live"}})
|
||||
return jsonify({"clientData": "3.0.1"})
|
||||
|
||||
|
||||
def run():
|
||||
app.run(host='0.0.0.0', port=8080)
|
||||
|
||||
|
|
@ -86,8 +102,17 @@ def keep_alive():
|
|||
t.start()
|
||||
|
||||
|
||||
try:
|
||||
keep_alive()
|
||||
except KeyboardInterrupt:
|
||||
print("Exiting...")
|
||||
exit(0)
|
||||
# ------------------------------------------------------- #
|
||||
# global variables
|
||||
# ------------------------------------------------------- #
|
||||
|
||||
config = load_config()
|
||||
es_server = config['elasticsearch']['host']
|
||||
|
||||
|
||||
# ------------------------------------------------------- #
|
||||
# main
|
||||
# ------------------------------------------------------- #
|
||||
keep_alive()
|
||||
print("Exiting...")
|
||||
exit(0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user