Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: http 插件支持 json 转义 #40 #49

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app_desc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spec_version: 2
app_version: "1.8.0"
app_version: "1.8.1"
app:
region: default
bk_app_code: &APP_CODE bk_flow_engine
Expand Down
4 changes: 3 additions & 1 deletion bkflow/interface/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def bkflow_settings(request):
frontend_entry_url = "{}bkflow".format(settings.STATIC_URL) if settings.RUN_VER == "open" else "/static/bkflow"
enable_notice_center = int(EnvironmentVariables.objects.get_var("ENABLE_NOTICE_CENTER", 0))
language = request.COOKIES.get("blueking_language", "zh-cn")
doc_lang_mappings = {"zh-cn": "ZH", "en": "EN"}
run_ver_key = "BKAPP_RUN_VER_NAME" if language == "zh-cn" else "BKAPP_RUN_VER_NAME_{}".format(language.upper())

ctx = {
Expand All @@ -36,7 +37,8 @@ def bkflow_settings(request):
"MEMBER_SELECTOR_DATA_HOST": settings.MEMBER_SELECTOR_DATA_HOST,
"APP_CODE": settings.APP_CODE,
"USERNAME": request.user.username,
"BK_DOC_URL": f"{env.BK_DOC_CENTER_HOST}/markdown/ZH/BKFlow/1.8/UserGuide/Introduce/introduce.md",
"BK_DOC_URL": f"{env.BK_DOC_CENTER_HOST}/markdown/{doc_lang_mappings.get(language, 'ZH')}/BKFlow/1.8"
f"/UserGuide/Introduce/introduce.md",
# 是否开启通知中心
"ENABLE_NOTICE_CENTER": enable_notice_center,
"BK_PAAS_SHARED_RES_URL": env.BKPAAS_SHARED_RES_URL,
Expand Down
13 changes: 5 additions & 8 deletions bkflow/pipeline_plugins/components/collections/http/v1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from __future__ import absolute_import

import json
import traceback
from copy import deepcopy

Expand Down Expand Up @@ -93,10 +94,7 @@ def inputs_format(self):
key="bk_http_success_exp",
type="string",
schema=StringItemSchema(
description=_(
"根据返回的 JSON 的数据来控制节点的成功或失败, "
"使用 resp 引用返回的 JSON 对象,例 resp.result==True"
)
description=_("根据返回的 JSON 的数据来控制节点的成功或失败, " "使用 resp 引用返回的 JSON 对象,例 resp.result==True")
),
),
]
Expand Down Expand Up @@ -133,6 +131,8 @@ def plugin_schedule(self, data, parent_data, callback_data=None):
other = {"headers": {}, "timeout": timeout}

if method.upper() not in ["GET", "HEAD"]:
if not isinstance(body, str):
body = json.dumps(body)
other["data"] = body.encode("utf-8")
other["headers"] = {"Content-type": "application/json"}

Expand Down Expand Up @@ -195,10 +195,7 @@ def __getstate__(self):

class HttpComponent(Component):
name = _("HTTP 请求")
desc = _(
"提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 "
"2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功"
)
desc = _("提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 " "2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功")
code = "bk_http_request"
bound_service = HttpRequestService
version = "v1.0"
Expand Down
81 changes: 40 additions & 41 deletions bkflow/pipeline_plugins/query/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,54 @@

import logging

import requests
from django.conf import settings
from django.http import JsonResponse
from django.utils.translation import ugettext_lazy as _

logger = logging.getLogger("root")


def variable_select_source_data_proxy(request):
"""
@summary: 获取下拉框源数据的通用接口
@summary: 获取下拉框源数据的通用接口,暂时关闭该接口
@param request:
@return:
"""
url = request.GET.get("url")
try:
response = requests.get(url=url, verify=False, timeout=10)
except Exception as e:
logger.exception("variable select get data from url[url={url}] raise error: {error}".format(url=url, error=e))
text = _("请求数据异常: {error}").format(error=e)
data = [{"text": text, "value": ""}]
return JsonResponse(data, safe=False)
return JsonResponse([{"text": "text1", "value": "value1"}])

try:
data = response.json()
except Exception:
try:
content = response.content.decode(response.encoding)
logger.exception(
"variable select get data from url[url={url}] is not a valid JSON: {data}".format(
url=url, data=content[:500]
)
)
except Exception:
logger.exception("variable select get data from url[url={url}] data is not a valid JSON".format(url=url))
text = _("返回数据格式错误,不是合法 JSON 格式")
data = [{"text": text, "value": ""}]
return JsonResponse(data, safe=False)

