From 4d87ba0486d24d6634df9f11c59e40ff9b070531 Mon Sep 17 00:00:00 2001 From: TatLead Date: Tue, 12 Mar 2024 03:08:59 +0000 Subject: [PATCH] Create Swagger --- app.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 10 ++++ terms.md | 27 ++++++++++ version.py | 1 + 4 files changed, 166 insertions(+) create mode 100644 terms.md create mode 100644 version.py diff --git a/app.py b/app.py index 8fc056a..851a518 100644 --- a/app.py +++ b/app.py @@ -1,9 +1,33 @@ from flask import Flask, abort, request, jsonify +from flasgger import Swagger + +import markdown from protocols import MasterServer, BeamMP, Factorio, Palworld, Scum +from version import __version__ app = Flask(__name__) +swagger_config = { + "headers": [], + "specs": [ + { + "endpoint": 'apispec_1', + "route": '/apispec_1.json', + "rule_filter": lambda rule: True, # all in + "model_filter": lambda tag: True, # all in + } + ], + "title": "OpenGSQ Master Server Search API", + "version": __version__, + "description": "Powered By OpenGSQ", + "termsOfService": "/terms", + "static_url_path": "/flasgger_static", + "swagger_ui": True, + "specs_route": "/" +} +swagger = Swagger(app, config=swagger_config) + def search(args: dict, master_server: MasterServer): host = args.get('host') @@ -29,23 +53,127 @@ def search(args: dict, master_server: MasterServer): @app.route('/beammp/search', methods=['GET']) def beammp_search(): + """ + BeamMP Search + This endpoint allows you to search for a BeamMP server using its host and port. + --- + tags: + - Search EndPoint + parameters: + - name: host + in: query + type: string + required: true + - name: port + in: query + type: integer + required: true + responses: + 200: + description: Success + 400: + description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer. + 404: + description: No server was found with the provided host and port. + """ return search(request.args, BeamMP()) @app.route('/factorio/search', methods=['GET']) def factorio_search(): + """ + Factorio Search + This endpoint allows you to search for a Factorio server using its host and port. + --- + tags: + - Search EndPoint + parameters: + - name: host + in: query + type: string + required: true + - name: port + in: query + type: integer + required: true + responses: + 200: + description: Success + 400: + description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer. + 404: + description: No server was found with the provided host and port. + """ return search(request.args, Factorio()) @app.route('/palworld/search', methods=['GET']) def palworld_search(): + """ + Palworld Search + This endpoint allows you to search for a Palworld server using its host and port. + --- + tags: + - Search EndPoint + parameters: + - name: host + in: query + type: string + required: true + - name: port + in: query + type: integer + required: true + responses: + 200: + description: Success + 400: + description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer. + 404: + description: No server was found with the provided host and port. + """ return search(request.args, Palworld()) @app.route('/scum/search', methods=['GET']) def scum_search(): + """ + SCUM Search + This endpoint allows you to search for a SCUM server using its host and port. + --- + tags: + - Search EndPoint + parameters: + - name: host + in: query + type: string + required: true + - name: port + in: query + type: integer + required: true + responses: + 200: + description: Success + 400: + description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer. + 404: + description: No server was found with the provided host and port. + """ return search(request.args, Scum()) +@app.route("/terms") +def render_terms(): + # Read the contents of terms.md + with open("terms.md", "r") as terms_file: + md_content = terms_file.read() + + # Convert Markdown to HTML + html_content = markdown.markdown(md_content) + + return html_content + + if __name__ == '__main__': app.run(debug=True) diff --git a/requirements.txt b/requirements.txt index 7fd7b3a..333a15f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,20 +1,30 @@ +attrs==23.2.0 blinker==1.7.0 certifi==2024.2.2 charset-normalizer==3.3.2 click==8.1.7 colorama==0.4.6 dnspython==2.6.1 +flasgger==0.9.7.1 Flask==3.0.2 gunicorn==21.2.0 idna==3.6 itsdangerous==2.1.2 Jinja2==3.1.3 +jsonschema==4.21.1 +jsonschema-specifications==2023.12.1 +Markdown==3.5.2 MarkupSafe==2.1.5 +mistune==3.0.2 packaging==24.0 pymongo==4.6.2 python-dotenv==1.0.1 +PyYAML==6.0.1 +referencing==0.33.0 requests==2.31.0 +rpds-py==0.18.0 schedule==1.2.1 +six==1.16.0 tqdm==4.66.2 urllib3==2.2.1 Werkzeug==3.0.1 diff --git a/terms.md b/terms.md new file mode 100644 index 0000000..99a052b --- /dev/null +++ b/terms.md @@ -0,0 +1,27 @@ +# OpenGSQ APIs Terms of Service + +## 1. Acceptance of Terms + +By accessing and using the **OpenGSQ Master Server Search API**, you agree to comply with these terms and conditions. If you do not agree with any part of these terms, please refrain from using the API. + +## 2. Use of the API + +- You may use the API for legitimate purposes related to **server search and retrieval**. +- You must not misuse the API, including but not limited to: + - Attempting to gain unauthorized access to the API or its data. + - Introducing malicious code or interfering with the API's functionality. + - Violating any applicable laws or regulations. + +## 3. Disclaimer of Warranties + +- The API is provided "as is" without any warranties, express or implied. +- We do not guarantee the accuracy, reliability, or availability of the API. + +## 4. Limitation of Liability + +- **OpenGSQ** shall not be liable for any direct, indirect, incidental, special, or consequential damages arising from API use. +- You assume all risks associated with API usage. + +## 5. Changes to the TOS + +- We reserve the right to modify these terms at any time. Changes will be effective upon posting on our website. diff --git a/version.py b/version.py new file mode 100644 index 0000000..75977e6 --- /dev/null +++ b/version.py @@ -0,0 +1 @@ +__version__ = '1.0.0' \ No newline at end of file