Skip to content

Commit

Permalink
fix: send() sender参数字符串传参修改成对象,sha1算法替换成sha256 TencentBlueKing#7625
Browse files Browse the repository at this point in the history
  • Loading branch information
huangpixu committed Dec 9, 2024
1 parent a476a92 commit 4a16b08
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
15 changes: 9 additions & 6 deletions gcloud/contrib/operate_record/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

from django.dispatch import Signal, receiver

from gcloud.contrib.operate_record.helpers import record_template_operation_helper, record_task_operation_helper
from gcloud.contrib.operate_record.constants import RecordType
from gcloud.contrib.operate_record.helpers import record_task_operation_helper, record_template_operation_helper

# signal_sender: RecordType
operate_record_signal = Signal(
["operator", "operate_type", "operate_source", "instance_id", "project_id", "node_id", "extra_info"]
)


@receiver(operate_record_signal, sender=RecordType.template.name)
@receiver(operate_record_signal, sender=RecordType.template)
def record_template_handler(operator, operate_type, operate_source, instance_id, project_id, **kwargs):
record_template_operation_helper(
operator=operator,
Expand All @@ -33,14 +33,17 @@ def record_template_handler(operator, operate_type, operate_source, instance_id,
)


@receiver(operate_record_signal, sender=RecordType.common_template.name)
@receiver(operate_record_signal, sender=RecordType.common_template)
def record_common_template_handler(operator, operate_type, operate_source, instance_id, **kwargs):
record_template_operation_helper(
operator=operator, operate_type=operate_type, operate_source=operate_source, template_id=instance_id,
operator=operator,
operate_type=operate_type,
operate_source=operate_source,
template_id=instance_id,
)


@receiver(operate_record_signal, sender=RecordType.task.name)
@receiver(operate_record_signal, sender=RecordType.task)
def record_task_handler(operator, operate_type, operate_source, instance_id, project_id, extra_info="", **kwargs):
record_task_operation_helper(
operator=operator,
Expand All @@ -52,7 +55,7 @@ def record_task_handler(operator, operate_type, operate_source, instance_id, pro
)


@receiver(operate_record_signal, sender=RecordType.task_node.name)
@receiver(operate_record_signal, sender=RecordType.task_node)
def record_task_node_handler(operator, operate_type, operate_source, instance_id, project_id, node_id, **kwargs):
record_task_operation_helper(
operator=operator,
Expand Down
8 changes: 4 additions & 4 deletions gcloud/core/apis/drf/viewsets/common_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.db import transaction
from django.db.models import BooleanField, ExpressionWrapper, Q
from drf_yasg.utils import swagger_auto_schema
from iam import Action, Request, Resource, Subject
from pipeline.models import TemplateScheme
from rest_framework import permissions, status
from rest_framework.decorators import action
Expand Down Expand Up @@ -45,7 +46,6 @@
from gcloud.iam_auth import IAMMeta, get_iam_client, res_factory
from gcloud.taskflow3.models import TaskConfig
from gcloud.template_base.domains.template_manager import TemplateManager
from iam import Action, Request, Resource, Subject

logger = logging.getLogger("root")
manager = TemplateManager(template_model_cls=CommonTemplate)
Expand Down Expand Up @@ -210,7 +210,7 @@ def create(self, request, *args, **kwargs):
data = self.injection_auth_actions(request, serializer.data, serializer.instance)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.common_template.name,
sender=RecordType.common_template,
operator=creator,
operate_type=OperateType.create.name,
operate_source=OperateSource.common.name,
Expand Down Expand Up @@ -259,7 +259,7 @@ def update(self, request, *args, **kwargs):
data = self.injection_auth_actions(request, serializer.data, template)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.common_template.name,
sender=RecordType.common_template,
operator=editor,
operate_type=OperateType.update.name,
operate_source=OperateSource.common.name,
Expand All @@ -284,7 +284,7 @@ def destroy(self, request, *args, **kwargs):
self.perform_destroy(template)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.common_template.name,
sender=RecordType.common_template,
operator=request.user.username,
operate_type=OperateType.delete.name,
operate_source=OperateSource.common.name,
Expand Down
14 changes: 9 additions & 5 deletions gcloud/core/apis/drf/viewsets/task_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def create(self, request, *args, **kwargs):
data = self.injection_auth_actions(request, serializer.data, serializer.instance)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.template.name,
sender=RecordType.template,
operator=creator,
operate_type=OperateType.create.name,
operate_source=OperateSource.project.name,
Expand Down Expand Up @@ -302,7 +302,7 @@ def update(self, request, *args, **kwargs):
data = self.injection_auth_actions(request, serializer.data, template)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.template.name,
sender=RecordType.template,
operator=editor,
operate_type=OperateType.update.name,
operate_source=OperateSource.project.name,
Expand Down Expand Up @@ -337,7 +337,7 @@ def destroy(self, request, *args, **kwargs):
)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.template.name,
sender=RecordType.template,
operator=request.user.username,
operate_type=OperateType.delete.name,
operate_source=OperateSource.project.name,
Expand All @@ -352,15 +352,19 @@ def destroy(self, request, *args, **kwargs):
)
return Response(status=status.HTTP_204_NO_CONTENT)

@swagger_auto_schema(method="GET", operation_summary="查询流程是否开启独立子流程", query_serializer=ProjectInfoQuerySerializer)
@swagger_auto_schema(
method="GET", operation_summary="查询流程是否开启独立子流程", query_serializer=ProjectInfoQuerySerializer
)
@action(methods=["GET"], detail=True)
def enable_independent_subprocess(self, request, *args, **kwargs):
template_id = kwargs.get("pk")
project_id = request.query_params.get("project_id")
independent_subprocess_enable = TaskConfig.objects.enable_independent_subprocess(project_id, template_id)
return Response({"enable": independent_subprocess_enable})

@swagger_auto_schema(method="GET", operation_summary="获取流程详情公开信息", query_serializer=ProjectFilterQuerySerializer)
@swagger_auto_schema(
method="GET", operation_summary="获取流程详情公开信息", query_serializer=ProjectFilterQuerySerializer
)
@action(methods=["GET"], detail=True)
def common_info(self, request, *args, **kwargs):
template = self.get_object()
Expand Down
4 changes: 2 additions & 2 deletions gcloud/core/apis/drf/viewsets/taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def perform_create(self, serializer):
extra_info = extract_extra_info(constants)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.task.name,
sender=RecordType.task,
operator=pipeline_instance_kwargs["creator"],
operate_type=OperateType.create.name,
operate_source=OperateSource.app.name,
Expand Down Expand Up @@ -577,7 +577,7 @@ def destroy(self, request, *args, **kwargs):
self.perform_destroy(instance)
# 记录操作流水
operate_record_signal.send(
sender=RecordType.task.name,
sender=RecordType.task,
operator=self.request.user.username,
operate_type=OperateType.delete.name,
operate_source=OperateSource.app.name,
Expand Down
7 changes: 3 additions & 4 deletions packages/blueking/component/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
"""

import base64
import hmac
import hashlib
import hmac

import ujson as json


def get_signature(method, path, app_secret, params=None, data=None):
"""generate signature
"""
"""generate signature"""
kwargs = {}
if params:
kwargs.update(params)
Expand All @@ -29,5 +28,5 @@ def get_signature(method, path, app_secret, params=None, data=None):
kwargs["data"] = data
kwargs = "&".join(["%s=%s" % (k, v) for k, v in sorted(list(kwargs.items()), key=lambda x: x[0])])
orignal = "%s%s?%s" % (method, path, kwargs)
signature = base64.b64encode(hmac.new(str(app_secret), orignal, hashlib.sha1).digest())
signature = base64.b64encode(hmac.new(str(app_secret), orignal, hashlib.sha256).digest())
return signature
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import json
from typing import List

import pytz
from bamboo_engine.context import Context
from bamboo_engine.template import Template
from django.conf import settings
from django.db import transaction
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from pipeline.component_framework.component import Component
from pipeline.core.flow import Service
Expand Down Expand Up @@ -128,7 +128,7 @@ def execute(self, data, parent_data):
getattr(Project.objects.filter(id=parent_data.get_one_of_inputs("project_id")).first(), "time_zone")
or settings.TIME_ZONE
)
time_stamp = datetime.datetime.now(tz=timezone.pytz.timezone(project_tz)).strftime("%Y%m%d%H%M%S")
time_stamp = datetime.datetime.now(tz=pytz.timezone(project_tz)).strftime("%Y%m%d%H%M%S")
template_name = getattr(PipelineTemplate.objects.filter(template_id=subprocess.template_id).first(), "name")
pipeline_instance_kwargs = {
"name": f"{template_name}_{time_stamp}",
Expand Down Expand Up @@ -203,7 +203,7 @@ def execute(self, data, parent_data):
pipeline_constants = pipeline_instance.execution_data.get("constants")
extra_info = extract_extra_info(pipeline_constants)
operate_record_signal.send(
sender=RecordType.task.name,
sender=RecordType.task,
operator="system",
operate_type=OperateType.create.name,
operate_source=OperateSource.parent.name,
Expand All @@ -219,7 +219,7 @@ def execute(self, data, parent_data):

# 记录操作流水
operate_record_signal.send(
sender=RecordType.task.name,
sender=RecordType.task,
operator="system",
operate_type=OperateType.start.name,
operate_source=OperateSource.parent.name,
Expand Down

0 comments on commit 4a16b08

Please sign in to comment.