passbook: implement dynamic URL loading
This commit is contained in:
parent
b5bc371a04
commit
61b79e90e5
|
@ -7,3 +7,4 @@ class PassbookAdminConfig(AppConfig):
|
|||
|
||||
name = 'passbook.admin'
|
||||
label = 'passbook_admin'
|
||||
mountpoint = 'administration/'
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
|
||||
"""passbook URL Configuration"""
|
||||
from logging import getLogger
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from passbook.core.views import authentication, overview
|
||||
from passbook.lib.utils.reflection import get_apps
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
admin.autodiscover()
|
||||
admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login')
|
||||
|
||||
|
@ -16,20 +19,21 @@ core_urls = [
|
|||
]
|
||||
|
||||
urlpatterns = [
|
||||
# Core
|
||||
# Core (include our own URLs so namespaces are used everywhere)
|
||||
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
|
||||
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:
|
||||
|
|
|
@ -7,7 +7,7 @@ log:
|
|||
level:
|
||||
console: DEBUG
|
||||
file: DEBUG
|
||||
file: NUL
|
||||
file: /dev/null
|
||||
syslog:
|
||||
host: 127.0.0.1
|
||||
port: 514
|
||||
|
|
|
@ -15,3 +15,11 @@ def path_to_class(path):
|
|||
package = '.'.join(parts[:-1])
|
||||
_class = getattr(import_module(package), parts[-1])
|
||||
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
|
||||
|
|
|
@ -14,6 +14,7 @@ class PassbookOAuthClientConfig(AppConfig):
|
|||
name = 'passbook.oauth_client'
|
||||
label = 'passbook_oauth_client'
|
||||
verbose_name = 'passbook OAuth Client'
|
||||
mountpoint = 'source/oauth/'
|
||||
|
||||
def ready(self):
|
||||
"""Load source_types from config file"""
|
||||
|
|
|
@ -8,3 +8,4 @@ class PassbookOAuthProviderConfig(AppConfig):
|
|||
|
||||
name = 'passbook.oauth_provider'
|
||||
label = 'passbook_oauth_provider'
|
||||
mountpoint = 'application/oauth/'
|
||||
|
|
|
@ -14,6 +14,7 @@ class PassbookSAMLIDPConfig(AppConfig):
|
|||
name = 'passbook.saml_idp'
|
||||
label = 'passbook_saml_idp'
|
||||
verbose_name = 'passbook SAML IDP'
|
||||
mountpoint = 'application/saml/'
|
||||
|
||||
def ready(self):
|
||||
"""Load source_types from config file"""
|
||||
|
|
|
@ -8,3 +8,4 @@ class PassbookTFAConfig(AppConfig):
|
|||
|
||||
name = 'passbook.tfa'
|
||||
label = 'passbook_tfa'
|
||||
mountpoint = 'user/tfa/'
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
"""passbook 2FA Urls"""
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.urls import path
|
||||
|
||||
from passbook.tfa import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='tfa-index'),
|
||||
url(r'qr/$', views.qr_code, name='tfa-qr'),
|
||||
url(r'verify/$', views.verify, name='tfa-verify'),
|
||||
# url(r'enable/$', views.TFASetupView.as_view(), name='tfa-enable'),
|
||||
url(r'disable/$', views.disable, name='tfa-disable'),
|
||||
url(r'user_settings/$', views.user_settings, name='tfa-user_settings'),
|
||||
path('', views.index, name='tfa-index'),
|
||||
path('qr/', views.qr_code, name='tfa-qr'),
|
||||
path('verify/', views.verify, name='tfa-verify'),
|
||||
# path('enable/', views.TFASetupView.as_view(), name='tfa-enable'),
|
||||
path('disable/', views.disable, name='tfa-disable'),
|
||||
path('user_settings/', views.user_settings, name='tfa-user_settings'),
|
||||
]
|
||||
|
|
Reference in New Issue