diff --git a/requirements.txt b/requirements.txt index cb01866..9df3fb8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,6 @@ gunicorn marshmallow Flask Flask-RESTful -requests \ No newline at end of file +requests +werkzeug +filetype \ No newline at end of file diff --git a/src/app.py b/src/app.py index 0103e8b..92b7430 100644 --- a/src/app.py +++ b/src/app.py @@ -13,7 +13,7 @@ Main Flask RESTful API """ __author__ = "@tormakris" -__copyright__ = "Copyright 2019, KSZK" +__copyright__ = "Copyright 2020, Birbnetes Team" __module_name__ = "app" __version__text__ = "1" diff --git a/src/config.py b/src/config.py index f4135f1..ea09504 100644 --- a/src/config.py +++ b/src/config.py @@ -8,7 +8,7 @@ Main Flask RESTful API __author__ = "@tormakris" -__copyright__ = "Copyright 2019, KSZK" +__copyright__ = "Copyright 2020, Birbnetes Team" __module_name__ = "app" __version__text__ = "1" diff --git a/src/resources.py b/src/resources.py index 62bd44c..ceeac1f 100644 --- a/src/resources.py +++ b/src/resources.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 import logging -import os +import json from flask import request -from flask_restful import Resource +from flask_restful import Resource, reqparse +from werkzeug.datastructures import FileStorage +import filetype from schemas import * """ @@ -10,7 +12,7 @@ Flask Restful endpoints """ __author__ = '@tormakris' -__copyright__ = "Copyright 2019, KSZK" +__copyright__ = "Copyright 2020, Birbnetes Team" __module_name__ = "endpoints" __version__text__ = "1" @@ -22,5 +24,33 @@ class SampleResource(Resource): Sample endpoint See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service """ + def post(self): - pass + """ + Post request send to the endpoint + :return: + """ + parse = reqparse.RequestParser() + parse.add_argument('soundFile', type=FileStorage, location='soundFile') + parse.add_argument('description', type=str, location='description') + args = parse.parse_args() + soundFile = args['soundFile'] + description = args['description'] + kind = filetype.guess(soundFile) + if kind.mime != 'wav': + LOGGER.error( + "Input file was not WAV. Recieved metadata: {}", + description) + return {'status': 'error', 'message': 'Input file not WAV.'}, 415 + try: + desc = json.loads(description) + except Exception as e: + LOGGER.exception(e) + return {'status': 'error', + 'message': 'Input JSON could not be parsed'}, 400 + validate_errors = InputSchema().validate(desc) + if validate_errors: + LOGGER.error( + "Input JSON did not conform to schema. It was: {}", desc) + return {'status': 'error', + 'message': 'Input JSON schema invalid'}, 417 diff --git a/src/schemas.py b/src/schemas.py index 726d137..552c8da 100644 --- a/src/schemas.py +++ b/src/schemas.py @@ -8,7 +8,7 @@ Schemas of input objects __author__ = "@tormakris" -__copyright__ = "Copyright 2019, KSZK" +__copyright__ = "Copyright 2020, Birbnetes Team" __module_name__ = "schemas" __version__text__ = "1"