2020-02-29 02:23:01 -05:00
|
|
|
import importlib
|
|
|
|
|
|
|
|
from django.apps import apps
|
2016-09-29 16:32:16 -04:00
|
|
|
from django.conf import settings
|
2019-05-26 14:44:28 +02:00
|
|
|
from django.conf.urls import include
|
2019-05-27 22:41:10 +02:00
|
|
|
from django.urls import path, re_path
|
2017-03-30 21:55:57 -04:00
|
|
|
from django.views.static import serve
|
2018-02-22 17:46:50 -05:00
|
|
|
from drf_yasg import openapi
|
2018-11-02 15:20:08 -04:00
|
|
|
from drf_yasg.views import get_schema_view
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-03-20 20:10:02 -04:00
|
|
|
from extras.plugins.urls import admin_plugin_patterns, plugin_patterns, plugin_api_patterns
|
2020-03-09 15:33:57 -04:00
|
|
|
from netbox.views import APIRootView, HomeView, StaticMediaFailureView, SearchView
|
2017-05-19 15:47:19 -04:00
|
|
|
from users.views import LoginView, LogoutView
|
2018-08-16 09:44:00 -04:00
|
|
|
from .admin import admin_site
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2020-01-23 14:26:04 +00:00
|
|
|
openapi_info = openapi.Info(
|
|
|
|
title="NetBox API",
|
|
|
|
default_version='v2',
|
|
|
|
description="API to access NetBox",
|
|
|
|
terms_of_service="https://github.com/netbox-community/netbox",
|
|
|
|
license=openapi.License(name="Apache v2 License"),
|
|
|
|
)
|
|
|
|
|
2018-02-22 17:46:50 -05:00
|
|
|
schema_view = get_schema_view(
|
2020-01-23 14:26:04 +00:00
|
|
|
openapi_info,
|
2018-02-22 17:46:50 -05:00
|
|
|
validators=['flex', 'ssv'],
|
|
|
|
public=True,
|
|
|
|
)
|
2016-07-15 11:04:03 -04:00
|
|
|
|
2016-09-30 11:19:50 -04:00
|
|
|
_patterns = [
|
|
|
|
|
2017-03-29 12:04:57 -04:00
|
|
|
# Base views
|
2020-02-05 16:12:48 -05:00
|
|
|
path('', HomeView.as_view(), name='home'),
|
|
|
|
path('search/', SearchView.as_view(), name='search'),
|
2016-09-30 11:19:50 -04:00
|
|
|
|
|
|
|
# Login/logout
|
2020-02-05 16:12:48 -05:00
|
|
|
path('login/', LoginView.as_view(), name='login'),
|
|
|
|
path('logout/', LogoutView.as_view(), name='logout'),
|
2016-09-30 11:19:50 -04:00
|
|
|
|
|
|
|
# Apps
|
2020-02-05 16:12:48 -05:00
|
|
|
path('circuits/', include('circuits.urls')),
|
|
|
|
path('dcim/', include('dcim.urls')),
|
|
|
|
path('extras/', include('extras.urls')),
|
|
|
|
path('ipam/', include('ipam.urls')),
|
|
|
|
path('secrets/', include('secrets.urls')),
|
|
|
|
path('tenancy/', include('tenancy.urls')),
|
|
|
|
path('user/', include('users.urls')),
|
|
|
|
path('virtualization/', include('virtualization.urls')),
|
2016-09-30 11:19:50 -04:00
|
|
|
|
|
|
|
# API
|
2020-02-05 16:12:48 -05:00
|
|
|
path('api/', APIRootView.as_view(), name='api-root'),
|
|
|
|
path('api/circuits/', include('circuits.api.urls')),
|
|
|
|
path('api/dcim/', include('dcim.api.urls')),
|
|
|
|
path('api/extras/', include('extras.api.urls')),
|
|
|
|
path('api/ipam/', include('ipam.api.urls')),
|
|
|
|
path('api/secrets/', include('secrets.api.urls')),
|
|
|
|
path('api/tenancy/', include('tenancy.api.urls')),
|
|
|
|
path('api/virtualization/', include('virtualization.api.urls')),
|
|
|
|
path('api/docs/', schema_view.with_ui('swagger'), name='api_docs'),
|
|
|
|
path('api/redoc/', schema_view.with_ui('redoc'), name='api_redocs'),
|
2019-05-27 22:41:10 +02:00
|
|
|
re_path(r'^api/swagger(?P<format>.json|.yaml)$', schema_view.without_ui(), name='schema_swagger'),
|
2016-09-30 11:19:50 -04:00
|
|
|
|
2017-03-31 15:51:17 -04:00
|
|
|
# Serving static media in Django to pipe it through LoginRequiredMiddleware
|
2020-02-05 16:12:48 -05:00
|
|
|
path('media/<path:path>', serve, {'document_root': settings.MEDIA_ROOT}),
|
2017-03-31 15:51:17 -04:00
|
|
|
|
2016-09-30 11:19:50 -04:00
|
|
|
# Admin
|
2020-02-05 16:12:48 -05:00
|
|
|
path('admin/', admin_site.urls),
|
|
|
|
path('admin/webhook-backend-status/', include('django_rq.urls')),
|
2016-09-29 16:32:16 -04:00
|
|
|
|
2020-03-09 15:33:57 -04:00
|
|
|
# Errors
|
|
|
|
path('media-failure/', StaticMediaFailureView.as_view(), name='media_failure'),
|
|
|
|
|
2020-03-20 20:10:02 -04:00
|
|
|
# Plugins
|
|
|
|
path('plugins/', include((plugin_patterns, 'plugins'))),
|
|
|
|
path('api/plugins/', include((plugin_api_patterns, 'plugins-api'))),
|
|
|
|
path('admin/plugins/installed-plugins/', include(admin_plugin_patterns))
|
2016-09-30 11:19:50 -04:00
|
|
|
]
|
2016-05-18 16:35:35 -04:00
|
|
|
|
2020-02-29 02:23:01 -05:00
|
|
|
|
2016-12-26 12:15:14 -05:00
|
|
|
if settings.DEBUG:
|
|
|
|
import debug_toolbar
|
|
|
|
_patterns += [
|
2020-02-05 16:12:48 -05:00
|
|
|
path('__debug__/', include(debug_toolbar.urls)),
|
2016-12-26 12:15:14 -05:00
|
|
|
]
|
|
|
|
|
2019-04-25 01:09:19 -04:00
|
|
|
if settings.METRICS_ENABLED:
|
|
|
|
_patterns += [
|
2019-05-31 21:37:41 -04:00
|
|
|
path('', include('django_prometheus.urls')),
|
2019-04-25 01:09:19 -04:00
|
|
|
]
|
|
|
|
|
2016-09-30 11:19:50 -04:00
|
|
|
# Prepend BASE_PATH
|
|
|
|
urlpatterns = [
|
2020-02-05 16:12:48 -05:00
|
|
|
path('{}'.format(settings.BASE_PATH), include(_patterns))
|
2016-03-01 11:23:03 -05:00
|
|
|
]
|
2018-07-23 23:00:09 -04:00
|
|
|
|
|
|
|
handler500 = 'utilities.views.server_error'
|