Skip to content

Commit 11f634f

Browse files
authored
feat: plugin_api_dispatch 文件上传支持同时传参 (#78)
* feat: plugin_api_dispatch 文件上传支持同时传参 * feat: bk_plugin_framework release V2.2.5 * feat: plugin_api_dispatch 文件上传支持同时传参
1 parent 136d181 commit 11f634f

3 files changed

Lines changed: 23 additions & 10 deletions

File tree

bk-plugin-framework/bk_plugin_framework/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
specific language governing permissions and limitations under the License.
1111
"""
1212

13-
__version__ = "2.2.4"
13+
__version__ = "2.2.5"

bk-plugin-framework/bk_plugin_framework/services/bpf_service/api/plugin_api_dispatch.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1010
specific language governing permissions and limitations under the License.
1111
"""
12-
12+
import json
1313
import logging
1414
import re
1515

@@ -41,6 +41,12 @@ class PluginAPIDispatchParamsSerializer(serializers.Serializer):
4141
method = serializers.CharField(help_text="调用方法", required=True)
4242
username = serializers.CharField(help_text="用户名", required=True)
4343
data = serializers.DictField(help_text="接口数据", required=False, default={})
44+
dumped_data = serializers.CharField(help_text="json dumps后的接口数据", required=False)
45+
46+
def validate(self, values):
47+
if values.get("dumped_data"):
48+
values["data"].update(json.loads(values["dumped_data"]))
49+
return values
4450

4551
def validate_url(self, value):
4652
if not value.startswith("/bk_plugin/plugin_api/"):
@@ -105,13 +111,20 @@ def post(self, request):
105111
# get apigw jwt info
106112
custom_headers["HTTP_X_BKAPI_JWT"] = request.META.get("HTTP_X_BKAPI_JWT", "")
107113

108-
fake_request = getattr(RequestFactory(), request_data["method"].lower())(
109-
path=request_data["url"], content_type=request.content_type, data=request_data["data"], **custom_headers
110-
)
111-
112-
# inject upload FILES
113-
for f in request.FILES:
114-
fake_request.FILES[f] = request.FILES[f]
114+
if request.FILES:
115+
fake_request = getattr(RequestFactory(), request_data["method"].lower())(
116+
path=request_data["url"], data=request_data["data"], **custom_headers
117+
)
118+
# inject upload FILES
119+
for f in request.FILES:
120+
fake_request.FILES[f] = request.FILES[f]
121+
else:
122+
fake_request = getattr(RequestFactory(), request_data["method"].lower())(
123+
path=request_data["url"],
124+
content_type=request.content_type,
125+
data=request_data["data"],
126+
**custom_headers
127+
)
115128

116129
# inject APIGW jwt
117130
fake_request.jwt = request.jwt

bk-plugin-framework/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "bk-plugin-framework"
3-
version = "2.2.4"
3+
version = "2.2.5"
44
description = "bk plugin python framework"
55
authors = ["Your Name <you@example.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)