diff --git a/awx/api/versioning.py b/awx/api/versioning.py index 9fc57ac71e5c..2c5820246dcd 100644 --- a/awx/api/versioning.py +++ b/awx/api/versioning.py @@ -24,6 +24,10 @@ def drf_reverse(viewname, args=None, kwargs=None, request=None, format=None, **e else: url = _reverse(viewname, args, kwargs, request, format, **extra) + if settings.OPTIONAL_API_URLPATTERN_PREFIX and request: + if request.path.startswith(f"/api/{settings.OPTIONAL_API_URLPATTERN_PREFIX}"): + url = url.replace('/api', f"/api/{settings.OPTIONAL_API_URLPATTERN_PREFIX}") + return url diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 1e2fed59b9a4..a4472ced6ef6 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -1126,3 +1126,8 @@ settings_file = os.path.join(os.path.dirname(dynamic_config.__file__), 'dynamic_settings.py') include(settings_file) + +# Add a postfix to the API URL patterns +# example if set to '' API pattern will be /api +# example if set to 'controller' API pattern will be /api AND /api/controller +OPTIONAL_API_URLPATTERN_PREFIX = '' diff --git a/awx/urls.py b/awx/urls.py index c2d7caed4338..28ed6148efa8 100644 --- a/awx/urls.py +++ b/awx/urls.py @@ -2,7 +2,7 @@ # All Rights Reserved. from django.conf import settings -from django.urls import re_path, include +from django.urls import path, re_path, include from ansible_base.resource_registry.urls import urlpatterns as resource_api_urls @@ -12,7 +12,15 @@ urlpatterns = [ re_path(r'', include('awx.ui.urls', namespace='ui')), re_path(r'^ui_next/.*', include('awx.ui_next.urls', namespace='ui_next')), - re_path(r'^api/', include('awx.api.urls', namespace='api')), + path('api/', include('awx.api.urls', namespace='api')), +] + +if settings.OPTIONAL_API_URLPATTERN_PREFIX: + urlpatterns += [ + path(f'api/{settings.OPTIONAL_API_URLPATTERN_PREFIX}/', include('awx.api.urls')), + ] + +urlpatterns += [ re_path(r'^api/v2/', include(resource_api_urls)), re_path(r'^sso/', include('awx.sso.urls', namespace='sso')), re_path(r'^sso/', include('social_django.urls', namespace='social')),