Story #4279
closedNamespace plugin endpoints for viewsets of master/detail models.
100%
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/
Updated by ttereshc almost 6 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):
"""
Updated by CodeHeeler almost 6 years ago
- Tracker changed from Issue to Story
- % Done set to 0
Updated by ttereshc almost 6 years ago
Discussion of the issue on the pulp-dev mailing list: https://www.redhat.com/archives/pulp-dev/2019-January/msg00002.html
Updated by ttereshc almost 6 years ago
The result of the discussion https://www.redhat.com/archives/pulp-dev/2019-January/msg00045.html
Updated by daviddavis almost 6 years ago
- Groomed changed from No to Yes
- Sprint Candidate changed from No to Yes
Updated by ttereshc almost 6 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to ttereshc
Added by ttereshc almost 6 years ago
Added by ttereshc almost 6 years ago
Revision 7654d5d2 | View on GitHub
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 almost 6 years ago
Revision 39f572db | View on GitHub
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
Added by ttereshc almost 6 years ago
Revision 39f572db | View on GitHub
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
Added by ttereshc almost 6 years ago
Revision 39f572db | View on GitHub
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
Added by ttereshc almost 6 years ago
Revision 39f572db | View on GitHub
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
Added by ttereshc almost 6 years ago
Revision 118f79ed | View on GitHub
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 almost 6 years ago
Revision f36b1a8b | View on GitHub
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
Added by ttereshc almost 6 years ago
Revision ba6c0a48 | View on GitHub
Change Django app label
re #4279 https://pulp.plan.io/issues/4279
Required PR: https://github.com/pulp/pulp/pull/3836
Updated by ttereshc almost 6 years ago
- Status changed from ASSIGNED to POST
https://github.com/pulp/pulp/pull/3836/
https://github.com/pulp/pulp_file/pull/157/
https://github.com/pulp/pulp_rpm/pull/1257/
https://github.com/pulp/ansible-pulp3/pull/67
https://github.com/pulp/devel/pull/210
https://github.com/pulp/pulp_docker/pull/302
https://github.com/pulp/pulp_python/pull/217
https://github.com/pulp/pulp_ansible/pull/76
https://github.com/pulp/plugin_template/pull/28
Updated by ttereshc almost 6 years ago
- Status changed from POST to MODIFIED
- % Done changed from 0 to 100
Applied in changeset pulp|7654d5d2824f51f580e536ba4b5e931baf9f49b5.
Added by ttereshc almost 6 years ago
Revision 2dbab818 | View on GitHub
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
Added by ttereshc almost 6 years ago
Revision f4ad91dc | View on GitHub
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
Added by ttereshc almost 6 years ago
Revision f67776df | View on GitHub
Update app_label for plugins
re #4279 https://pulp.plan.io/issues/4279
Required PR: https://github.com/pulp/pulp_file/pull/157
Added by ttereshc almost 6 years ago
Revision f67776df | View on GitHub
Update app_label for plugins
re #4279 https://pulp.plan.io/issues/4279
Required PR: https://github.com/pulp/pulp_file/pull/157
Added by ttereshc over 5 years ago
Revision 7423470a | View on GitHub
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
Updated by bmbouter almost 5 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
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