Project

Profile

Help

Story #3472

closed

As a plugin writer, I have docs to define endpoints for multiple namespaced content types

Added by daviddavis over 6 years ago. Updated almost 5 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:
Documentation, Plugin Template
Sprint:
Sprint 42
Quarter:

Description

Any plugin objects can run into this problem, so the documentation should be general to remotes, publishers, exporters, and content types.

Explain that namespacing is optional but encouraged, the long term problems that it can avoid, and how it is done in the viewset.

This change will be a part of a larger plugin-writer change, so please open this PR against that feature branch:
https://github.com/asmacdo/plugin_template/tree/add-plugin-writer-docs

These docs should be put here:
these docs https://github.com/asmacdo/plugin_template/blob/add-plugin-writer-docs/docs/plugin-writer/subclassing/namespacing.rst

Background

Problem:
Working on the Ansible plugin, we have multiple content types (roles, role versions, and more in the future). For role, I was thinking about defining my content viewset to be 'role' which pulpcore automatically sets up as "/api/v3/content/role/". See:

https://github.com/pulp/pulp_file/blob/master/pulp_file/app/viewsets.py#L32

That got me thinking: what if another plugin has a role type?

Apparently if I have two viewsets that define type 'role', the application just selects one of the two. I can't make out which it prefers though.

Solution:
By convention (meaning, in the plugin docs), plugins are encouraged to namespace their "Detail" endpoints by plugin name.

This is done in the viewset:

class AnsibleRoleViewSet(ContentViewSet):

    # the endpoint becomes v3/content/ansible/roles
    endpoint_name = 'ansible/roles'
    queryset = AnsibleRole.objects.all()
    model = AnsibleRole
    serializer_class = AnsibleRoleSerializer

For some plugins, this is awkward because they only have one type, like the file plugin. Following this convention, the endpoint will be v3/content/file/files/. If the file plugin chooses, they can keep v3/content/file/, but if they do this, they should be aware that adding other content types later will either create inconsistency or will be backwards incompatible. v3/content/file/newfile/.


Related issues

Related to Python Support - Issue #3572: Move 'content/python' to 'content/python/packages'MODIFIEDamacdona@redhat.comActions
Related to File Support - Task #3601: Move /content/file/ to /content/file/files/CLOSED - CURRENTRELEASEdaviddavis

Actions
Actions #1

Updated by daviddavis over 6 years ago

  • Tags Pulp 3 MVP added
Actions #2

Updated by daviddavis over 6 years ago

  • Description updated (diff)
Actions #3

Updated by daviddavis over 6 years ago

  • Description updated (diff)
Actions #4

Updated by amacdona@redhat.com over 6 years ago

I think the way to do this would be an extension of the master/detail concept we already have, where Content ViewSets are registered under the url:

v3/content/<plugin>/<type>/

This would be awkward for plugins with only 1 type:

v3/content/file/file/
v3/content/python/python/

I think I prefer establishing the convention:
If the type is different than the plugin name, the plugin name should be a part of the type in the url.
/v3/content/python/
v3/content/ansible-role/

Actions #5

Updated by dalley over 6 years ago

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

Updated by daviddavis over 6 years ago

  • Subject changed from Plugin writers can define types which conflict with other plugins to As a plugin writer, I can define types which does not conflict with other plugins
Actions #7

Updated by daviddavis over 6 years ago

I think plugins should either use /content/<plugin>-<type>/ or /content/<plugin>/<type>/ regardless of how many content types they have.

I am a bit worried about the idea of allowing plugins with one content type use a different convention for a few reasons:

1. It's inconsistent with plugins that will have multiple content types
2. A plugin could start out with a single content type (/content/rpm/) and then add more later (e.g. erratum, srpm, etc). At this point though, they've painted themselves into a corner and are forced to update existing routes.
3. It's unclear to me whether file in v3/content/file refers to the content type or the name of the plugin. If it's the former, then what if I have another plugin with a content type of 'file'?

