From b420106262f24248886f7077103e67390450772b Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 26 Apr 2023 18:41:49 +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 | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/performance-test/backend/src/main/java/io/metersphere/controller/ShareController.java b/performance-test/backend/src/main/java/io/metersphere/controller/ShareController.java index 720e276004..affeac5874 100644 --- a/performance-test/backend/src/main/java/io/metersphere/controller/ShareController.java +++ b/performance-test/backend/src/main/java/io/metersphere/controller/ShareController.java @@ -3,12 +3,16 @@ package io.metersphere.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.LoadTestReportLog; +import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.commons.constants.ResourceStatusEnum; +import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.dto.*; import io.metersphere.request.resourcepool.QueryResourcePoolRequest; 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.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -17,7 +21,9 @@ import org.springframework.web.bind.annotation.RestController; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; + import java.util.List; +import java.util.Map; @RestController @RequestMapping("share") @@ -171,7 +177,29 @@ public class ShareController { public List getTestResourcePools() { QueryResourcePoolRequest resourcePoolRequest = new QueryResourcePoolRequest(); resourcePoolRequest.setStatus(ResourceStatusEnum.VALID.name()); - return baseTestResourcePoolService.listResourcePools(resourcePoolRequest); + // 数据脱敏 + // 仅对k8s操作 + List 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; } }