passbook: implement dynamic URL loading

This commit is contained in:
Jens Langhammer 2018-11-22 10:28:13 +01:00
parent b5bc371a04
commit 61b79e90e5
9 changed files with 37 additions and 20 deletions

View File

@ -7,3 +7,4 @@ class PassbookAdminConfig(AppConfig):
name = 'passbook.admin' name = 'passbook.admin'
label = 'passbook_admin' label = 'passbook_admin'
mountpoint = 'administration/'

View File

@ -1,12 +1,15 @@
"""passbook URL Configuration""" """passbook URL Configuration"""
from logging import getLogger
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from django.views.generic import RedirectView from django.views.generic import RedirectView
from passbook.core.views import authentication, overview from passbook.core.views import authentication, overview
from passbook.lib.utils.reflection import get_apps
LOGGER = getLogger(__name__)
admin.autodiscover() admin.autodiscover()
admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login') admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login')
@ -16,20 +19,21 @@ core_urls = [
] ]
urlpatterns = [ urlpatterns = [
# Core # Core (include our own URLs so namespaces are used everywhere)
path('', include((core_urls, 'passbook_core'), namespace='passbook_core')), path('', include((core_urls, 'passbook_core'), namespace='passbook_core')),
]
for _passbook_app in get_apps():
if hasattr(_passbook_app, 'mountpoint'):
_path = path(_passbook_app.mountpoint, include((_passbook_app.name+'.urls',
_passbook_app.name),
namespace=_passbook_app.label))
urlpatterns.append(_path)
LOGGER.debug("Loaded %s's URLs", _passbook_app.name)
urlpatterns += [
# Administration # Administration
path('administration/django/', admin.site.urls), path('administration/django/', admin.site.urls),
path('administration/',
include(('passbook.admin.urls', 'passbook_admin'), namespace='passbook_admin')),
path('source/oauth/', include(('passbook.oauth_client.urls',
'passbook_oauth_client'), namespace='passbook_oauth_client')),
path('application/oauth/', include(('passbook.oauth_provider.urls',
'passbook_oauth_provider'),
namespace='passbook_oauth_provider')),
path('application/saml/', include(('passbook.saml_idp.urls',
'passbook_saml_idp'),
namespace='passbook_saml_idp')),
] ]
if settings.DEBUG: if settings.DEBUG:

View File

@ -7,7 +7,7 @@ log:
level: level:
console: DEBUG console: DEBUG
file: DEBUG file: DEBUG
file: NUL file: /dev/null
syslog: syslog:
host: 127.0.0.1 host: 127.0.0.1
port: 514 port: 514

View File

@ -15,3 +15,11 @@ def path_to_class(path):
package = '.'.join(parts[:-1]) package = '.'.join(parts[:-1])
_class = getattr(import_module(package), parts[-1]) _class = getattr(import_module(package), parts[-1])
return _class return _class
def get_apps():
"""Get list of all passbook apps"""
from django.apps.registry import apps
for _app in apps.get_app_configs():
if _app.name.startswith('passbook'):
yield _app

View File

@ -14,6 +14,7 @@ class PassbookOAuthClientConfig(AppConfig):
name = 'passbook.oauth_client' name = 'passbook.oauth_client'
label = 'passbook_oauth_client' label = 'passbook_oauth_client'
verbose_name = 'passbook OAuth Client' verbose_name = 'passbook OAuth Client'
mountpoint = 'source/oauth/'
def ready(self): def ready(self):
"""Load source_types from config file""" """Load source_types from config file"""

View File

@ -8,3 +8,4 @@ class PassbookOAuthProviderConfig(AppConfig):
name = 'passbook.oauth_provider' name = 'passbook.oauth_provider'
label = 'passbook_oauth_provider' label = 'passbook_oauth_provider'
mountpoint = 'application/oauth/'

View File

@ -14,6 +14,7 @@ class PassbookSAMLIDPConfig(AppConfig):
name = 'passbook.saml_idp' name = 'passbook.saml_idp'
label = 'passbook_saml_idp' label = 'passbook_saml_idp'
verbose_name = 'passbook SAML IDP' verbose_name = 'passbook SAML IDP'
mountpoint = 'application/saml/'
def ready(self): def ready(self):
"""Load source_types from config file""" """Load source_types from config file"""

View File

@ -8,3 +8,4 @@ class PassbookTFAConfig(AppConfig):
name = 'passbook.tfa' name = 'passbook.tfa'
label = 'passbook_tfa' label = 'passbook_tfa'
mountpoint = 'user/tfa/'

View File

@ -1,14 +1,14 @@
"""passbook 2FA Urls""" """passbook 2FA Urls"""
from django.conf.urls import url from django.urls import path
from passbook.tfa import views from passbook.tfa import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.index, name='tfa-index'), path('', views.index, name='tfa-index'),
url(r'qr/$', views.qr_code, name='tfa-qr'), path('qr/', views.qr_code, name='tfa-qr'),
url(r'verify/$', views.verify, name='tfa-verify'), path('verify/', views.verify, name='tfa-verify'),
# url(r'enable/$', views.TFASetupView.as_view(), name='tfa-enable'), # path('enable/', views.TFASetupView.as_view(), name='tfa-enable'),
url(r'disable/$', views.disable, name='tfa-disable'), path('disable/', views.disable, name='tfa-disable'),
url(r'user_settings/$', views.user_settings, name='tfa-user_settings'), path('user_settings/', views.user_settings, name='tfa-user_settings'),
] ]