Project

Profile

Help

Story #4279

closed

Namespace plugin endpoints for viewsets of master/detail models.

Added by ttereshc over 3 years ago. Updated over 2 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
% Done:

100%

Estimated time:
Platform Release:
Groomed:
Yes
Sprint Candidate:
Yes
Tags:
Sprint:
Sprint 48
Quarter:

Description

At the moment plugins specify the plugin name or some identifier to namespace their endpoints manually as a part of endpoint_name when they write their viewsets,
e.g. for PackageViewSet: endpoint_name = 'rpm/packages', for UpdateRecordViewSet: endpoint_name = 'rpm/errata', etc.

Currently it's mostly a problem for ContentViewSets and less of a problem for Remotes, Publishers, etc, since it's common for a single plugin to support multiple content types.

The suggestion is to prepend endpoint_name of a viewset of any detail model automagically with a plugin name which is defined as a Django app label.
For the plugins it is recommended to drop the 'pulp_' part of their Django app label.

E.g.: For PackageViewSet: endpoint_name will be 'packages', and the Django label will change "pulp_rpm" -> "rpm", so for there is no change in content endpoints:

/api/v3/content/rpm/packages/

Remotes'/Publishers'/other "detail" endpoints will change this way (first "rpm" is a Django label, second "rpm" is endpoint_name defined on a viewset):

/api/v3/remotes/rpm/ --> /api/v3/content/remotes/rpm/rpm/
/api/v3/publishers/rpm/ --> /api/v3/content/publishers/rpm/rpm/
Actions #1

Updated by ttereshc over 3 years ago

The example of the change which can be added to any "master" viewset.

diff --git a/pulpcore/app/viewsets/content.py b/pulpcore/app/viewsets/content.py
index c42232853..c3d191c57 100644
--- a/pulpcore/app/viewsets/content.py
+++ b/pulpcore/app/viewsets/content.py
@@ -96,6 +96,17 @@ class ContentViewSet(NamedModelViewSet,
     serializer_class = ContentSerializer
     filterset_class = ContentFilter

+    def __init_subclass__(cls, **kwargs):
+        """
+        For subclasses (plugin viewsets) add a plugin name to the endpoint name.
+        """
+        super().__init_subclass__(**kwargs)
+        app_label = cls.queryset.model._meta.app_label
+        if hasattr(cls, 'endpoint_name'):
+            cls.endpoint_name = '{app_label}/{plugin_endpoint_name}'.format(
+                app_label=app_label,
+                plugin_endpoint_name=cls.endpoint_name)
+
     @transaction.atomic
     def create(self, request):
         """
Actions #2

Updated by CodeHeeler over 3 years ago

  • Tracker changed from Issue to Story
  • % Done set to 0
Actions #3

Updated by ttereshc over 3 years ago

  • Description updated (diff)
Actions #4

Updated by ttereshc over 3 years ago

Discussion of the issue on the pulp-dev mailing list: https://www.redhat.com/archives/pulp-dev/2019-January/msg00002.html

Actions #6

Updated by ttereshc over 3 years ago

  • Description updated (diff)
Actions #7

Updated by ttereshc over 3 years ago

  • Description updated (diff)
Actions #8

Updated by ttereshc over 3 years ago

  • Description updated (diff)
Actions #9

Updated by daviddavis over 3 years ago

  • Groomed changed from No to Yes
  • Sprint Candidate changed from No to Yes
Actions #10

Updated by ttereshc over 3 years ago

  • Sprint set to Sprint 47
Actions #11

Updated by ttereshc over 3 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to ttereshc

Added by ttereshc over 3 years ago

Revision 7654d5d2

Namespace plugin endpoints with Django app label

closes #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp_file/pull/157

Added by ttereshc over 3 years ago

Revision 7654d5d2

Namespace plugin endpoints with Django app label

closes #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp_file/pull/157

Added by ttereshc over 3 years ago

Revision 39f572db

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Added by ttereshc over 3 years ago

Revision 39f572db

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Added by ttereshc over 3 years ago

Revision 39f572db

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Added by ttereshc over 3 years ago

Revision 39f572db

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Added by ttereshc over 3 years ago

Revision 118f79ed

Fix plugins installation due to the app label change

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp_file/pull/157

Added by ttereshc over 3 years ago

Revision f36b1a8b

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Actions #13

Updated by rchan over 3 years ago

  • Sprint changed from Sprint 47 to Sprint 48
Actions #14

Updated by ttereshc over 3 years ago

  • Status changed from POST to MODIFIED
  • % Done changed from 0 to 100

Added by ttereshc over 3 years ago

Revision 2dbab818

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Actions #15

Updated by ttereshc over 3 years ago

  • Status changed from MODIFIED to POST

Added by ttereshc over 3 years ago

Revision f4ad91dc

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Actions #16

Updated by ttereshc over 3 years ago

  • Status changed from POST to MODIFIED
Actions #17

Updated by ttereshc over 3 years ago

Added by ttereshc over 3 years ago

Revision 7423470a

Change Django app label and adjust endpoint_names

re #4279 https://pulp.plan.io/issues/4279

Required PR: https://github.com/pulp/pulp/pull/3836

Actions #18

Updated by daviddavis about 3 years ago

  • Sprint/Milestone set to 3.0.0
Actions #19

Updated by bmbouter about 3 years ago

  • Tags deleted (Pulp 3, Pulp 3 RC Blocker)
Actions #20

Updated by bmbouter over 2 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF