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; } }