From 4d5c5ffa7be0b77f53b6b58f255d7a589bd696db Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Thu, 16 Nov 2023 12:43:58 +0100 Subject: [PATCH] Correctly report file plugin provided by pulpcore 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 --- CHANGES/4728.deprecation | 1 + CHANGES/4728.feature | 1 + CHANGES/4728.removal | 1 + pulp_file/app/__init__.py | 2 +- pulpcore/app/serializers/status.py | 2 ++ pulpcore/app/views/status.py | 1 + pulpcore/openapi/__init__.py | 43 +++++++++++++++++++++++------- 7 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 CHANGES/4728.deprecation create mode 100644 CHANGES/4728.feature create mode 100644 CHANGES/4728.removal diff --git a/CHANGES/4728.deprecation b/CHANGES/4728.deprecation new file mode 100644 index 0000000000..b303706041 --- /dev/null +++ b/CHANGES/4728.deprecation @@ -0,0 +1 @@ +Deprecated the query parameter ``plugin`` on the api doc endpoint in favor of ``component``. diff --git a/CHANGES/4728.feature b/CHANGES/4728.feature new file mode 100644 index 0000000000..8897c4b9a0 --- /dev/null +++ b/CHANGES/4728.feature @@ -0,0 +1 @@ +Added "module" to status api. diff --git a/CHANGES/4728.removal b/CHANGES/4728.removal new file mode 100644 index 0000000000..bfc8c9d05f --- /dev/null +++ b/CHANGES/4728.removal @@ -0,0 +1 @@ +The python package for the ``file`` plugin is now correctly reporting as ``"pulpcore"``. diff --git a/pulp_file/app/__init__.py b/pulp_file/app/__init__.py index 133acaf4c6..455d6154de 100644 --- a/pulp_file/app/__init__.py +++ b/pulp_file/app/__init__.py @@ -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 diff --git a/pulpcore/app/serializers/status.py b/pulpcore/app/serializers/status.py index cc1789074d..a1f73d6f06 100644 --- a/pulpcore/app/serializers/status.py +++ b/pulpcore/app/serializers/status.py @@ -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") ) diff --git a/pulpcore/app/views/status.py b/pulpcore/app/views/status.py index 6961ba7eab..0b63717aa5 100644 --- a/pulpcore/app/views/status.py +++ b/pulpcore/app/views/status.py @@ -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), } ) diff --git a/pulpcore/openapi/__init__.py b/pulpcore/openapi/__init__.py index 835872ef9b..780637f7ef 100644 --- a/pulpcore/openapi/__init__.py +++ b/pulpcore/openapi/__init__.py @@ -1,3 +1,5 @@ +from gettext import gettext as _ + import re from urllib.parse import urljoin @@ -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: @@ -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) @@ -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), @@ -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