Skip to content

Commit

Permalink
Define a custom API root endpoint class
Browse files Browse the repository at this point in the history
closes pulp#2340
  • Loading branch information
lubosmj committed Jun 1, 2022
1 parent b8c918e commit 4e7e763
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/2340.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made the API root endpoint accessible for anonymous users once again.
19 changes: 16 additions & 3 deletions pulpcore/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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()),
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4e7e763

Please sign in to comment.