From e8a69fb7970a042e690c7908c76f6aab75e0611d Mon Sep 17 00:00:00 2001 From: dengyh <4622105+dengyh@users.noreply.github.com> Date: Wed, 1 Jul 2026 19:12:38 +0800 Subject: [PATCH] feat: add APIGW schedule polling resource --- .../commands/support-files/resources.yaml | 127 +++++++++++++++++- .../bpf_service/test_resources_yaml.py | 51 +++++++ 2 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 bk-plugin-framework/tests/services/bpf_service/test_resources_yaml.py diff --git a/bk-plugin-framework/bk_plugin_framework/services/bpf_service/management/commands/support-files/resources.yaml b/bk-plugin-framework/bk_plugin_framework/services/bpf_service/management/commands/support-files/resources.yaml index 6b900cf..9fb844d 100644 --- a/bk-plugin-framework/bk_plugin_framework/services/bpf_service/management/commands/support-files/resources.yaml +++ b/bk-plugin-framework/bk_plugin_framework/services/bpf_service/management/commands/support-files/resources.yaml @@ -121,6 +121,52 @@ paths: resourcePermissionRequired: true disabledStages: [] descriptionEn: Invoke specific version plugin + + /bk_plugin/schedule/{id}: + get: + operationId: schedule + summary: 获取插件调度详情 + description: 根据 trace_id 获取插件调度详情 + tags: + - schedule + parameters: + - in: path + name: id + schema: + type: string + required: true + description: 插件调用 trace id + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/EnvelopedScheduleResponse' + description: '查询成功' + x-bk-apigateway-resource: + isPublic: true + matchSubpath: false + backend: + type: HTTP + name: default + method: get + {% if settings.BK_PLUGIN_APIGW_BACKEND_SUB_PATH %} + path: /{env.api_sub_path}/bk_plugin/schedule/{id} + {% else %} + path: /bk_plugin/schedule/{id} + {% endif %} + matchSubpath: false + timeout: 0 + upstreams: {} + transformHeaders: {} + pluginConfigs: [] + allowApplyPermission: true + authConfig: + userVerifiedRequired: false + appVerifiedRequired: true + resourcePermissionRequired: false + disabledStages: [] + descriptionEn: Get plugin schedule detail with trace_id /bk_plugin/plugin_api/: x-bk-apigateway-method-any: operationId: plugin_api @@ -370,6 +416,64 @@ components: - result - trace_id + ScheduleData: + type: object + description: 插件调度返回数据 + properties: + trace_id: + type: string + description: 插件调用 trace id + plugin_version: + type: string + description: 插件版本 + state: + type: integer + description: '插件执行状态(2: POLL 3:CALLBACK 4:SUCCESS 5:FAIL)' + outputs: + type: object + additionalProperties: {} + description: 插件输出 + err: + type: string + description: 错误信息 + created_at: + type: string + description: 创建时间 + finish_at: + type: string + description: 结束时间 + required: + - created_at + - err + - finish_at + - outputs + - plugin_version + - state + - trace_id + + ScheduleResponse: + type: object + description: 插件调度响应 + properties: + result: + type: boolean + description: 请求是否成功 + message: + type: string + description: 请求额外信息,result 为 false 时读取 + trace_id: + type: string + description: 调用跟踪 ID + data: + allOf: + - $ref: '#/components/schemas/ScheduleData' + description: 接口数据 + required: + - data + - message + - result + - trace_id + PluginCallbackResponse: type: object description: 插件回调响应 @@ -428,6 +532,27 @@ components: - message - result + EnvelopedScheduleResponse: + type: object + description: 插件调度统一响应封装 + properties: + code: + type: integer + description: 状态码,0表示成功 + data: + $ref: '#/components/schemas/ScheduleResponse' + message: + type: string + description: 响应消息 + result: + type: boolean + description: 操作结果 + required: + - code + - data + - message + - result + EnvelopedPluginCallbackResponse: type: object description: 插件回调统一响应封装 @@ -468,4 +593,4 @@ components: - code - data - message - - result \ No newline at end of file + - result diff --git a/bk-plugin-framework/tests/services/bpf_service/test_resources_yaml.py b/bk-plugin-framework/tests/services/bpf_service/test_resources_yaml.py new file mode 100644 index 0000000..9e8b05e --- /dev/null +++ b/bk-plugin-framework/tests/services/bpf_service/test_resources_yaml.py @@ -0,0 +1,51 @@ +""" +Tencent is pleased to support the open source community by making 蓝鲸智云 - PaaS平台 (BlueKing - PaaS System) available. +Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +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. +""" + +from pathlib import Path + +import yaml +from django.template import Context, Engine + + +RESOURCE_TEMPLATE = ( + Path(__file__).parents[3] + / "bk_plugin_framework" + / "services" + / "bpf_service" + / "management" + / "commands" + / "support-files" + / "resources.yaml" +) + + +class TestGatewayResources: + def test_schedule_resource_is_public_and_requires_app_auth_only(self): + engine = Engine() + expected_backend_paths = [ + ("", "/bk_plugin/schedule/{id}"), + ("subpath", "/{env.api_sub_path}/bk_plugin/schedule/{id}"), + ] + + for backend_sub_path, expected_backend_path in expected_backend_paths: + rendered = engine.from_string(RESOURCE_TEMPLATE.read_text(encoding="utf-8")).render( + Context({"settings": {"BK_PLUGIN_APIGW_BACKEND_SUB_PATH": backend_sub_path}}) + ) + resource = yaml.safe_load(rendered)["paths"]["/bk_plugin/schedule/{id}"]["get"]["x-bk-apigateway-resource"] + + assert resource["isPublic"] is True + assert resource["allowApplyPermission"] is True + assert resource["authConfig"] == { + "userVerifiedRequired": False, + "appVerifiedRequired": True, + "resourcePermissionRequired": False, + } + assert resource["backend"]["path"] == expected_backend_path