Skip to content

Commit e65b01c

Browse files
author
Xinkai Yi
committed
feat: 新增bk_plugin模块下的apis通用视图接口
1 parent 6445e46 commit e65b01c

8 files changed

Lines changed: 18 additions & 29 deletions

File tree

bk-plugin-framework/bk_plugin_framework/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rest_framework import serializers
33

44

5-
def enveloper(serializer_class, many: bool = False):
5+
def standard_response_enveloper(serializer_class, many: bool = False):
66
"""统一响应包装器"""
77
component_name = "Enveloped{}{}".format(
88
serializer_class.__name__.replace("Serializer", ""),

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
from django.utils.decorators import method_decorator
2020
from drf_spectacular.utils import extend_schema
2121
from rest_framework import serializers
22-
from rest_framework.decorators import action
2322
from rest_framework.response import Response
2423
from rest_framework.views import APIView
2524

2625
from bk_plugin_framework.runtime.callback.api import callback, parse_callback_token
27-
from bk_plugin_framework.serializers import enveloper
26+
from bk_plugin_framework.serializers import standard_response_enveloper
2827

2928
logger = logging.getLogger("bk_plugin")
3029

@@ -45,8 +44,9 @@ class PluginCallback(APIView):
4544

4645
@extend_schema(
4746
summary="插件回调",
47+
operation_id="callback",
4848
request=PluginCallbackParamsSerializer,
49-
responses={200: enveloper(PluginCallbackResponseSerializer)},
49+
responses={200: standard_response_enveloper(PluginCallbackResponseSerializer)},
5050
extensions=gen_apigateway_resource_config(
5151
is_public=True,
5252
allow_apply_permission=True,
@@ -57,7 +57,6 @@ class PluginCallback(APIView):
5757
match_subpath=False,
5858
),
5959
)
60-
@action(methods=["POST"], detail=True)
6160
def post(self, request, token):
6261
logger.info("[plugin callback]token=({}),body={}".format(token, request.body))
6362

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
from django.utils.decorators import method_decorator
1717
from drf_spectacular.utils import extend_schema
1818
from rest_framework import permissions, serializers, status
19-
from rest_framework.decorators import action
2019
from rest_framework.response import Response
2120
from rest_framework.views import APIView
2221

2322
from bk_plugin_framework.hub import VersionHub
24-
from bk_plugin_framework.serializers import enveloper
23+
from bk_plugin_framework.serializers import standard_response_enveloper
2524
from bk_plugin_framework.services.bpf_service.api.serializers import (
2625
StandardResponseSerializer,
2726
)
@@ -70,7 +69,7 @@ class Detail(APIView):
7069

7170
@extend_schema(
7271
summary="Get plugin detail for specific version",
73-
responses={200: enveloper(DetailResponseSerializer)},
72+
responses={200: standard_response_enveloper(DetailResponseSerializer)},
7473
extensions=gen_apigateway_resource_config(
7574
is_public=True,
7675
allow_apply_permission=True,
@@ -81,7 +80,6 @@ class Detail(APIView):
8180
match_subpath=False,
8281
),
8382
)
84-
@action(methods=["GET"], detail=True)
8583
def get(self, request, version):
8684
plugin_cls = VersionHub.all_plugins().get(version)
8785
if not plugin_cls:

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
from django.utils.decorators import method_decorator
1818
from drf_spectacular.utils import extend_schema
1919
from rest_framework import serializers, status
20-
from rest_framework.decorators import action
2120
from rest_framework.exceptions import ValidationError
2221
from rest_framework.response import Response
2322
from rest_framework.views import APIView
2423

2524
from bk_plugin_framework.hub import VersionHub
2625
from bk_plugin_framework.runtime.executor import BKPluginExecutor
27-
from bk_plugin_framework.serializers import enveloper
26+
from bk_plugin_framework.serializers import standard_response_enveloper
2827
from bk_plugin_framework.services.bpf_service.api.permissions import (
2928
ScopeAllowPermission,
3029
)
@@ -60,8 +59,9 @@ class Invoke(APIView):
6059

6160
@extend_schema(
6261
summary="插件调用",
62+
operation_id="invoke",
6363
request=InvokeParamsSerializer,
64-
responses={200: enveloper(InvokeResponseSerializer)},
64+
responses={200: standard_response_enveloper(InvokeResponseSerializer)},
6565
extensions=gen_apigateway_resource_config(
6666
is_public=True,
6767
allow_apply_permission=True,
@@ -72,7 +72,6 @@ class Invoke(APIView):
7272
match_subpath=False,
7373
),
7474
)
75-
@action(methods=["POST"], detail=True)
7675
def post(self, request, version):
7776
plugin_cls = VersionHub.all_plugins().get(version)
7877
if not plugin_cls:

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
from django.utils.decorators import method_decorator
1717
from drf_spectacular.utils import extend_schema
1818
from rest_framework import permissions, serializers
19-
from rest_framework.decorators import action
2019
from rest_framework.response import Response
2120
from rest_framework.views import APIView
2221

2322
from bk_plugin_framework.runtime.loghub.models import LogEntry
24-
from bk_plugin_framework.serializers import enveloper
23+
from bk_plugin_framework.serializers import standard_response_enveloper
2524
from bk_plugin_framework.services.bpf_service.api.serializers import (
2625
StandardResponseSerializer,
2726
)
@@ -46,7 +45,7 @@ class Logs(APIView):
4645

4746
@extend_schema(
4847
summary="Get plugin execution log with trace_id",
49-
responses={200: enveloper(LogsResponseSerializer)},
48+
responses={200: standard_response_enveloper(LogsResponseSerializer)},
5049
extensions=gen_apigateway_resource_config(
5150
is_public=True,
5251
allow_apply_permission=True,
@@ -57,6 +56,5 @@ class Logs(APIView):
5756
match_subpath=False,
5857
),
5958
)
60-
@action(methods=["GET"], detail=True)
6159
def get(self, request, trace_id):
6260
return Response({"result": True, "data": {"log": LogEntry.objects.get_plain_log(trace_id)}, "message": ""})

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
from django.utils.decorators import method_decorator
1919
from drf_spectacular.utils import extend_schema
2020
from rest_framework import permissions, serializers
21-
from rest_framework.decorators import action
2221
from rest_framework.response import Response
2322
from rest_framework.views import APIView
2423

2524
from bk_plugin_framework import __version__ as bpf_version
2625
from bk_plugin_framework.hub import VersionHub
27-
from bk_plugin_framework.serializers import enveloper
26+
from bk_plugin_framework.serializers import standard_response_enveloper
2827
from bk_plugin_framework.services.bpf_service.api.serializers import (
2928
StandardResponseSerializer,
3029
)
@@ -64,7 +63,7 @@ class Meta(APIView):
6463

6564
@extend_schema(
6665
summary="Get plugin meta info",
67-
responses={200: enveloper(MetaResponseSerializer)},
66+
responses={200: standard_response_enveloper(MetaResponseSerializer)},
6867
extensions=gen_apigateway_resource_config(
6968
is_public=True,
7069
allow_apply_permission=True,
@@ -75,7 +74,6 @@ class Meta(APIView):
7574
match_subpath=False,
7675
),
7776
)
78-
@action(methods=["GET"], detail=True)
7977
def get(self, request):
8078
try:
8179
meta_module = import_module("bk_plugin.meta")

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
from django.utils.decorators import method_decorator
2323
from drf_spectacular.utils import extend_schema
2424
from rest_framework import serializers, status
25-
from rest_framework.decorators import action
2625
from rest_framework.exceptions import ValidationError
2726
from rest_framework.response import Response
2827
from rest_framework.views import APIView
2928

30-
from bk_plugin_framework.serializers import enveloper
29+
from bk_plugin_framework.serializers import standard_response_enveloper
3130
from bk_plugin_framework.services.bpf_service.api.permissions import (
3231
ScopeAllowPermission,
3332
)
@@ -81,8 +80,9 @@ class PluginAPIDispatch(APIView):
8180

8281
@extend_schema(
8382
summary="插件API分发",
83+
operation_id="plugin_api_dispatch",
8484
request=PluginAPIDispatchParamsSerializer,
85-
responses={200: enveloper(PluginAPIDispatchResponseSerializer)},
85+
responses={200: standard_response_enveloper(PluginAPIDispatchResponseSerializer)},
8686
extensions=gen_apigateway_resource_config(
8787
is_public=True,
8888
allow_apply_permission=True,
@@ -93,7 +93,6 @@ class PluginAPIDispatch(APIView):
9393
match_subpath=False,
9494
),
9595
)
96-
@action(methods=["POST"], detail=True)
9796
def post(self, request):
9897
data_serializer = PluginAPIDispatchParamsSerializer(data=request.data)
9998
try:

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
from django.utils.decorators import method_decorator
1818
from drf_spectacular.utils import extend_schema
1919
from rest_framework import permissions, serializers
20-
from rest_framework.decorators import action
2120
from rest_framework.response import Response
2221
from rest_framework.views import APIView
2322

2423
from bk_plugin_framework.runtime.schedule.models import Schedule as ScheduleModel
25-
from bk_plugin_framework.serializers import enveloper
24+
from bk_plugin_framework.serializers import standard_response_enveloper
2625
from bk_plugin_framework.services.bpf_service.api.serializers import (
2726
StandardResponseSerializer,
2827
)
@@ -58,7 +57,7 @@ class Schedule(APIView):
5857
@extend_schema(
5958
summary="获取插件调度详情",
6059
request=ScheduleParamsSerializer,
61-
responses={200: enveloper(ScheduleResponseSerializer)},
60+
responses={200: standard_response_enveloper(ScheduleResponseSerializer)},
6261
extensions=gen_apigateway_resource_config(
6362
is_public=True,
6463
allow_apply_permission=True,
@@ -69,7 +68,6 @@ class Schedule(APIView):
6968
match_subpath=False,
7069
),
7170
)
72-
@action(methods=["GET"], detail=True)
7371
def get(self, request, trace_id):
7472
try:
7573
s = ScheduleModel.objects.get(trace_id=trace_id)

0 commit comments

Comments
 (0)