From 9add9357f16bd5de56db1a4478abefb3935351d3 Mon Sep 17 00:00:00 2001 From: TheCataliasTNT2k <44349750+TheCataliasTNT2k@users.noreply.github.com> Date: Sun, 22 Mar 2020 03:38:50 +0100 Subject: [PATCH 1/9] Test github action workflow for experimental --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 0975b29..f0e4d9e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ # TODO -Fill out Dockerfile - Fill out docker-compose.yml Fill out GitHub Action workflow From 53388835285dc408028238197ceff7eb5a3f13a8 Mon Sep 17 00:00:00 2001 From: TheCataliasTNT2k <44349750+TheCataliasTNT2k@users.noreply.github.com> Date: Sun, 22 Mar 2020 03:41:08 +0100 Subject: [PATCH 2/9] Another test for github actions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f0e4d9e..4be1781 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ Fill out docker-compose.yml Fill out GitHub Action workflow -Fill out README +Fill out README! From 842ce2c6e9b65f7ff13e3c3077d4168bd9fa405f Mon Sep 17 00:00:00 2001 From: mibkvr <40341638+mibkvr@users.noreply.github.com> Date: Sun, 22 Mar 2020 10:54:06 +0100 Subject: [PATCH 3/9] Update Routes New: - User can't create Ticket if banned - new Route /ticket/id/answer Bugfixes --- app.py | 6 +++++- report/Blueprints/routes.py | 37 ++++++++++++++++++++++++++++++++++++- report/__init__.py | 15 +++++++-------- report/database.py | 4 +++- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index 0a71dc9..2f660cd 100644 --- a/app.py +++ b/app.py @@ -1,2 +1,6 @@ from report import app -app.run(host='0.0.0.0', port=5000) +from report import db + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000, debug=True) + db.create_all() diff --git a/report/Blueprints/routes.py b/report/Blueprints/routes.py index b9f3b56..8937645 100644 --- a/report/Blueprints/routes.py +++ b/report/Blueprints/routes.py @@ -24,8 +24,10 @@ def ticked_create(): print(e) return jsonify({'error': 'INVALID_SESSION'}), 400 - user_id = userdata.get("id") + if userdata.get("status") == 4: # Status 4 == User Banned + return jsonify({}), 200 + user_id = userdata.get("id") ticket = Ticket(taskId=data['task_id'], title=data['title'], body=data['body'], TicketType=data['TicketType'], user_id=user_id) db.session.add(ticket) @@ -130,3 +132,36 @@ def ticked_edit(id): return jsonify({}), 200 else: return jsonify({}), 500 + + +@main_page.route('/ticket//answer', methods=['PUT']) +def ticked_slove(id): + data = request.json + header = request.headers.get('Authorization') + + if header is not None and 'is_troll' in data: + pass + else: + return jsonify({'error': 'Missing Keys'}), 510 + + try: + userdata = jwt.decode(header, os.environ.get( + 'JWT_SECRET'), algorithms=['HS256']) + except Exception: + return jsonify({'error': 'Invalid Session'}), 510 + + role = userdata.get('role') + if role == 2: + if data['is_troll']: + # TODO: bann user + # User Microservice not Ready + print("User Banned") + return jsonify({}), 500 + else: + ticked_q = Ticket.query.get_or_404(id) + if ticked_q is not None: + ticked_q.isSloved = True + db.session.commit() + return jsonify({}), 500 + else: + jsonify({'forbidden': 'INVALID_PERMISSION'}), 403 diff --git a/report/__init__.py b/report/__init__.py index 9af1d34..3f58361 100644 --- a/report/__init__.py +++ b/report/__init__.py @@ -1,23 +1,22 @@ -from flask import Flask -from flask_sqlalchemy import SQLAlchemy -from flask_marshmallow import Marshmallow import os import sys -import pymysql - -app = Flask(__name__) +from flask import Flask +from flask_marshmallow import Marshmallow +from flask_sqlalchemy import SQLAlchemy +app = Flask(__name__) try: - db_path = "mysql+pymysql://" + os.environ.get("DATABASE_USERNAME") + ":" + os.environ.get("DATABASE_PASSWORD") + "@" + os.environ.get("DATABASE_HOSTNAME") + ":" + os.environ.get("DATABASE_PORT") + "/" + os.environ.get("DATABASE_DATABASE") + db_path = "mysql+pymysql://" + os.environ.get("DATABASE_USERNAME") + ":" + os.environ.get( + "DATABASE_PASSWORD") + "@" + os.environ.get("DATABASE_HOSTNAME") + ":" + os.environ.get( + "DATABASE_PORT") + "/" + os.environ.get("DATABASE_DATABASE") app.config['SQLALCHEMY_DATABASE_URI'] = db_path except TypeError as e: print(e) print("No Environ Var found") sys.exit(1) - app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) diff --git a/report/database.py b/report/database.py index b836ad6..8c4e444 100644 --- a/report/database.py +++ b/report/database.py @@ -10,6 +10,7 @@ class Ticket(db.Model): TicketType = db.Column(db.String(10)) role = db.Column(db.String(3)) user_id = db.Column(db.String(1000)) # ! change when >1000 user + isSloved = db.Column(db.Boolean(), default=False) def __init__(self, taskId, title, body, TicketType, user_id): self.taskId = taskId @@ -21,9 +22,10 @@ def __init__(self, taskId, title, body, TicketType, user_id): class TicketSchema(ma.Schema): class Meta: - fields = ('ticketId', 'taskId', 'title', 'body', 'TicketType') + fields = ('ticketId', 'taskId', 'title', 'body', 'TicketType', 'isSloved') ticketSchema = TicketSchema() ticketSchema_many = TicketSchema(many=True) db.create_all() + From 8ef593131635882501605315ecedf6de9952e56f Mon Sep 17 00:00:00 2001 From: mibkvr <40341638+mibkvr@users.noreply.github.com> Date: Sun, 22 Mar 2020 12:40:56 +0100 Subject: [PATCH 4/9] Try to add Gunicon --- Dockerfile | 12 +++++++----- report/__init__.py | 3 +++ wsgi.py | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 wsgi.py diff --git a/Dockerfile b/Dockerfile index 6ff2519..290c9df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,11 @@ -FROM python:3.8.2-alpine3.10 +FROM python:3.7-alpine + +EXPOSE 80 + COPY . /microservice/ WORKDIR /microservice/ +RUN apk add gcc musl-dev libffi-dev libressl-dev gnupg --update libxml2-dev libxslt-dev g++ bash RUN pip install --upgrade pip - -RUN apk add --update libxml2-dev libxslt-dev gcc g++ bash RUN pip install -r requirements.txt -ENTRYPOINT ["python"] -CMD ["app.py"] \ No newline at end of file + +CMD ["gunicorn", "--workers", "4", "wsgi:application", "--bind", "0.0.0.0:80", "--log-syslog", "--log-level", "DEBUG"] \ No newline at end of file diff --git a/report/__init__.py b/report/__init__.py index 3f58361..b6c221c 100644 --- a/report/__init__.py +++ b/report/__init__.py @@ -7,6 +7,7 @@ app = Flask(__name__) + try: db_path = "mysql+pymysql://" + os.environ.get("DATABASE_USERNAME") + ":" + os.environ.get( "DATABASE_PASSWORD") + "@" + os.environ.get("DATABASE_HOSTNAME") + ":" + os.environ.get( @@ -22,6 +23,8 @@ db = SQLAlchemy(app) ma = Marshmallow(app) +db.create_all() + from report.Blueprints.routes import main_page from report.Blueprints.error_handler import app_error diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..091546a --- /dev/null +++ b/wsgi.py @@ -0,0 +1,3 @@ +from report import app + +application = app \ No newline at end of file From b235abdef39f99869f7d9d4d647408ca56f616f1 Mon Sep 17 00:00:00 2001 From: mibkvr <40341638+mibkvr@users.noreply.github.com> Date: Sun, 22 Mar 2020 12:42:09 +0100 Subject: [PATCH 5/9] I'm an Idiot --> Forgot Requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 89be1d0..bf254c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ flask_sqlalchemy===2.4.1 marshmallow-sqlalchemy==0.22.3 pymysql==0.9.3 flask-marshmallow +gunicorn==20.0.4 \ No newline at end of file From 3b5cfb90a70d0ebabebe1e66baaeb129f08b5c38 Mon Sep 17 00:00:00 2001 From: iiestIT Date: Sun, 22 Mar 2020 15:01:36 +0100 Subject: [PATCH 6/9] Readme --- README.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4be1781..eb03127 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,20 @@ -# TODO -Fill out docker-compose.yml +# Report Microservice Microservice -Fill out GitHub Action workflow +## Explanations +### Routes +/ticket +/ticket/delete/ +/ticket/list +/ticket//edit +/ticket//answer -Fill out README! +## Documents +[Drafts & Documentation](https://github.com/E-Edu/draft-documents)
+[Git Workflow (German)](https://github.com/E-Edu/general/blob/master/guides/conventions.md)
+[Code Style (German)](https://github.com/E-Edu/general/blob/master/guides/conventions.md#code-style) + + +## License + +This project is licensed under the `GNU General Public License v3.0`
+See `LICENSE` for more information \ No newline at end of file From e46543cd0ca67651645a498bdb3f660f8b0ba4bf Mon Sep 17 00:00:00 2001 From: iiestIT Date: Sun, 22 Mar 2020 15:03:22 +0100 Subject: [PATCH 7/9] Readme2 --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eb03127..6e99c6f 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ## Explanations ### Routes -/ticket -/ticket/delete/ -/ticket/list -/ticket//edit -/ticket//answer +/ticket
+/ticket/delete/id
+/ticket/list
+/ticket/id/edit
+/ticket/id/answer ## Documents [Drafts & Documentation](https://github.com/E-Edu/draft-documents)
From 71cc53b8cd2ffadc289f93cca4ffc305442c3886 Mon Sep 17 00:00:00 2001 From: mibkvr <40341638+mibkvr@users.noreply.github.com> Date: Sun, 22 Mar 2020 15:08:43 +0100 Subject: [PATCH 8/9] New PEP8 formatted --- docker-compose.yml | 52 +++++++++++++++--------------- report/Blueprints/error_handler.py | 9 +++--- report/Blueprints/routes.py | 6 ++-- report/__init__.py | 1 - report/database.py | 3 +- test.py | 3 +- wsgi.py | 2 +- 7 files changed, 37 insertions(+), 39 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7e3aa80..429dd03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,32 +1,32 @@ version: '3.7' report_database: - image: mariadb:latest - volumes: - - /var/data/mariadb:/var/lib/mysql # to save the mariadb content - ports: - - 3306:3306 #debug - environment: - - MYSQL_ROOT_PASSWORD=da7tnqw79e5v6nbqw3v5rtwev57mtwm5vrftw75vfnm275v2 - - MYSQL_USER=report - - MYSQL_PASSWORD=TuqWuRdjLbSPTRqBnnEU24ZSsqAy9b6LbXA8ZuQg - - MYSQL_DATABASE=report - restart: unless-stopped - container_name: report_database - hostname: report_database + image: mariadb:latest + volumes: + - /var/data/mariadb:/var/lib/mysql # to save the mariadb content + ports: + - 3306:3306 #debug + environment: + - MYSQL_ROOT_PASSWORD=da7tnqw79e5v6nbqw3v5rtwev57mtwm5vrftw75vfnm275v2 + - MYSQL_USER=report + - MYSQL_PASSWORD=TuqWuRdjLbSPTRqBnnEU24ZSsqAy9b6LbXA8ZuQg + - MYSQL_DATABASE=report + restart: unless-stopped + container_name: report_database + hostname: report_database report_microservice: - image: eedu/reportms - ports: - - 5000:5000 - environment: - - DATABASE_HOSTNAME= - - DATABASE_PORT= - - DATABASE_USERNAME= - - DATABASE_PASSWORD= - - DATABASE_DATABASE= - - JWT_SECRET= - - SERVICE_SECRET= - restart: unless-stopped - container_name: report_microservice + image: eedu/reportms + ports: + - 5000:5000 + environment: + - DATABASE_HOSTNAME= + - DATABASE_PORT= + - DATABASE_USERNAME= + - DATABASE_PASSWORD= + - DATABASE_DATABASE= + - JWT_SECRET= + - SERVICE_SECRET= + restart: unless-stopped + container_name: report_microservice diff --git a/report/Blueprints/error_handler.py b/report/Blueprints/error_handler.py index 48fcbfc..9b3f1d0 100644 --- a/report/Blueprints/error_handler.py +++ b/report/Blueprints/error_handler.py @@ -1,12 +1,13 @@ -from flask import Blueprint, render_template, abort,request, jsonify +from flask import Blueprint, jsonify +app_error = Blueprint('error-handler', __name__) -app_error = Blueprint('error-handler',__name__) @app_error.app_errorhandler(404) def handle_404_error(e): - return jsonify({'error':'Page not found'}),404 + return jsonify({'error': 'Page not found'}), 404 + @app_error.app_errorhandler(405) def handle_405_error(e): - return jsonify({'error':'Method not allowed'}),405 \ No newline at end of file + return jsonify({'error': 'Method not allowed'}), 405 diff --git a/report/Blueprints/routes.py b/report/Blueprints/routes.py index 8937645..4b2d341 100644 --- a/report/Blueprints/routes.py +++ b/report/Blueprints/routes.py @@ -1,7 +1,5 @@ -import json -import os - import jwt +import os from flask import Blueprint, request, jsonify from report import db @@ -24,7 +22,7 @@ def ticked_create(): print(e) return jsonify({'error': 'INVALID_SESSION'}), 400 - if userdata.get("status") == 4: # Status 4 == User Banned + if userdata.get("status") == 4: # Status 4 == User Banned return jsonify({}), 200 user_id = userdata.get("id") diff --git a/report/__init__.py b/report/__init__.py index b6c221c..98563b5 100644 --- a/report/__init__.py +++ b/report/__init__.py @@ -7,7 +7,6 @@ app = Flask(__name__) - try: db_path = "mysql+pymysql://" + os.environ.get("DATABASE_USERNAME") + ":" + os.environ.get( "DATABASE_PASSWORD") + "@" + os.environ.get("DATABASE_HOSTNAME") + ":" + os.environ.get( diff --git a/report/database.py b/report/database.py index 8c4e444..af6abf4 100644 --- a/report/database.py +++ b/report/database.py @@ -10,7 +10,7 @@ class Ticket(db.Model): TicketType = db.Column(db.String(10)) role = db.Column(db.String(3)) user_id = db.Column(db.String(1000)) # ! change when >1000 user - isSloved = db.Column(db.Boolean(), default=False) + isSloved = db.Column(db.Boolean(), default=False) def __init__(self, taskId, title, body, TicketType, user_id): self.taskId = taskId @@ -28,4 +28,3 @@ class Meta: ticketSchema = TicketSchema() ticketSchema_many = TicketSchema(many=True) db.create_all() - diff --git a/test.py b/test.py index 994fbac..e45fe70 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,5 @@ import jwt + asd = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256') -jwt.decode(asd, 'secret123', algorithms=['HS256']) \ No newline at end of file +jwt.decode(asd, 'secret123', algorithms=['HS256']) diff --git a/wsgi.py b/wsgi.py index 091546a..177edc4 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,3 +1,3 @@ from report import app -application = app \ No newline at end of file +application = app From 37a7461d25212de85b9c6f40dc253c9ffcedc555 Mon Sep 17 00:00:00 2001 From: mibkvr <40341638+mibkvr@users.noreply.github.com> Date: Wed, 1 Apr 2020 13:50:44 +0200 Subject: [PATCH 9/9] Hotfix: Fixed Port --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 429dd03..1eee1dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ report_database: report_microservice: image: eedu/reportms ports: - - 5000:5000 + - 80:80 environment: - DATABASE_HOSTNAME= - DATABASE_PORT=