ki-backend/app.py

46 lines
1.4 KiB
Python
Raw Permalink Normal View History

2021-07-05 19:37:05 +02:00
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
2021-06-21 17:35:28 +02:00
import logging
2021-06-06 22:25:10 +02:00
import os
from dotenv import load_dotenv, find_dotenv
from flask import Flask
2021-06-21 22:21:25 +02:00
from flask_cors import CORS
2021-07-11 12:16:41 +02:00
from flask.logging import default_handler
2021-06-06 22:25:10 +02:00
from flask_migrate import Migrate
2021-07-11 12:16:41 +02:00
from flask_sqlalchemy import SQLAlchemy
from ldap3.utils.log import logger as ldap3_logger
from ldap3.utils.log import set_library_log_detail_level, BASIC
2021-06-06 22:25:10 +02:00
load_dotenv(find_dotenv())
2021-07-11 12:16:41 +02:00
app = Flask(__name__)
2021-06-21 17:35:28 +02:00
loglevel = os.getenv("KI_LOGLEVEL", logging.WARNING)
loglevel = int(loglevel)
2021-07-11 12:16:41 +02:00
app.logger.setLevel(loglevel)
2021-06-21 17:35:28 +02:00
logging.basicConfig(level=loglevel)
2021-07-11 12:16:41 +02:00
set_library_log_detail_level(BASIC)
ldap3_logger.addHandler(default_handler)
2021-06-21 17:35:28 +02:00
app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("SQLALCHEMY_DATABASE_URI")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["KI_DATA_DIR"] = os.path.dirname(__file__) + "/data"
2021-06-21 22:21:25 +02:00
app.config["CORS_ORIGINS"] = os.getenv("CORS_ORIGINS", "*")
2021-07-11 12:16:41 +02:00
app.config["KI_AUTH"] = os.getenv("KI_AUTH")
app.config["KI_LDAP_URL"] = os.getenv("KI_LDAP_URL")
2021-09-15 19:44:11 +02:00
app.config["KI_LDAP_AUTH_USER"] = os.getenv("KI_LDAP_AUTH_USER")
app.config["KI_LDAP_AUTH_PASSWORD"] = os.getenv("KI_LDAP_AUTH_PASSWORD")
app.config["KI_LDAP_BASE_DN"] = os.getenv("KI_LDAP_BASE_DN")
2021-07-11 12:16:41 +02:00
2021-06-21 22:21:25 +02:00
CORS(app)
2021-06-06 22:25:10 +02:00
db = SQLAlchemy(app)
2021-11-22 20:11:58 +01:00
migrate = Migrate(app, db, compare_type=True)
2021-06-06 22:25:10 +02:00
2021-07-11 12:16:41 +02:00
logging.debug("Hello from KI")
2021-07-05 19:37:05 +02:00
from ki import module # noqa