From d7c011e68f3f76b3d5feaf83c3c740c04431d380 Mon Sep 17 00:00:00 2001 From: ZKWolf Date: Mon, 11 Sep 2023 17:59:33 +0200 Subject: [PATCH] Moved debug endpoint. Fixed debug Mirrors not returning a error code but allways 200 and made the ElIf mess better... --- src/endpoints/web.py | 54 +++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/endpoints/web.py b/src/endpoints/web.py index c0e5e41..a956d36 100644 --- a/src/endpoints/web.py +++ b/src/endpoints/web.py @@ -28,6 +28,20 @@ def dnt(): return send_from_directory(app.static_folder, request.path[1:]) +@app.route("/debug/", methods=["Get"]) +def debug_root(): + check_for_game_client("soft") + endpoint_descriptions = { + '/debug/user': 'Endpoint to debug user information'} + + endpoint_list = [] + for endpoint, description in endpoint_descriptions.items(): + endpoint_list.append(f'
  • {endpoint}: {description}
  • ') + + endpoints_html = '' + return f'

    Debug Endpoints:

    {endpoints_html}' + + @app.route('/debug/user/', methods=['GET'], defaults={'steamid': None}) @app.route('/debug/user/', methods=['GET']) def debug_user(steamid): @@ -72,24 +86,28 @@ def debug_mirrors_write(): api_token = request.cookies.get("api_token") if api_token is None: return jsonify({"status": "error", "message": "No api token found"}, 401) - else: - if api_token in allowed_tokens: + if api_token not in allowed_tokens: + return jsonify({"status": "error", "message": "Invalid api token"}), 401 + steam_user_id = request.json.get("steamid") + data_b = request.json.get("data") - steam_user_id = request.json.get("steamid") - data_b = request.json.get("data") + if not data_b: + return jsonify({"status": "error", "message": "No data found."}), 400 - if data_b or steam_user_id: - return_val = mongo.write_data_with_list(steamid=steam_user_id, items_dict=data_b, server=mongo_host, db=mongo_db, - collection=mongo_collection) - if return_val is None: - return jsonify({"status": "error", "message": "There was a error on our End. " - "Please try again later."}, 400) - else: - return jsonify({"status": "success", "message": "Data written."}, 200) - else: - return jsonify({"status": "error", "message": "No data or Steamid found."}, 400) - else: - return jsonify({"status": "error", "message": "Invalid api token"}, 401) + if not steam_user_id: + return jsonify({"status": "error", "message": "No Steamid found."}), 400 + + logger.graylog_logger(level="info", handler="logging_debug_mirror_write", + message={"IP": check_for_game_client("remote"), "steamid": steam_user_id, "data": data_b}) + + return_val = mongo.write_data_with_list(steamid=steam_user_id, items_dict=data_b, server=mongo_host, db=mongo_db, + collection=mongo_collection) + + if return_val is None: + return jsonify({"status": "error", "message": "There was a error on our End. " + "Please try again later."}), 400 + + return jsonify({"status": "success", "message": "Data written."}), 200 except TimeoutError: return jsonify({"status": "error"}) @@ -108,7 +126,7 @@ def updater_root(): @app.route("/updater/version/", methods=["GET"]) def updater_version(): - return jsonify({"Error": "Please read the Docs about this Endpoint."}) + return jsonify({"Error": "Please read the Docs about this Endpoint."}), 400 @app.route("/updater/version/script/", methods=["GET"]) @@ -128,7 +146,7 @@ def updater_version_sig(): @app.route("/updater/files/", methods=["GET"]) def updater_files(): - return jsonify({"Error": "Please read the Docs about this Endpoint."}) + return jsonify({"Error": "Please read the Docs about this Endpoint."}), 400 @app.route("/updater/files/pak/", methods=["GET"])