Skip to content

Commit ed50bcb

Browse files
committed
feat: 增加webhook请求调试方法 --story=126514126
# Reviewed, transaction id: 54982
1 parent 54205cc commit ed50bcb

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

config/default.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@
238238
INSTALLED_APPS = locals().get("INSTALLED_APPS", [])
239239
INSTALLED_APPS += ("django_celery_beat", "django_celery_results")
240240
CELERY_ENABLE_UTC = False
241-
CELERY_TASK_SERIALIZER = "pickle"
242-
CELERY_ACCEPT_CONTENT = ["json", "pickle", "msgpack", "yaml"]
241+
CELERY_TASK_SERIALIZER = "json"
243242
CELERYBEAT_SCHEDULER = "django_celery_beat.schedulers.DatabaseScheduler"
244243

245244
TEMPLATE_DATA_SALT = "821a11587ea434eb85c2f5327a90ae54"
Binary file not shown.
Binary file not shown.

gcloud/core/apis/drf/serilaziers/task_template.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,12 @@ class TemplateLabelQuerySerializer(serializers.Serializer):
130130
label_ids = serializers.ListField(
131131
child=serializers.IntegerField(), allow_empty=True, required=True, help_text="标签ID列表"
132132
)
133+
134+
135+
class WebhookConfigQuerySerializer(serializers.Serializer):
136+
webhook_config = serializers.JSONField(help_text="webhook配置", required=True)
137+
138+
def validate_webhook_config(self, value):
139+
if not value.get("url"):
140+
raise serializers.ValidationError("缺少请求地址")
141+
return value

gcloud/core/apis/drf/viewsets/task_template.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
TaskTemplateSerializer,
4444
TopCollectionTaskTemplateSerializer,
4545
TemplateLabelQuerySerializer,
46+
WebhookConfigQuerySerializer,
4647
)
4748
from gcloud.core.apis.drf.viewsets.base import GcloudModelViewSet
4849
from gcloud.iam_auth import IAMMeta, res_factory
@@ -53,6 +54,7 @@
5354
from gcloud.user_custom_config.constants import TASKTMPL_ORDERBY_OPTIONS
5455
from gcloud.utils.webhook import apply_webhook_configs, get_webhook_configs, clear_scope_webhooks
5556
from gcloud.core.apis.drf.exceptions import ValidationException
57+
from webhook.api import verify_webhook_endpoint
5658

5759
logger = logging.getLogger("root")
5860
manager = TemplateManager(template_model_cls=TaskTemplate)
@@ -88,6 +90,9 @@ class TaskTemplatePermission(IamPermission):
8890
"update_template_labels": IamPermissionInfo(
8991
IAMMeta.FLOW_EDIT_ACTION, res_factory.resources_for_flow_obj, HAS_OBJECT_PERMISSION
9092
),
93+
"verify_webhook_configuration": IamPermissionInfo(
94+
IAMMeta.FLOW_EDIT_ACTION, res_factory.resources_for_flow_obj, HAS_OBJECT_PERMISSION
95+
),
9196
}
9297

9398

@@ -414,3 +419,21 @@ def update_template_labels(self, request, *args, **kwargs):
414419
return Response({"detail": ErrorDetail(message, err_code.REQUEST_PARAM_INVALID.code)}, exception=True)
415420

416421
return Response({"name": template.name, "label_ids": label_ids})
422+
423+
@swagger_auto_schema(method="POST", operation_summary="验证Webhook配置", request_body=WebhookConfigQuerySerializer)
424+
@action(methods=["POST"], detail=False)
425+
def verify_webhook_configuration(self, request, *args, **kwargs):
426+
serializer = WebhookConfigQuerySerializer(data=request.data)
427+
serializer.is_valid(raise_exception=True)
428+
webhook_config = serializer.validated_data["webhook_config"]
429+
try:
430+
verify_result = verify_webhook_endpoint(webhook_config)
431+
except Exception as e:
432+
message = str(e)
433+
return Response({"detail": ErrorDetail(message, err_code.REQUEST_PARAM_INVALID.code)}, exception=True)
434+
435+
if not verify_result.ok:
436+
message = str(verify_result.json_response())
437+
return Response({"detail": ErrorDetail(message, err_code.REQUEST_PARAM_INVALID.code)}, exception=True)
438+
439+
return Response(status=status.HTTP_200_OK)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ bk-notice-sdk==1.3.0
105105
croniter==1.4.1
106106

107107
# bkflow feel
108-
./dist/bkflow_django_webhook-1.2.0rc3-py2.py3-none-any.whl
108+
./dist/bkflow_django_webhook-1.2.0rc5-py2.py3-none-any.whl

0 commit comments

Comments
 (0)