Actions #8

Updated by bmbouter over 6 years ago

+1 to using /content/<plugin>/<type>/.

Actions #9

Updated by daviddavis over 6 years ago

  • Subject changed from As a plugin writer, I can define types which does not conflict with other plugins to As a plugin writer, I can define endpoints for multiple content types and be assured my endpoints don't conflict with other plugins
Actions #10

Updated by amacdona@redhat.com over 6 years ago

  • Description updated (diff)

This was discussed on the list: https://www.redhat.com/archives/pulp-dev/2018-April/msg00050.html

I've updated the issue to match the consensus.

Actions #11

Updated by daviddavis over 6 years ago

  • Description updated (diff)
Actions #12

Updated by bmbouter over 6 years ago

  • Groomed changed from No to Yes
  • Tags Documentation added

This story looks fully groomed with agreement from several other core devs. I also tagged it as a docs story.

Actions #13

Updated by amacdona@redhat.com over 6 years ago

  • Sprint Candidate changed from No to Yes
Actions #14

Updated by amacdona@redhat.com over 6 years ago

  • Sprint set to Sprint 35
Actions #15

Updated by amacdona@redhat.com over 6 years ago

  • Subject changed from As a plugin writer, I can define endpoints for multiple content types and be assured my endpoints don't conflict with other plugins to As a plugin writer, I have docs to define endpoints for multiple namespaced content types
Actions #16

Updated by daviddavis over 6 years ago

  • Related to Issue #3572: Move 'content/python' to 'content/python/packages' added
Actions #17

Updated by dkliban@redhat.com over 6 years ago

  • Sprint/Milestone set to 3.0.0
Actions #18

Updated by rchan over 6 years ago

  • Sprint changed from Sprint 35 to Sprint 36
Actions #19

Updated by daviddavis over 6 years ago

  • Related to Task #3601: Move /content/file/ to /content/file/files/ added
Actions #20

Updated by rchan over 6 years ago

  • Sprint changed from Sprint 36 to Sprint 37
Actions #21

Updated by rchan over 6 years ago

  • Sprint changed from Sprint 37 to Sprint 38
Actions #22

Updated by amacdona@redhat.com over 6 years ago

  • Project changed from Pulp to 27
  • Sprint/Milestone deleted (3.0.0)
Actions #23

Updated by rchan over 6 years ago

  • Sprint changed from Sprint 38 to Sprint 39
Actions #24

Updated by amacdona@redhat.com over 6 years ago

  • Description updated (diff)
Actions #25

Updated by daviddavis over 6 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to daviddavis
Actions #26

Updated by daviddavis over 6 years ago

  • Status changed from ASSIGNED to POST
Actions #27

Updated by dkliban@redhat.com over 6 years ago

  • Sprint changed from Sprint 39 to Sprint 40
Actions #28

Updated by rchan over 6 years ago

  • Sprint changed from Sprint 40 to Sprint 41
Actions #29

Updated by rchan about 6 years ago

  • Sprint changed from Sprint 41 to Sprint 42
Actions #30

Updated by dalley about 6 years ago

  • Status changed from POST to MODIFIED
Actions #31

Updated by werwty about 6 years ago

  • % Done changed from 0 to 100

Applied in changeset commit:d73ec31f75db6dfdebab8742982ea350cb0475a8.

Actions #32

Updated by bmbouter over 5 years ago

  • Tags deleted (Pulp 3, Pulp 3 MVP)
Actions #33

Updated by bmbouter over 5 years ago

  • Tags Plugin Template added
Actions #34

Updated by bmbouter over 5 years ago

  • Project changed from 27 to Pulp

The plugin template Redmine project is being consolidated into the Pulp Redmine project so all issues are being moved over.

Actions #35

Updated by bmbouter over 5 years ago

  • Sprint/Milestone set to 3.0.0
Actions #36

Updated by bmbouter almost 5 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF