Skip to content

Commit

Permalink
refactor websocket url mounting
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu committed May 9, 2023
1 parent 42178af commit b8da3da
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion authentik/api/v3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion authentik/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion authentik/outposts/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
14 changes: 8 additions & 6 deletions authentik/root/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Check warning on line 14 in authentik/root/websocket.py

View check run for this annotation

Codecov / codecov/patch

authentik/root/websocket.py#L12-L14

Added lines #L12 - L14 were not covered by tests
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)

Check warning on line 19 in authentik/root/websocket.py

View check run for this annotation

Codecov / codecov/patch

authentik/root/websocket.py#L16-L19

Added lines #L16 - L19 were not covered by tests
LOGGER.debug(
"Mounted URLs",
"Mounted Websocket URLs",
app_name=_authentik_app.name,
app_mountpoint=mountpoint,
)

0 comments on commit b8da3da

Please sign in to comment.