This commit is contained in:
parent
4d1de2a1f6
commit
afd8f4a9fd
@ -7,4 +7,5 @@ requests
|
|||||||
werkzeug
|
werkzeug
|
||||||
filetype
|
filetype
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
flask_sqlalchemy
|
flask_sqlalchemy
|
||||||
|
rstr
|
@ -19,7 +19,7 @@ class SampleMetadata(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True, auto_increment=True)
|
id = db.Column(db.Integer, primary_key=True, auto_increment=True)
|
||||||
timestamp = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
|
timestamp = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
|
||||||
|
|
||||||
device_id = db.Column(db.String, nullable=False)
|
device_id = db.Column(db.Integer, nullable=False)
|
||||||
device_date = db.Column(db.DateTime, nullable=False)
|
device_date = db.Column(db.DateTime, nullable=False)
|
||||||
|
|
||||||
tag = db.Column(db.String, nullable=False)
|
tag = db.Column(db.String(32), nullable=False)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
from flask import request
|
import rstr
|
||||||
from flask_restful import Resource, reqparse
|
from flask_restful import Resource, reqparse
|
||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
import filetype
|
import filetype
|
||||||
@ -50,12 +50,18 @@ class SampleResource(Resource):
|
|||||||
LOGGER.exception(e)
|
LOGGER.exception(e)
|
||||||
return {'status': 'error',
|
return {'status': 'error',
|
||||||
'message': 'Input JSON could not be parsed'}, 400
|
'message': 'Input JSON could not be parsed'}, 400
|
||||||
validate_errors = InputSchema().validate(desc)
|
validate_errors = SampleSchema().validate(desc)
|
||||||
if validate_errors:
|
if validate_errors:
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
"Input JSON did not conform to schema. It was: {}", desc)
|
"Input JSON did not conform to schema. It was: {}", desc)
|
||||||
return {'status': 'error',
|
return {'status': 'error',
|
||||||
'message': 'Input JSON schema invalid'}, 417
|
'message': 'Input JSON schema invalid'}, 417
|
||||||
# TODO: Preserve input data in relational DB
|
generated_tag = rstr.xeger(r'^[a-zA-Z]+[0-9a-zA-Z_]*$', 2, 32)
|
||||||
|
|
||||||
|
record = SampleMetadata(device_id=desc['device_id'], device_date=desc['date'], tag=generated_tag)
|
||||||
|
db.session.add(record)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
# TODO: Pass data and tag to ObjectStorage
|
# TODO: Pass data and tag to ObjectStorage
|
||||||
# TODO: Pass tag to MQ
|
# TODO: Pass tag to MQ
|
||||||
|
Loading…
Reference in New Issue
Block a user