refactor: 处理分享报告查询资源池的返回信息

This commit is contained in:
CaptainB 2023-04-26 18:41:49 +08:00 committed by 刘瑞斌
parent 0ed71bc9ec
commit b420106262
1 changed files with 29 additions and 1 deletions

View File

@ -3,12 +3,16 @@ package io.metersphere.controller;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.LoadTestReportLog; import io.metersphere.base.domain.LoadTestReportLog;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.constants.ResourceStatusEnum;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.dto.*; import io.metersphere.dto.*;
import io.metersphere.request.resourcepool.QueryResourcePoolRequest; import io.metersphere.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.service.*; import io.metersphere.service.*;
import io.metersphere.xpack.resourcepool.engine.provider.ClientCredential;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -17,7 +21,9 @@ import org.springframework.web.bind.annotation.RestController;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
@RequestMapping("share") @RequestMapping("share")
@ -171,7 +177,29 @@ public class ShareController {
public List<TestResourcePoolDTO> getTestResourcePools() { public List<TestResourcePoolDTO> getTestResourcePools() {
QueryResourcePoolRequest resourcePoolRequest = new QueryResourcePoolRequest(); QueryResourcePoolRequest resourcePoolRequest = new QueryResourcePoolRequest();
resourcePoolRequest.setStatus(ResourceStatusEnum.VALID.name()); resourcePoolRequest.setStatus(ResourceStatusEnum.VALID.name());
return baseTestResourcePoolService.listResourcePools(resourcePoolRequest); // 数据脱敏
// 仅对k8s操作
List<TestResourcePoolDTO> testResourcePoolDTOS = baseTestResourcePoolService.listResourcePools(resourcePoolRequest);
testResourcePoolDTOS.stream()
.filter(testResourcePoolDTO -> StringUtils.equals(ResourcePoolTypeEnum.K8S.name(), testResourcePoolDTO.getType()))
.forEach(pool -> pool.getResources().forEach(resource -> {
String configuration = resource.getConfiguration();
Map map = JSON.parseMap(configuration);
if (map.containsKey("token")) {
map.put("token", "******");
}
if (map.containsKey("masterUrl")) {
map.put("masterUrl", "******");
}
if (map.containsKey("jobTemplate")) {
map.put("jobTemplate", "******");
}
if (map.containsKey("namespace")) {
map.put("namespace", "******");
}
resource.setConfiguration(JSON.toJSONString(map));
}));
return testResourcePoolDTOS;
} }
} }