ki-backend/app.py

47 lines
1.6 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-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 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__)
2022-01-26 23:34:38 +01:00
# Configure logging
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)
2022-02-28 18:48:32 +01:00
app.logger.propagate = False # do not forward messages to the root logger
logging.basicConfig(level=loglevel,
format='[%(asctime)s] %(levelname)s [%(name)s] %(message)s') # configure root logger as fallback
logging.getLogger('werkzeug').propagate = False # werkzeug has its own ColorStreamHandler
set_library_log_detail_level(BASIC) # ldap3 has different verbosity levels internally
2021-07-11 12:16:41 +02:00
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
2022-01-26 21:43:31 +01:00
app.logger.info("Hello from KI")
2021-07-11 12:16:41 +02:00
2021-07-05 19:37:05 +02:00
from ki import module # noqa