validate
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2020-03-25 02:36:05 +01:00
parent 03bf58bab3
commit 7d7227aa47
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
5 changed files with 40 additions and 8 deletions

View File

@ -3,4 +3,6 @@ gunicorn
marshmallow
Flask
Flask-RESTful
requests
requests
werkzeug
filetype

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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"