From b8da3dab9d7db22359dfbf8a5f588d524c644e66 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 9 May 2023 12:10:40 +0200 Subject: [PATCH] refactor websocket url mounting Signed-off-by: Jens Langhammer --- authentik/api/v3/urls.py | 2 +- authentik/core/apps.py | 1 - authentik/outposts/apps.py | 1 - authentik/root/websocket.py | 14 ++++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/authentik/api/v3/urls.py b/authentik/api/v3/urls.py index c501fa771db..f6b2f45f8bc 100644 --- a/authentik/api/v3/urls.py +++ b/authentik/api/v3/urls.py @@ -21,7 +21,7 @@ for _authentik_app in get_apps(): try: api_urls = import_module(f"{_authentik_app.name}.urls") - except ModuleNotFoundError: + except (ModuleNotFoundError, ImportError): continue if not hasattr(api_urls, "api_urlpatterns"): continue diff --git a/authentik/core/apps.py b/authentik/core/apps.py index 072e59a9e74..719b2abb1ca 100644 --- a/authentik/core/apps.py +++ b/authentik/core/apps.py @@ -11,7 +11,6 @@ class AuthentikCoreConfig(ManagedAppConfig): label = "authentik_core" verbose_name = "authentik Core" mountpoint = "" - ws_mountpoint = "authentik.core.urls" default = True def reconcile_load_core_signals(self): diff --git a/authentik/outposts/apps.py b/authentik/outposts/apps.py index ea29ebdca1f..6898a170a40 100644 --- a/authentik/outposts/apps.py +++ b/authentik/outposts/apps.py @@ -24,7 +24,6 @@ class AuthentikOutpostConfig(ManagedAppConfig): label = "authentik_outposts" verbose_name = "authentik Outpost" default = True - ws_mountpoint = "authentik.outposts.urls" def reconcile_load_outposts_signals(self): """Load outposts signals""" diff --git a/authentik/root/websocket.py b/authentik/root/websocket.py index 8a044056f85..df32a35af1a 100644 --- a/authentik/root/websocket.py +++ b/authentik/root/websocket.py @@ -9,13 +9,15 @@ websocket_urlpatterns = [] for _authentik_app in get_apps(): - mountpoint = getattr(_authentik_app, "ws_mountpoint", None) - if not mountpoint: + try: + api_urls = import_module(f"{_authentik_app.name}.urls") + except ModuleNotFoundError: continue - ws_paths = import_module(mountpoint) - websocket_urlpatterns.extend(getattr(ws_paths, "websocket_urlpatterns")) + if not hasattr(api_urls, "websocket_urlpatterns"): + continue + urls: list = getattr(api_urls, "websocket_urlpatterns") + websocket_urlpatterns.extend(urls) LOGGER.debug( - "Mounted URLs", + "Mounted Websocket URLs", app_name=_authentik_app.name, - app_mountpoint=mountpoint, )