From 4e7e7639f957689d4dd818081bc39746b1616b77 Mon Sep 17 00:00:00 2001 From: Lubos Mjachky Date: Wed, 1 Jun 2022 16:51:20 +0200 Subject: [PATCH] Define a custom API root endpoint class closes #2340 --- CHANGES/2340.bugfix | 1 + pulpcore/app/urls.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 CHANGES/2340.bugfix diff --git a/CHANGES/2340.bugfix b/CHANGES/2340.bugfix new file mode 100644 index 0000000000..4c808c94f2 --- /dev/null +++ b/CHANGES/2340.bugfix @@ -0,0 +1 @@ +Made the API root endpoint accessible for anonymous users once again. diff --git a/pulpcore/app/urls.py b/pulpcore/app/urls.py index 9a0a293a66..e0a6890ed7 100644 --- a/pulpcore/app/urls.py +++ b/pulpcore/app/urls.py @@ -10,6 +10,7 @@ SpectacularSwaggerView, ) from rest_framework_nested import routers +from rest_framework.routers import APIRootView from pulpcore.app.apps import pulp_plugin_configs from pulpcore.app.views import OrphansView, PulpImporterImportCheckView, RepairView, StatusView @@ -104,6 +105,19 @@ def __repr__(self): return str(self.viewset) +class PulpAPIRootView(APIRootView): + """A Pulp-defined APIRootView class with no authentication requirements.""" + + authentication_classes = [] + permission_classes = [] + + +class PulpDefaultRouter(routers.DefaultRouter): + """A DefaultRouter class that benefits from the customized PulpAPIRootView class.""" + + APIRootView = PulpAPIRootView + + all_viewsets = [] plugin_patterns = [] # Iterate over each app, including pulpcore and the plugins. @@ -118,9 +132,6 @@ def __repr__(self): for viewset in sorted_by_depth: vs_tree.add_decendent(ViewSetNode(viewset)) -#: The Pulp Platform v3 API router, which can be used to manually register ViewSets with the API. -root_router = routers.DefaultRouter() - urlpatterns = [ path(f"{API_ROOT}repair/", RepairView.as_view()), path(f"{API_ROOT}status/", StatusView.as_view()), @@ -184,6 +195,8 @@ def __repr__(self): ) ) +#: The Pulp Platform v3 API router, which can be used to manually register ViewSets with the API. +root_router = PulpDefaultRouter() all_routers = [root_router] + vs_tree.register_with(root_router) for router in all_routers: