From cdd41778df2381df1fb5852dc1a21d543d89d7a7 Mon Sep 17 00:00:00 2001 From: jsonwan Date: Wed, 1 Mar 2023 15:24:21 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E5=88=9B=E5=BB=BA=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=B6=E4=BD=BF=E7=94=A8=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E6=96=B9=E6=A1=88=E4=B8=AD=E7=9A=84=E9=BB=98=E8=AE=A4=E5=AF=86?= =?UTF-8?q?=E6=96=87=E5=8F=98=E9=87=8F=E4=B8=8D=E7=94=9F=E6=95=88=20#1764?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inner/ServiceExecuteTaskResourceImpl.java | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java index 3dc71c002b..b5abb571ed 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java @@ -54,6 +54,8 @@ import java.util.ArrayList; import java.util.List; +import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.CIPHER; + @RestController @Slf4j public class ServiceExecuteTaskResourceImpl implements ServiceExecuteTaskResource { @@ -91,26 +93,7 @@ public InternalResponse executeTask(ServiceTaskExecute private TaskExecuteParam buildExecuteParam(ServiceTaskExecuteRequest request) { List executeVariableValues = new ArrayList<>(); - if (request.getTaskVariables() != null) { - for (ServiceTaskVariable serviceTaskVariable : request.getTaskVariables()) { - TaskVariableDTO taskVariableDTO = new TaskVariableDTO(); - taskVariableDTO.setId(serviceTaskVariable.getId()); - if (serviceTaskVariable.getType() == TaskVariableTypeEnum.STRING.getType() - || serviceTaskVariable.getType() == TaskVariableTypeEnum.CIPHER.getType() - || serviceTaskVariable.getType() == TaskVariableTypeEnum.INDEX_ARRAY.getType() - || serviceTaskVariable.getType() == TaskVariableTypeEnum.ASSOCIATIVE_ARRAY.getType()) { - taskVariableDTO.setValue(serviceTaskVariable.getStringValue()); - } else if (serviceTaskVariable.getType() == TaskVariableTypeEnum.HOST_LIST.getType()) { - ServiceTargetServers serviceServers = serviceTaskVariable.getServerValue(); - ServersDTO serversDTO = convertToServersDTO(serviceServers); - taskVariableDTO.setTargetServers(serversDTO); - } else if (serviceTaskVariable.getType() == TaskVariableTypeEnum.NAMESPACE.getType()) { - taskVariableDTO.setValue(serviceTaskVariable.getNamespaceValue()); - } - executeVariableValues.add(taskVariableDTO); - } - } - return TaskExecuteParam + TaskExecuteParam taskExecuteParam = TaskExecuteParam .builder() .appId(request.getAppId()) .planId(request.getPlanId()) @@ -121,6 +104,35 @@ private TaskExecuteParam buildExecuteParam(ServiceTaskExecuteRequest request) { .taskName(request.getTaskName()) .skipAuth(request.getCronTaskId() != null && request.isSkipAuth()) .build(); + if (request.getTaskVariables() == null) { + return taskExecuteParam; + } + // 解析构造全局变量 + for (ServiceTaskVariable serviceTaskVariable : request.getTaskVariables()) { + TaskVariableDTO taskVariableDTO = new TaskVariableDTO(); + taskVariableDTO.setId(serviceTaskVariable.getId()); + if (serviceTaskVariable.getType() == TaskVariableTypeEnum.STRING.getType() + || serviceTaskVariable.getType() == TaskVariableTypeEnum.INDEX_ARRAY.getType() + || serviceTaskVariable.getType() == TaskVariableTypeEnum.ASSOCIATIVE_ARRAY.getType()) { + taskVariableDTO.setValue(serviceTaskVariable.getStringValue()); + } else if (serviceTaskVariable.getType() == CIPHER.getType()) { + // 如果密码类型的变量传入为空或者“******”,那么密码使用系统中保存的 + if (serviceTaskVariable.getStringValue() == null || "******".equals(serviceTaskVariable.getStringValue())) { + continue; + } else { + taskVariableDTO.setValue(serviceTaskVariable.getStringValue()); + } + } else if (serviceTaskVariable.getType() == TaskVariableTypeEnum.HOST_LIST.getType()) { + ServiceTargetServers serviceServers = serviceTaskVariable.getServerValue(); + ServersDTO serversDTO = convertToServersDTO(serviceServers); + taskVariableDTO.setTargetServers(serversDTO); + } else if (serviceTaskVariable.getType() == TaskVariableTypeEnum.NAMESPACE.getType()) { + taskVariableDTO.setValue(serviceTaskVariable.getNamespaceValue()); + } + executeVariableValues.add(taskVariableDTO); + } + taskExecuteParam.setExecuteVariableValues(executeVariableValues); + return taskExecuteParam; } private ServersDTO convertToServersDTO(ServiceTargetServers servers) {