diff --git a/authentik/lib/setup.py b/authentik/lib/setup.py new file mode 100644 index 0000000000..8c39f7f8f9 --- /dev/null +++ b/authentik/lib/setup.py @@ -0,0 +1,24 @@ +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 4aaddf83d6..f48a094524 100644 --- a/authentik/root/asgi.py +++ b/authentik/root/asgi.py @@ -9,13 +9,13 @@ https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ import django from channels.routing import ProtocolTypeRouter, URLRouter -from defusedxml import defuse_stdlib from django.core.asgi import get_asgi_application from sentry_sdk.integrations.asgi import SentryAsgiMiddleware +import authentik.lib.setup # noqa + # DJANGO_SETTINGS_MODULE is set in gunicorn.conf.py -defuse_stdlib() django.setup() diff --git a/authentik/tasks/setup.py b/authentik/tasks/setup.py index 6b480ea393..26b4387ff2 100644 --- a/authentik/tasks/setup.py +++ b/authentik/tasks/setup.py @@ -1,27 +1,4 @@ -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") +import authentik.lib.setup # noqa import django # noqa: E402 diff --git a/lifecycle/gunicorn.conf.py b/lifecycle/gunicorn.conf.py index 07d226ea6c..4b269feb99 100644 --- a/lifecycle/gunicorn.conf.py +++ b/lifecycle/gunicorn.conf.py @@ -7,10 +7,9 @@ from pathlib import Path from tempfile import gettempdir from typing import TYPE_CHECKING -from cryptography.hazmat.backends.openssl.backend import backend -from defusedxml import defuse_stdlib 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 @@ -28,11 +27,6 @@ if TYPE_CHECKING: from authentik.root.asgi import AuthentikAsgi -defuse_stdlib() - -if CONFIG.get_bool("compliance.fips.enabled", False): - backend._enable_fips() - wait_for_db() _tmp = Path(gettempdir()) diff --git a/manage.py b/manage.py index 06ce3f24ac..9d495c73eb 100755 --- a/manage.py +++ b/manage.py @@ -3,34 +3,16 @@ import os import sys -import warnings -from authentik.lib.config import CONFIG -from cryptography.hazmat.backends.openssl.backend import backend -from defusedxml import defuse_stdlib from django.utils.autoreload import DJANGO_AUTORELOAD_ENV +import authentik.lib.setup # noqa + from lifecycle.migrate import run_migrations from lifecycle.wait_for_db import wait_for_db -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() - if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "authentik.root.settings") wait_for_db() if ( len(sys.argv) > 1