create project structure
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
59
src/app.py
Normal file
59
src/app.py
Normal file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
import logging
|
||||
from flask import Flask
|
||||
from flask_restful import Api
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
|
||||
from config import *
|
||||
from db import db
|
||||
from marshm import ma
|
||||
"""
|
||||
Main Flask RESTful API
|
||||
"""
|
||||
|
||||
__author__ = "@tormakris"
|
||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||
__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__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
|
||||
|
||||
api = Api(app)
|
||||
db.init_app(app)
|
||||
ma.init_app(app)
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
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, "/sample")
|
||||
# api.add_resource(SampleParameterResource, '/sample/<tag>')
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(
|
||||
debug=bool(DEBUG),
|
||||
host="0.0.0.0",
|
||||
port=int(PORT),
|
||||
)
|
27
src/config.py
Normal file
27
src/config.py
Normal file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
|
||||
|
||||
"""
|
||||
Configuration variables
|
||||
"""
|
||||
|
||||
|
||||
__author__ = "@tormakris"
|
||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||
__module_name__ = "config"
|
||||
__version__text__ = "1"
|
||||
|
||||
|
||||
PORT = os.environ.get("CNC_SERVICE_PORT", 8080)
|
||||
DEBUG = os.environ.get("CNC_SERVICE_DEBUG", True)
|
||||
|
||||
|
||||
SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
||||
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
||||
RELEASEMODE = os.environ.get("CNC_SERVICE_RELEASEMODE", "dev")
|
||||
|
||||
POSTGRES_HOSTNAME = os.getenv("CNC_POSTGRES_HOSTNAME", "localhost")
|
||||
POSTGRES_USERNAME = os.getenv("CNC_POSTGRES_USERNAME", "cnc-service")
|
||||
POSTGRES_PASSWORD = os.getenv("CNC_POSTGRES_PASSWORD", "cnc-service")
|
||||
POSTGRES_DB = os.getenv("CNC_POSTGRES_DB", "cnc-service")
|
13
src/db.py
Normal file
13
src/db.py
Normal file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
"""
|
||||
SQLAlchemy definition
|
||||
"""
|
||||
|
||||
__author__ = '@tormakris'
|
||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||
__module_name__ = "db"
|
||||
__version__text__ = "1"
|
||||
|
||||
db = SQLAlchemy()
|
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 definition
|
||||
"""
|
||||
|
||||
__author__ = '@tormakris'
|
||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||
__module_name__ = "marshm"
|
||||
__version__text__ = "1"
|
||||
|
||||
ma = Marshmallow()
|
Reference in New Issue
Block a user