2019-04-17 12:46:46 +00:00
|
|
|
""" Server-package
|
|
|
|
|
|
|
|
Initialize app, cors, database and bcrypt (for passwordhashing) and added it to the application.
|
|
|
|
Initialize also a singelton for the AccesTokenControler and start the Thread.
|
|
|
|
|
|
|
|
"""
|
2019-05-02 23:40:13 +00:00
|
|
|
import logging
|
|
|
|
from logging.handlers import WatchedFileHandler
|
|
|
|
import sys
|
|
|
|
|
2019-12-19 07:12:29 +00:00
|
|
|
MONEY = "moneymaster"
|
|
|
|
GASTRO = "gastro"
|
|
|
|
USER = "user"
|
|
|
|
BAR = "bar"
|
|
|
|
|
2019-05-02 23:40:13 +00:00
|
|
|
FORMATTER = logging.Formatter("%(asctime)s — %(name)s — %(levelname)s — %(message)s")
|
|
|
|
|
|
|
|
logFileHandler = WatchedFileHandler("testlog.log")
|
|
|
|
logFileHandler.setFormatter(FORMATTER)
|
|
|
|
|
|
|
|
logStreamHandler = logging.StreamHandler(stream=sys.stdout)
|
|
|
|
logStreamHandler.setFormatter(FORMATTER)
|
|
|
|
|
|
|
|
def getLogger(logger_name):
|
|
|
|
logger = logging.getLogger(logger_name)
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
logger.addHandler(logFileHandler)
|
|
|
|
logger.addHandler(logStreamHandler)
|
|
|
|
|
|
|
|
logger.propagate = False
|
|
|
|
|
|
|
|
return logger
|
|
|
|
|
|
|
|
LOGGER = getLogger(__name__)
|
|
|
|
LOGGER.info("Initialize App")
|
2019-04-17 12:46:46 +00:00
|
|
|
|
2019-12-19 07:12:29 +00:00
|
|
|
class Singleton(type):
|
|
|
|
_instances = {}
|
|
|
|
def __call__(cls, *args, **kwargs):
|
|
|
|
if cls not in cls._instances:
|
|
|
|
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
|
|
|
return cls._instances[cls]
|
2019-12-19 17:26:41 +00:00
|
|
|
|
2019-12-19 07:12:29 +00:00
|
|
|
from .controller.databaseController import DatabaseController
|
|
|
|
db = DatabaseController()
|
|
|
|
from .controller.ldapController import LDAPController
|
|
|
|
ldapController = LDAPController()
|
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
def getDatabesController():
|
|
|
|
if db is not None:
|
|
|
|
return db
|
|
|
|
else:
|
|
|
|
return DatabaseController()
|
|
|
|
def getLDAPController():
|
|
|
|
if ldapController is not None:
|
|
|
|
return ldapController
|
|
|
|
else:
|
|
|
|
return LDAPController()
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-19 07:12:29 +00:00
|
|
|
|
2019-04-11 21:56:55 +00:00
|
|
|
from flask import Flask
|
2019-04-12 12:51:37 +00:00
|
|
|
from flask_cors import CORS
|
2019-04-11 21:56:55 +00:00
|
|
|
from .controller.accesTokenController import AccesTokenController
|
2019-01-13 19:07:46 +00:00
|
|
|
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.info("Build APP")
|
2019-01-13 19:07:46 +00:00
|
|
|
app = Flask(__name__)
|
2019-04-12 12:51:37 +00:00
|
|
|
CORS(app)
|
2019-04-11 21:56:55 +00:00
|
|
|
# app.config['SECRET_KEY'] = '0a657b97ef546da90b2db91862ad4e29'
|
2019-05-02 23:40:13 +00:00
|
|
|
accesTokenController = AccesTokenController("GERUECHT")
|
2019-01-13 19:07:46 +00:00
|
|
|
|
2019-12-19 07:12:29 +00:00
|
|
|
|
2019-05-01 20:43:28 +00:00
|
|
|
|
2019-01-13 23:25:25 +00:00
|
|
|
|
2019-04-11 21:56:55 +00:00
|
|
|
from geruecht import routes
|
2019-12-22 21:27:39 +00:00
|
|
|
from geruecht.baruser.routes import baruser
|
2019-12-19 17:26:41 +00:00
|
|
|
from geruecht.finanzer.routes import finanzer
|
2019-05-01 20:43:28 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
LOGGER.info("Registrate bluebrints")
|
2019-12-22 21:27:39 +00:00
|
|
|
app.register_blueprint(baruser)
|
2019-12-19 17:26:41 +00:00
|
|
|
app.register_blueprint(finanzer)
|