Skip to content

Commit

Permalink
Correctly report file plugin provided by pulpcore
Browse files Browse the repository at this point in the history
Since being merged, the python package for the pulp app labeled 'file'
is supposed to be "pulpcore". Due to some inconsistencies around the use
of app label vs. python package vs. python module, we need some
straightening all around.

fixes #4728
  • Loading branch information
mdellweg committed Jan 15, 2024
1 parent 565d083 commit 4d5c5ff
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES/4728.deprecation
@@ -0,0 +1 @@
Deprecated the query parameter ``plugin`` on the api doc endpoint in favor of ``component``.
1 change: 1 addition & 0 deletions CHANGES/4728.feature
@@ -0,0 +1 @@
Added "module" to status api.
1 change: 1 addition & 0 deletions CHANGES/4728.removal
@@ -0,0 +1 @@
The python package for the ``file`` plugin is now correctly reporting as ``"pulpcore"``.
2 changes: 1 addition & 1 deletion pulp_file/app/__init__.py
Expand Up @@ -9,5 +9,5 @@ class PulpFilePluginAppConfig(PulpPluginAppConfig):
name = "pulp_file.app"
label = "file"
version = "3.44.0.dev"
python_package_name = "pulp-file" # TODO Add python_module_name
python_package_name = "pulpcore"
domain_compatible = True
2 changes: 2 additions & 0 deletions pulpcore/app/serializers/status.py
Expand Up @@ -20,6 +20,8 @@ class VersionSerializer(serializers.Serializer):

package = serializers.CharField(help_text=_("Python package name providing the component"))

module = serializers.CharField(help_text=_("Python module name of the component"))

domain_compatible = serializers.BooleanField(
help_text=_("Domain feature compatibility of component")
)
Expand Down
1 change: 1 addition & 0 deletions pulpcore/app/views/status.py
Expand Up @@ -67,6 +67,7 @@ def get(self, request):
"component": app.label,
"version": app.version,
"package": app.python_package_name,
"module": app.name,
"domain_compatible": getattr(app, "domain_compatible", False),
}
)
Expand Down
43 changes: 33 additions & 10 deletions pulpcore/openapi/__init__.py
@@ -1,3 +1,5 @@
from gettext import gettext as _

import re
from urllib.parse import urljoin

Expand All @@ -21,9 +23,11 @@
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, extend_schema_field
from rest_framework import mixins, serializers
from rest_framework.exceptions import ParseError
from rest_framework.schemas.utils import get_pk_description

from pulpcore.app.apps import pulp_plugin_configs
from pulpcore.app.loggers import deprecation_logger


if settings.DOMAIN_ENABLED:
Expand Down Expand Up @@ -395,15 +399,13 @@ def parse(self, input_request, public):
path_prefix = "^" + path_prefix # make sure regex only matches from the start

# Adding plugin filter
plugins = None
# /pulp/api/v3/docs/api.json?plugin=pulp_file
if input_request and "plugin" in query_params:
plugins = [input_request.query_params["plugin"]]
plugins = getattr(input_request, "plugins", None)

for path, path_regex, method, view in endpoints:
plugin = view.__module__.split(".")[0]
if plugins and plugin not in plugins: # plugin filter
continue
if plugins:
plugin = view.__module__.split(".")[0]
if plugin not in plugins: # plugin filter
continue

view.request = spectacular_settings.GET_MOCK_REQUEST(method, path, view, input_request)

Expand Down Expand Up @@ -469,6 +471,29 @@ def parse(self, input_request, public):
def get_schema(self, request=None, public=False):
"""Generate a OpenAPI schema."""
reset_generator_stats()

apps = list(pulp_plugin_configs())
if request and "component" in request.query_params:
# /pulp/api/v3/docs/api.json?component=core,file
if "plugin" in request.query_params:
raise ParseError("'component' and 'plugin' cannot be combined.")
app_labels = request.query_params["component"].split(",")
apps = [app for app in apps if app.label in app_labels]
if len(apps) != len(app_labels):
raise ParseError("Invalid component specified.")
request.plugins = [app.name.split(".")[0] for app in apps]

if request and "plugin" in request.query_params:
# /pulp/api/v3/docs/api.json?plugin=pulp_file
deprecation_logger.warn(
_(
"The query parameter `plugin` has been deprecated and "
"will be removed with pulpcore>=3.55. "
"Please use `component` with a list of app labels instead."
)
)
request.plugins = request.query_params["plugin"].split(",")

result = build_root_object(
paths=self.parse(request, public),
components=self.registry.build(spectacular_settings.APPEND_COMPONENTS),
Expand All @@ -483,9 +508,7 @@ def get_schema(self, request=None, public=False):
}

# Adding plugin version config
result["info"]["x-pulp-app-versions"] = {}
for app in pulp_plugin_configs():
result["info"]["x-pulp-app-versions"][app.label] = app.version
result["info"]["x-pulp-app-versions"] = {app.label: app.version for app in apps}

# Add domain-settings value
result["info"]["x-pulp-domain-enabled"] = settings.DOMAIN_ENABLED
Expand Down

0 comments on commit 4d5c5ff

Please sign in to comment.