init
This commit is contained in:
48
src/app.py
Normal file
48
src/app.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask import Flask
|
||||
from flask_restful import Api
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
|
||||
from redis_client import redis_client
|
||||
from config import Config
|
||||
from marshm import ma
|
||||
from resources import SampleResource
|
||||
|
||||
"""
|
||||
Main Flask RESTful API
|
||||
"""
|
||||
|
||||
__author__ = "@tormakris"
|
||||
__copyright__ = "Copyright 2021, KMLabz Team"
|
||||
__module_name__ = "app"
|
||||
__version__text__ = "1"
|
||||
|
||||
if Config.SENTRY_DSN:
|
||||
sentry_sdk.init(
|
||||
dsn=Config.SENTRY_DSN,
|
||||
integrations=[FlaskIntegration()],
|
||||
traces_sample_rate=0.0,
|
||||
send_default_pii=True,
|
||||
release=Config.RELEASE_ID,
|
||||
environment=Config.RELEASEMODE
|
||||
)
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
api = Api(app)
|
||||
ma.init_app(app)
|
||||
|
||||
redis_client.init_app(app)
|
||||
|
||||
|
||||
api.add_resource(SampleResource, "/input")
|
||||
|
||||
|
||||
if __name__ != '__main__':
|
||||
import logging
|
||||
|
||||
gunicorn_logger = logging.getLogger('gunicorn.error')
|
||||
app.logger.handlers = gunicorn_logger.handlers
|
||||
app.logger.setLevel(gunicorn_logger.level)
|
||||
22
src/config.py
Normal file
22
src/config.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
|
||||
"""
|
||||
Main Flask RESTful API
|
||||
"""
|
||||
|
||||
__author__ = "@tormakris"
|
||||
__copyright__ = "Copyright 2021, KMLabz Team"
|
||||
__module_name__ = "config"
|
||||
__version__text__ = "1"
|
||||
|
||||
|
||||
class Config:
|
||||
PORT = 8080
|
||||
DEBUG = os.environ.get("DEBUG", "true").lower() in ["true", "yes", "1"]
|
||||
|
||||
SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
||||
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
||||
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
|
||||
|
||||
REDIS_URL = os.environ['CACHE_REDIS_URL']
|
||||
14
src/marshm.py
Normal file
14
src/marshm.py
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from flask_marshmallow import Marshmallow
|
||||
|
||||
"""
|
||||
Marshmallow
|
||||
"""
|
||||
|
||||
__author__ = '@tormakris'
|
||||
__copyright__ = "Copyright 2021, KMLabz Team"
|
||||
__module_name__ = "marshm"
|
||||
__version__text__ = "1"
|
||||
|
||||
ma = Marshmallow()
|
||||
4
src/redis_client.py
Normal file
4
src/redis_client.py
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask_redis import FlaskRedis
|
||||
|
||||
redis_client = FlaskRedis()
|
||||
25
src/schemas.py
Normal file
25
src/schemas.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
from marshm import ma
|
||||
from marshmallow import fields
|
||||
|
||||
|
||||
"""
|
||||
Schemas of api objects
|
||||
"""
|
||||
|
||||
|
||||
__author__ = "@tormakris"
|
||||
__copyright__ = "Copyright 2021, KMLabz Team"
|
||||
__module_name__ = "schemas"
|
||||
__version__text__ = "1"
|
||||
|
||||
|
||||
class SampleSchema(ma.Schema):
|
||||
"""
|
||||
Parameters:
|
||||
- date (date)
|
||||
- device_id (int)
|
||||
"""
|
||||
|
||||
date = fields.DateTime(required=True)
|
||||
device_id = fields.Integer(required=True)
|
||||
Reference in New Issue
Block a user