Project

Profile

Help

Story #4279

Namespace plugin endpoints for viewsets of master/detail models.

Added by ttereshc 10 months ago. Updated 6 months ago.

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

100%

Platform Release:
Blocks Release:
Backwards Incompatible:
No
Groomed:
Yes
Sprint Candidate:
Yes
Tags:
QA Contact:
Complexity:
Smash Test:
Verified:
No
Verification Required:
No
Sprint:
Sprint 48

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/


Checklist

Associated revisions

Revision 7654d5d2 View on GitHub
Added by ttereshc 9 months ago

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

Revision 7654d5d2 View on GitHub
Added by ttereshc 9 months ago

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

Revision 39f572db View on GitHub
Added by ttereshc 9 months ago

Change Django app label and adjust `endpoint_name`s

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

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

Revision 39f572db View on GitHub
Added by ttereshc 9 months ago

Change Django app label and adjust `endpoint_name`s

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

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

Revision 118f79ed View on GitHub
Added by ttereshc 9 months ago

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

Revision f36b1a8b View on GitHub
Added by ttereshc 9 months ago

Change Django app label and adjust `endpoint_name`s

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

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

Revision 2dbab818 View on GitHub
Added by ttereshc 9 months ago

Change Django app label and adjust `endpoint_name`s

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

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

Revision f4ad91dc View on GitHub
Added by ttereshc 9 months ago

Change Django app label and adjust `endpoint_name`s

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

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

Revision 7423470a View on GitHub
Added by ttereshc 8 months ago

Change Django app label and adjust `endpoint_name`s

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

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

History

#1 Updated by ttereshc 10 months 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):
         """ 

#2 Updated by CodeHeeler 10 months ago

  • Tracker changed from Issue to Story
  • % Done set to 0

#3 Updated by ttereshc 10 months ago

  • Description updated (diff)

#4 Updated by ttereshc 9 months ago

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

#6 Updated by ttereshc 9 months ago

  • Checklist item Prepend all master/detail related endpoints with a Django app label added
  • Checklist item Remove 'pulp_' prefix in Django app labels for all the plugins which core team is responsible for added
  • Checklist item Update plugin writer's guidelines to reflect how plugin's Django app label is used in the endpoints added
  • Checklist item E-mail pulp-dev list to reach plugin writers with a suggestion to drop 'pulp_' in their Django app label added
  • Description updated (diff)

#7 Updated by ttereshc 9 months ago

  • Description updated (diff)

#8 Updated by ttereshc 9 months ago

  • Description updated (diff)

#9 Updated by daviddavis 9 months ago

  • Groomed changed from No to Yes
  • Sprint Candidate changed from No to Yes

#10 Updated by ttereshc 9 months ago

  • Sprint set to Sprint 47

#11 Updated by ttereshc 9 months ago

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

#12 Updated by ttereshc 9 months ago

  • Checklist item Prepend all master/detail related endpoints with a Django app label set to Done
  • Checklist item Remove 'pulp_' prefix in Django app labels for all the plugins which core team is responsible for set to Done
  • Status changed from ASSIGNED to POST

#13 Updated by rchan 9 months ago

  • Sprint changed from Sprint 47 to Sprint 48

#14 Updated by ttereshc 9 months ago

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

#15 Updated by ttereshc 9 months ago

  • Status changed from MODIFIED to POST

#16 Updated by ttereshc 9 months ago

  • Status changed from POST to MODIFIED

#17 Updated by ttereshc 9 months ago

  • Checklist item E-mail pulp-dev list to reach plugin writers with a suggestion to drop 'pulp_' in their Django app label set to Done

#18 Updated by daviddavis 6 months ago

  • Sprint/Milestone set to 3.0

#19 Updated by bmbouter 6 months ago

  • Tags deleted (Pulp 3, Pulp 3 RC Blocker)

Please register to edit this issue

Also available in: Atom PDF