diff --git a/authentik/lib/setup.py b/authentik/lib/setup.py deleted file mode 100644 index 8c39f7f8f9..0000000000 --- a/authentik/lib/setup.py +++ /dev/null @@ -1,24 +0,0 @@ -import os -import warnings - -from cryptography.hazmat.backends.openssl.backend import backend -from defusedxml import defuse_stdlib - -from authentik.lib.config import CONFIG - -warnings.filterwarnings("ignore", "SelectableGroups dict interface") -warnings.filterwarnings( - "ignore", - "defusedxml.lxml is no longer supported and will be removed in a future release.", -) -warnings.filterwarnings( - "ignore", - "defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead.", -) - -defuse_stdlib() - -if CONFIG.get_bool("compliance.fips.enabled", False): - backend._enable_fips() - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "authentik.root.settings") diff --git a/authentik/root/asgi.py b/authentik/root/asgi.py index f48a094524..613add4adb 100644 --- a/authentik/root/asgi.py +++ b/authentik/root/asgi.py @@ -12,10 +12,11 @@ from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application from sentry_sdk.integrations.asgi import SentryAsgiMiddleware -import authentik.lib.setup # noqa +from authentik.root.setup import setup # DJANGO_SETTINGS_MODULE is set in gunicorn.conf.py +setup() django.setup() diff --git a/authentik/root/setup.py b/authentik/root/setup.py new file mode 100644 index 0000000000..fdb5f162f9 --- /dev/null +++ b/authentik/root/setup.py @@ -0,0 +1,26 @@ +import os +import warnings + +from cryptography.hazmat.backends.openssl.backend import backend +from defusedxml import defuse_stdlib + +from authentik.lib.config import CONFIG + + +def setup(): + warnings.filterwarnings("ignore", "SelectableGroups dict interface") + warnings.filterwarnings( + "ignore", + "defusedxml.lxml is no longer supported and will be removed in a future release.", + ) + warnings.filterwarnings( + "ignore", + "defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead.", + ) + + defuse_stdlib() + + if CONFIG.get_bool("compliance.fips.enabled", False): + backend._enable_fips() + + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "authentik.root.settings") diff --git a/lifecycle/gunicorn.conf.py b/lifecycle/gunicorn.conf.py index 4b269feb99..58b6643807 100644 --- a/lifecycle/gunicorn.conf.py +++ b/lifecycle/gunicorn.conf.py @@ -9,7 +9,6 @@ from typing import TYPE_CHECKING from prometheus_client.values import MultiProcessValue -import authentik.lib.setup # noqa from authentik import get_full_version from authentik.lib.config import CONFIG from authentik.lib.debug import start_debug_server @@ -17,6 +16,7 @@ from authentik.lib.logging import get_logger_config from authentik.lib.utils.http import get_http_session from authentik.lib.utils.reflection import get_env from authentik.root.install_id import get_install_id_raw +from authentik.root.setup import setup from lifecycle.migrate import run_migrations from lifecycle.wait_for_db import wait_for_db from lifecycle.worker import DjangoUvicornWorker @@ -27,6 +27,8 @@ if TYPE_CHECKING: from authentik.root.asgi import AuthentikAsgi +setup() + wait_for_db() _tmp = Path(gettempdir()) diff --git a/manage.py b/manage.py index 9d495c73eb..060df5e2c7 100755 --- a/manage.py +++ b/manage.py @@ -6,11 +6,11 @@ import sys from django.utils.autoreload import DJANGO_AUTORELOAD_ENV -import authentik.lib.setup # noqa - +from authentik.root.setup import setup from lifecycle.migrate import run_migrations from lifecycle.wait_for_db import wait_for_db +setup() if __name__ == "__main__": wait_for_db()