Skip to content

Commit

Permalink
bugfix: 创建定时任务时使用执行方案中的默认密文变量不生效 TencentBlueKing#1764
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed Jun 27, 2023
1 parent 284bf3e commit 9cb2d71
Showing 1 changed file with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -91,26 +93,7 @@ public InternalResponse<ServiceTaskExecuteResult> executeTask(ServiceTaskExecute

private TaskExecuteParam buildExecuteParam(ServiceTaskExecuteRequest request) {
List<TaskVariableDTO> 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())
Expand All @@ -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) {
Expand Down

0 comments on commit 9cb2d71

Please sign in to comment.