From 11f634f6ba4583374dcfeaab4e15337250c3530f Mon Sep 17 00:00:00 2001 From: normal-wls <1158341873@qq.com> Date: Mon, 24 Jun 2024 11:57:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20plugin=5Fapi=5Fdispatch=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=94=AF=E6=8C=81=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E4=BC=A0=E5=8F=82=20(#78)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: plugin_api_dispatch 文件上传支持同时传参 * feat: bk_plugin_framework release V2.2.5 * feat: plugin_api_dispatch 文件上传支持同时传参 --- .../bk_plugin_framework/__version__.py | 2 +- .../bpf_service/api/plugin_api_dispatch.py | 29 ++++++++++++++----- bk-plugin-framework/pyproject.toml | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/bk-plugin-framework/bk_plugin_framework/__version__.py b/bk-plugin-framework/bk_plugin_framework/__version__.py index 94f1263..0cd7b98 100644 --- a/bk-plugin-framework/bk_plugin_framework/__version__.py +++ b/bk-plugin-framework/bk_plugin_framework/__version__.py @@ -10,4 +10,4 @@ specific language governing permissions and limitations under the License. """ -__version__ = "2.2.4" +__version__ = "2.2.5" diff --git a/bk-plugin-framework/bk_plugin_framework/services/bpf_service/api/plugin_api_dispatch.py b/bk-plugin-framework/bk_plugin_framework/services/bpf_service/api/plugin_api_dispatch.py index ac7b9a8..3686354 100644 --- a/bk-plugin-framework/bk_plugin_framework/services/bpf_service/api/plugin_api_dispatch.py +++ b/bk-plugin-framework/bk_plugin_framework/services/bpf_service/api/plugin_api_dispatch.py @@ -9,7 +9,7 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ - +import json import logging import re @@ -41,6 +41,12 @@ class PluginAPIDispatchParamsSerializer(serializers.Serializer): method = serializers.CharField(help_text="调用方法", required=True) username = serializers.CharField(help_text="用户名", required=True) data = serializers.DictField(help_text="接口数据", required=False, default={}) + dumped_data = serializers.CharField(help_text="json dumps后的接口数据", required=False) + + def validate(self, values): + if values.get("dumped_data"): + values["data"].update(json.loads(values["dumped_data"])) + return values def validate_url(self, value): if not value.startswith("/bk_plugin/plugin_api/"): @@ -105,13 +111,20 @@ def post(self, request): # get apigw jwt info custom_headers["HTTP_X_BKAPI_JWT"] = request.META.get("HTTP_X_BKAPI_JWT", "") - fake_request = getattr(RequestFactory(), request_data["method"].lower())( - path=request_data["url"], content_type=request.content_type, data=request_data["data"], **custom_headers - ) - - # inject upload FILES - for f in request.FILES: - fake_request.FILES[f] = request.FILES[f] + if request.FILES: + fake_request = getattr(RequestFactory(), request_data["method"].lower())( + path=request_data["url"], data=request_data["data"], **custom_headers + ) + # inject upload FILES + for f in request.FILES: + fake_request.FILES[f] = request.FILES[f] + else: + fake_request = getattr(RequestFactory(), request_data["method"].lower())( + path=request_data["url"], + content_type=request.content_type, + data=request_data["data"], + **custom_headers + ) # inject APIGW jwt fake_request.jwt = request.jwt diff --git a/bk-plugin-framework/pyproject.toml b/bk-plugin-framework/pyproject.toml index 985754f..c69eb67 100644 --- a/bk-plugin-framework/pyproject.toml +++ b/bk-plugin-framework/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bk-plugin-framework" -version = "2.2.4" +version = "2.2.5" description = "bk plugin python framework" authors = ["Your Name "] license = "MIT"