Skip to content

Commit

Permalink
feat: plugin_api_dispatch 文件上传支持同时传参 (#78)
Browse files Browse the repository at this point in the history
* feat: plugin_api_dispatch 文件上传支持同时传参

* feat: bk_plugin_framework release V2.2.5

* feat: plugin_api_dispatch 文件上传支持同时传参
  • Loading branch information
normal-wls authored Jun 24, 2024
1 parent 136d181 commit 11f634f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bk-plugin-framework/bk_plugin_framework/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
specific language governing permissions and limitations under the License.
"""

__version__ = "2.2.4"
__version__ = "2.2.5"
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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/"):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bk-plugin-framework/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <you@example.com>"]
license = "MIT"
Expand Down

0 comments on commit 11f634f

Please sign in to comment.