project layout done
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-03-25 01:19:22 +01:00
parent 265d43f79b
commit 03bf58bab3
8 changed files with 177 additions and 13 deletions

50
src/app.py Normal file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python3
import logging
import sentry_sdk
from flask import Flask
from flask_restful import Api
from sentry_sdk.integrations.flask import FlaskIntegration
from config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, PORT, DEBUG
from resources import *
"""
Main Flask RESTful API
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "app"
__version__text__ = "1"
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[FlaskIntegration()],
send_default_pii=True,
release=RELEASE_ID,
environment=RELEASEMODE
)
app = Flask(__name__)
api = Api(app)
formatter = logging.Formatter(
fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s"
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
api.add_resource(SampleResource, "/v1/input/sample")
if __name__ == "__main__":
app.run(
debug=bool(DEBUG),
host="0.0.0.0",
port=int(PORT),
)

22
src/config.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import os
"""
Main Flask RESTful API
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "app"
__version__text__ = "1"
PORT = os.environ.get("INPUT_SERVICE_PORT", 8080)
DEBUG = os.environ.get("INPUT_SERVICE_DEBUG", True)
SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID")
RELEASEMODE = os.environ.get("INPUT_SERVICE_RELEASEMODE")

26
src/resources.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import logging
import os
from flask import request
from flask_restful import Resource
from schemas import *
"""
Flask Restful endpoints
"""
__author__ = '@tormakris'
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "endpoints"
__version__text__ = "1"
LOGGER = logging.getLogger(__name__)
class SampleResource(Resource):
"""
Sample endpoint
See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
"""
def post(self):
pass

25
src/schemas.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
from marshmallow import Schema, fields
"""
Schemas of input objects
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "schemas"
__version__text__ = "1"
class SampleSchema(Schema):
""" /v1/email/pay - POST
Parameters:
- date (date)
- device_id (str)
"""
date = fields.Date(required=True)
device_id = fields.Str(required=True)