summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElijah DeLee <kdelee@redhat.com>2024-04-03 14:56:32 +0200
committerChris Meyers <chrismeyersfsu@users.noreply.github.com>2024-04-04 13:48:04 +0200
commite2f4213839e49b31f4b80e8351bd73be6fafccef (patch)
tree76c40bac8bd87db22f8663b6e3d30f3a22e26a28
parentRename container hostname from awx_1 to awx-1 (diff)
downloadawx-e2f4213839e49b31f4b80e8351bd73be6fafccef.tar.xz
awx-e2f4213839e49b31f4b80e8351bd73be6fafccef.zip
Round out options url prefix edge cases
-rw-r--r--awx/api/versioning.py12
-rw-r--r--awx/api/views/analytics.py34
-rw-r--r--awx/api/views/root.py12
3 files changed, 32 insertions, 26 deletions
diff --git a/awx/api/versioning.py b/awx/api/versioning.py
index 2c5820246d..f6778b60d2 100644
--- a/awx/api/versioning.py
+++ b/awx/api/versioning.py
@@ -8,6 +8,13 @@ from rest_framework.reverse import _reverse
from rest_framework.versioning import URLPathVersioning as BaseVersioning
+def is_optional_api_urlpattern_prefix_request(request):
+ if settings.OPTIONAL_API_URLPATTERN_PREFIX and request:
+ if request.path.startswith(f"/api/{settings.OPTIONAL_API_URLPATTERN_PREFIX}"):
+ return True
+ return False
+
+
def drf_reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra):
"""
Copy and monkey-patch `rest_framework.reverse.reverse` to prevent adding unwarranted
@@ -24,9 +31,8 @@ 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}")
+ if is_optional_api_urlpattern_prefix_request(request):
+ url = url.replace('/api', f"/api/{settings.OPTIONAL_API_URLPATTERN_PREFIX}")
return url
diff --git a/awx/api/views/analytics.py b/awx/api/views/analytics.py
index 9f6066084f..b19acd7d15 100644
--- a/awx/api/views/analytics.py
+++ b/awx/api/views/analytics.py
@@ -48,23 +48,23 @@ class AnalyticsRootView(APIView):
def get(self, request, format=None):
data = OrderedDict()
- data['authorized'] = reverse('api:analytics_authorized')
- data['reports'] = reverse('api:analytics_reports_list')
- data['report_options'] = reverse('api:analytics_report_options_list')
- data['adoption_rate'] = reverse('api:analytics_adoption_rate')
- data['adoption_rate_options'] = reverse('api:analytics_adoption_rate_options')
- data['event_explorer'] = reverse('api:analytics_event_explorer')
- data['event_explorer_options'] = reverse('api:analytics_event_explorer_options')
- data['host_explorer'] = reverse('api:analytics_host_explorer')
- data['host_explorer_options'] = reverse('api:analytics_host_explorer_options')
- data['job_explorer'] = reverse('api:analytics_job_explorer')
- data['job_explorer_options'] = reverse('api:analytics_job_explorer_options')
- data['probe_templates'] = reverse('api:analytics_probe_templates_explorer')
- data['probe_templates_options'] = reverse('api:analytics_probe_templates_options')
- data['probe_template_for_hosts'] = reverse('api:analytics_probe_template_for_hosts_explorer')
- data['probe_template_for_hosts_options'] = reverse('api:analytics_probe_template_for_hosts_options')
- data['roi_templates'] = reverse('api:analytics_roi_templates_explorer')
- data['roi_templates_options'] = reverse('api:analytics_roi_templates_options')
+ data['authorized'] = reverse('api:analytics_authorized', request=request)
+ data['reports'] = reverse('api:analytics_reports_list', request=request)
+ data['report_options'] = reverse('api:analytics_report_options_list', request=request)
+ data['adoption_rate'] = reverse('api:analytics_adoption_rate', request=request)
+ data['adoption_rate_options'] = reverse('api:analytics_adoption_rate_options', request=request)
+ data['event_explorer'] = reverse('api:analytics_event_explorer', request=request)
+ data['event_explorer_options'] = reverse('api:analytics_event_explorer_options', request=request)
+ data['host_explorer'] = reverse('api:analytics_host_explorer', request=request)
+ data['host_explorer_options'] = reverse('api:analytics_host_explorer_options', request=request)
+ data['job_explorer'] = reverse('api:analytics_job_explorer', request=request)
+ data['job_explorer_options'] = reverse('api:analytics_job_explorer_options', request=request)
+ data['probe_templates'] = reverse('api:analytics_probe_templates_explorer', request=request)
+ data['probe_templates_options'] = reverse('api:analytics_probe_templates_options', request=request)
+ data['probe_template_for_hosts'] = reverse('api:analytics_probe_template_for_hosts_explorer', request=request)
+ data['probe_template_for_hosts_options'] = reverse('api:analytics_probe_template_for_hosts_options', request=request)
+ data['roi_templates'] = reverse('api:analytics_roi_templates_explorer', request=request)
+ data['roi_templates_options'] = reverse('api:analytics_roi_templates_options', request=request)
return Response(data)
diff --git a/awx/api/views/root.py b/awx/api/views/root.py
index 86488ed801..0aac01ad01 100644
--- a/awx/api/views/root.py
+++ b/awx/api/views/root.py
@@ -28,7 +28,7 @@ from awx.main.analytics import all_collectors
from awx.main.ha import is_ha_environment
from awx.main.utils import get_awx_version, get_custom_venv_choices
from awx.main.utils.licensing import validate_entitlement_manifest
-from awx.api.versioning import reverse, drf_reverse
+from awx.api.versioning import URLPathVersioning, is_optional_api_urlpattern_prefix_request, reverse, drf_reverse
from awx.main.constants import PRIVILEGE_ESCALATION_METHODS
from awx.main.models import Project, Organization, Instance, InstanceGroup, JobTemplate
from awx.main.utils import set_environ
@@ -40,19 +40,19 @@ logger = logging.getLogger('awx.api.views.root')
class ApiRootView(APIView):
permission_classes = (AllowAny,)
name = _('REST API')
- versioning_class = None
+ versioning_class = URLPathVersioning
swagger_topic = 'Versioning'
@method_decorator(ensure_csrf_cookie)
def get(self, request, format=None):
'''List supported API versions'''
-
- v2 = reverse('api:api_v2_root_view', kwargs={'version': 'v2'})
+ v2 = reverse('api:api_v2_root_view', request=request, kwargs={'version': 'v2'})
data = OrderedDict()
data['description'] = _('AWX REST API')
data['current_version'] = v2
data['available_versions'] = dict(v2=v2)
- data['oauth2'] = drf_reverse('api:oauth_authorization_root_view')
+ if not is_optional_api_urlpattern_prefix_request(request):
+ data['oauth2'] = drf_reverse('api:oauth_authorization_root_view')
data['custom_logo'] = settings.CUSTOM_LOGO
data['custom_login_info'] = settings.CUSTOM_LOGIN_INFO
data['login_redirect_override'] = settings.LOGIN_REDIRECT_OVERRIDE
@@ -131,7 +131,7 @@ class ApiVersionRootView(APIView):
data['mesh_visualizer'] = reverse('api:mesh_visualizer_view', request=request)
data['bulk'] = reverse('api:bulk', request=request)
data['analytics'] = reverse('api:analytics_root_view', request=request)
- data['service_index'] = django_reverse('service-index-root')
+ data['service_index'] = django_reverse('service-index-root', request=request)
return Response(data)