90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
""" 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.
|
|
|
|
"""
|
|
from pathlib import Path
|
|
_modpath = Path(__file__).parent
|
|
|
|
from flask import Flask
|
|
from flask_cors import CORS
|
|
from flask_ldapconn import LDAPConn
|
|
import ssl
|
|
import pkg_resources, yaml
|
|
|
|
from logging.config import dictConfig
|
|
|
|
with (_modpath/'logging.yml').open(mode='rb') as file:
|
|
config = yaml.safe_load(file.read())
|
|
dictConfig(config)
|
|
|
|
import logging
|
|
from werkzeug.local import LocalProxy
|
|
logger = LocalProxy(lambda: logging.getLogger(__name__))
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
CORS(app)
|
|
|
|
with app.app_context():
|
|
from .system.controller import dbConfig, ldapConfig
|
|
from .system.database import db
|
|
app.config['SECRET_KEY'] = '0a657b97ef546da90b2db91862ad4e29'
|
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://{user}:{passwd}@{host}/{database}'.format(
|
|
user=dbConfig['user'],
|
|
passwd=dbConfig['passwd'],
|
|
host=dbConfig['URL'],
|
|
database=dbConfig['database'])
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
# app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
|
|
app.config['LDAP_SERVER'] = ldapConfig['URL']
|
|
app.config['LDAP_PORT'] = ldapConfig['PORT']
|
|
if ldapConfig['BIND_DN']:
|
|
app.config['LDAP_BINDDN'] = ldapConfig['BIND_DN']
|
|
else:
|
|
app.config['LDAP_BINDDN'] = ldapConfig['DN']
|
|
if ldapConfig['BIND_SECRET']:
|
|
app.config['LDAP_SECRET'] = ldapConfig['BIND_SECRET']
|
|
app.config['LDAP_USE_TLS'] = False
|
|
app.config['LDAP_USE_SSL'] = ldapConfig['SSL']
|
|
app.config['LDAP_TLS_VERSION'] = ssl.PROTOCOL_TLSv1_2
|
|
app.config['LDAP_REQUIRE_CERT'] = ssl.CERT_NONE
|
|
app.config['FORCE_ATTRIBUTE_VALUE_AS_LIST'] = True
|
|
|
|
app.config['FG_AUTH_BACKENDS'] = [
|
|
entry_point.load() for entry_point in pkg_resources.iter_entry_points('flaschengeist.auth')
|
|
]
|
|
|
|
ldap = LDAPConn(app)
|
|
db.init_app(app)
|
|
|
|
discovered_plugins = {
|
|
entry_point.name: entry_point.load()
|
|
for entry_point in pkg_resources.iter_entry_points('flaschengeist.plugin')
|
|
}
|
|
|
|
#from geruecht import routes
|
|
#from geruecht.baruser.routes import baruser
|
|
#from geruecht.finanzer.routes import finanzer
|
|
#from geruecht.user.routes import user
|
|
#from geruecht.vorstand.routes import vorstand
|
|
#from geruecht.gastro.routes import gastrouser
|
|
#from geruecht.registration_route import registration
|
|
|
|
app.logger.info("Registrate bluebrints")
|
|
for name in discovered_plugins:
|
|
app.logger.info("Register plugin: %s" % name)
|
|
app.register_blueprint(discovered_plugins[name]())
|
|
|
|
return app
|
|
#app.register_blueprint(baruser)
|
|
#app.register_blueprint(finanzer)
|
|
#app.register_blueprint(user)
|
|
#app.register_blueprint(vorstand)
|
|
#app.register_blueprint(gastrouser)
|
|
#app.register_blueprint(registration)
|