# 支持开发者对远程数据源数据配置处理函数,进行再处理
post_process_function = getattr(settings, "REMOTE_SOURCE_DATA_TRANSFORM_FUNCTION", None)
if post_process_function and callable(post_process_function):
try:
data = post_process_function(data)
except Exception as e:
logger.exception(
"variable select transforming data from remote resource url[url={url}] "
"raise error: {error}".format(url=url, error=e)
)
text = _("远程数据源数据转换失败: {error}").format(error=e)
data = [{"text": text, "value": ""}]
return JsonResponse(data, safe=False)
# url = request.GET.get("url")
# try:
# response = requests.get(url=url, verify=False, timeout=10)
# except Exception as e:
# logger.exception("variable select get data from url[url={url}] raise error: {error}".format(url=url, error=e))
# text = _("请求数据异常: {error}").format(error=e)
# data = [{"text": text, "value": ""}]
# return JsonResponse(data, safe=False)
#
# try:
# data = response.json()
# except Exception:
# try:
# content = response.content.decode(response.encoding)
# logger.exception(
# "variable select get data from url[url={url}] is not a valid JSON: {data}".format(
# url=url, data=content[:500]
# )
# )
# except Exception:
# logger.exception("variable select get data from url[url={url}] data is not a valid JSON".format(url=url))
# text = _("返回数据格式错误,不是合法 JSON 格式")
# data = [{"text": text, "value": ""}]
# return JsonResponse(data, safe=False)
#
# # 支持开发者对远程数据源数据配置处理函数,进行再处理
# post_process_function = getattr(settings, "REMOTE_SOURCE_DATA_TRANSFORM_FUNCTION", None)
# if post_process_function and callable(post_process_function):
# try:
# data = post_process_function(data)
# except Exception as e:
# logger.exception(
# "variable select transforming data from remote resource url[url={url}] "
# "raise error: {error}".format(url=url, error=e)
# )
# text = _("远程数据源数据转换失败: {error}").format(error=e)
# data = [{"text": text, "value": ""}]
# return JsonResponse(data, safe=False)
34 changes: 18 additions & 16 deletions bkflow/pipeline_plugins/static/variables/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
hookable: true,
items: [{name: gettext("自定义"), value: "0"}, {name: gettext("远程数据源"), value: "1"}],
value: "0",
hidden: true,
validation: [
{
type: "required"
Expand All @@ -29,7 +30,7 @@
attrs: {
name: gettext("选项"),
hookable: true,
placeholder: gettext('请输入数据源信息,自定义数据源格式为 [{"text": "", "value": ""}...],若是远程数据源则填写返回该格式数据的 URL'),
placeholder: gettext('请输入数据源信息,自定义数据源格式为 [{"text": "", "value": ""}...]'),
validation: [
{
type: "required"
Expand Down Expand Up @@ -73,10 +74,11 @@
let remote_url = "";
let items = [];
let placeholder = '';
if (metaConfig.datasource === "1") {
remote_url = $.context.get('site_url') + 'api/plugin_query/variable_select_source_data_proxy/?url=' + metaConfig.items_text;
remote = true;
} else {
// if (metaConfig.datasource === "1") {
// remote_url = $.context.get('site_url') + 'api/plugin_query/variable_select_source_data_proxy/?url=' + metaConfig.items_text;
// remote = true;
// }
if (metaConfig.datasource === "0") {
try {
items = JSON.parse(metaConfig.items_text);
} catch (err) {
Expand All @@ -92,16 +94,16 @@
let multiple = false;
let default_val = metaConfig.default || '';

if (metaConfig.type === "1") {
multiple = true;
default_val = [];
if (metaConfig.default) {
let vals = metaConfig.default.split(',');
for (let i in vals) {
default_val.push(vals[i].trim());
}
}
}
// if (metaConfig.type === "1") {
// multiple = true;
// default_val = [];
// if (metaConfig.default) {
// let vals = metaConfig.default.split(',');
// for (let i in vals) {
// default_val.push(vals[i].trim());
// }
// }
// }
return {
tag_code: this.tag_code,
type: "select",
Expand All @@ -115,7 +117,7 @@
remote_url: remote_url,
placeholder: placeholder,
remote_data_init: function (data) {
return data
return data;
},
validation: [
{
Expand Down
18 changes: 18 additions & 0 deletions bkflow/space/migrations/0007_alter_space_app_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.15 on 2024-10-09 03:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('space', '0006_auto_20240823_1544'),
]

operations = [
migrations.AlterField(
model_name='space',
name='app_code',
field=models.CharField(max_length=32, verbose_name='应用ID'),
),
]
2 changes: 1 addition & 1 deletion bkflow/space/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Space(CommonModel):
id = models.AutoField(_("空间ID"), primary_key=True)
# 空间名不允许重复
name = models.CharField(_("空间名称"), max_length=32, null=False, blank=False, unique=True)
app_code = models.CharField(_("APP Code"), max_length=32, null=False, blank=False)
app_code = models.CharField(_("应用ID"), max_length=32, null=False, blank=False)
desc = models.CharField(_("空间描述"), max_length=128, null=True, blank=True)
platform_url = models.CharField(_("平台提供服务的地址"), max_length=256, null=False, blank=False)
create_type = models.CharField(
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ body {
min-width: 1366px;
}
.with-system-notice {
height: calc(100vh - 40px);
/deep/.container-content {
height: calc(100vh - 40px) !important;
.navigation-nav,
.container-content {
max-height: calc(100vh - 92px)!important;
}
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/layout/NavigationHeadLeft.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
},
methods: {
onHandleNavClick(nav) {
if (this.navActive === nav.id) return;
const { meta } = this.$route;
if (this.navActive === nav.id && meta.admin) return;

if (nav.id === 'space-manager') {
this.$router.push({ name: 'spaceAdmin' });
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/config/i18n/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ const cn = {
'描述:': '描述:',
'关联流程:': '关联流程:',
请选择: '请选择',
'ID/名称/创建人/更新人/所属模板 Id/所属作用域类型/所属作用域值': 'ID/名称/创建人/更新人/所属模板 Id/所属作用域类型/所属作用域值',
'ID/名称/创建人/更新人/所属模板 ID/所属作用域类型/所属作用域值': 'ID/名称/创建人/更新人/所属模板 ID/所属作用域类型/所属作用域值',
操作: '操作',
所属作用域类型: '所属作用域类型',
所属作用域值: '所属作用域值',
'所属模板 Id': '所属模板 Id',
'所属模板 ID': '所属模板 ID',
创建人: '创建人',
更新人: '更新人',
恢复默认值: '恢复默认值',
Expand All @@ -399,7 +399,7 @@ const cn = {
'数据格式不正确,应为JSON格式': '数据格式不正确,应为JSON格式',
'确认" {0} "恢复默认值?': '确认" {0} "恢复默认值?',
'删除成功!': '删除成功!',
'ID/任务名称/创建人/执行人/所属模板 Id/所属作用域类型/所属作用域值': 'ID/任务名称/创建人/执行人/所属模板 Id/所属作用域类型/所属作用域值',
'ID/任务名称/创建人/执行人/所属模板 ID/所属作用域类型/所属作用域值': 'ID/任务名称/创建人/执行人/所属模板 ID/所属作用域类型/所属作用域值',
引擎操作: '引擎操作',
任务名称: '任务名称',
执行人: '执行人',
Expand All @@ -409,14 +409,14 @@ const cn = {
未知: '未知',
'任务删除成功!': '任务删除成功!',
新建任务: '新建任务',
模板Id: '模板Id',
模板ID: '模板ID',
请求参数: '请求参数',
'请求参数格式不正确,应为JSON格式': '请求参数格式不正确,应为JSON格式',
任务创建成功: '任务创建成功',
新建流程: '新建流程',
流程名称: '流程名称',
流程创建成功: '流程创建成功',
'ID/模板名称/创建人/更新人/启用/所属作用域类型/所属作用域值': 'ID/模板名称/创建人/更新人/启用/所属作用域类型/所属作用域值',
'ID/流程名称/创建人/更新人/启用/所属作用域类型/所属作用域值': 'ID/流程名称/创建人/更新人/启用/所属作用域类型/所属作用域值',
创建流程: '创建流程',
'当前已选择 x 条数据': '当前已选择 {num} 条数据',
',': ',',
Expand Down Expand Up @@ -903,6 +903,10 @@ const cn = {
天: '天 | {n} 天 | {n} 天',
新建全局变量: '新建全局变量',
error_handle_秒: '秒',
流程的入参: '流程的入参',
scopeType: '指对应资源在接入平台所属的作用域范围的类型。如该资源属于业务 1,则该字段的值可设为"project"。',
scopeValue: '指对应资源在接入平台所属的作用域范围的值。如该资源属于业务1,则该字段的值可设为"1"。',
名字: '名字',
};

export default cn;
Loading
Loading