|
43 | 43 | TaskTemplateSerializer,
|
44 | 44 | TopCollectionTaskTemplateSerializer,
|
45 | 45 | TemplateLabelQuerySerializer,
|
| 46 | + WebhookConfigQuerySerializer, |
46 | 47 | )
|
47 | 48 | from gcloud.core.apis.drf.viewsets.base import GcloudModelViewSet
|
48 | 49 | from gcloud.iam_auth import IAMMeta, res_factory
|
|
53 | 54 | from gcloud.user_custom_config.constants import TASKTMPL_ORDERBY_OPTIONS
|
54 | 55 | from gcloud.utils.webhook import apply_webhook_configs, get_webhook_configs, clear_scope_webhooks
|
55 | 56 | from gcloud.core.apis.drf.exceptions import ValidationException
|
| 57 | +from webhook.api import verify_webhook_endpoint |
56 | 58 |
|
57 | 59 | logger = logging.getLogger("root")
|
58 | 60 | manager = TemplateManager(template_model_cls=TaskTemplate)
|
@@ -88,6 +90,9 @@ class TaskTemplatePermission(IamPermission):
|
88 | 90 | "update_template_labels": IamPermissionInfo(
|
89 | 91 | IAMMeta.FLOW_EDIT_ACTION, res_factory.resources_for_flow_obj, HAS_OBJECT_PERMISSION
|
90 | 92 | ),
|
| 93 | + "verify_webhook_configuration": IamPermissionInfo( |
| 94 | + IAMMeta.FLOW_EDIT_ACTION, res_factory.resources_for_flow_obj, HAS_OBJECT_PERMISSION |
| 95 | + ), |
91 | 96 | }
|
92 | 97 |
|
93 | 98 |
|
@@ -414,3 +419,21 @@ def update_template_labels(self, request, *args, **kwargs):
|
414 | 419 | return Response({"detail": ErrorDetail(message, err_code.REQUEST_PARAM_INVALID.code)}, exception=True)
|
415 | 420 |
|
416 | 421 | 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) |
0 commit comments