From 9bc880e486bcb7672035a05412d1ec422a1c7494 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Fri, 5 May 2023 18:12:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A4=84=E7=90=86=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E6=8A=A5=E5=91=8A=E6=9F=A5=E8=AF=A2=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=B1=A0=E7=9A=84=E8=BF=94=E5=9B=9E=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ShareController.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/controller/ShareController.java b/backend/src/main/java/io/metersphere/controller/ShareController.java index c5bdfbf0e9..d103237e57 100644 --- a/backend/src/main/java/io/metersphere/controller/ShareController.java +++ b/backend/src/main/java/io/metersphere/controller/ShareController.java @@ -1,5 +1,7 @@ package io.metersphere.controller; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.APIReportResult; @@ -11,6 +13,7 @@ import io.metersphere.api.service.ApiScenarioReportService; import io.metersphere.api.service.ShareInfoService; import io.metersphere.base.domain.IssuesDao; import io.metersphere.base.domain.LoadTestReportLog; +import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; @@ -32,6 +35,7 @@ import io.metersphere.track.dto.TestPlanLoadCaseDTO; import io.metersphere.track.dto.TestPlanSimpleReportDTO; import io.metersphere.track.request.testplan.LoadCaseReportRequest; import io.metersphere.track.service.*; +import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -309,7 +313,29 @@ public class ShareController { public List getTestResourcePools() { QueryResourcePoolRequest resourcePoolRequest = new QueryResourcePoolRequest(); resourcePoolRequest.setStatus(ResourceStatusEnum.VALID.name()); - return testResourcePoolService.listResourcePools(resourcePoolRequest); + // 数据脱敏 + // 仅对k8s操作 + List testResourcePoolDTOS = testResourcePoolService.listResourcePools(resourcePoolRequest); + testResourcePoolDTOS.stream() + .filter(testResourcePoolDTO -> StringUtils.equals(ResourcePoolTypeEnum.K8S.name(), testResourcePoolDTO.getType())) + .forEach(pool -> pool.getResources().forEach(resource -> { + String configuration = resource.getConfiguration(); + JSONObject map = JSON.parseObject(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; } @GetMapping("/{shareId}/scenario/report/selectReportContent/{stepId}")