From 08096bf044ef1d3a2139c8bcb9c5d03b49e14b2f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 16 May 2023 15:43:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=8E=BB=E6=8E=89=E6=9C=AC=E5=9C=B0=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=B1=A0=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1012025 --user=王孝刚 彻底去除本地执行,统一放到资源池执行,解决安全隐患 https://www.tapd.cn/55049933/s/1371917 --- .../automation/scenario/common/ApiRunMode.vue | 28 ++++--------- .../automation/schedule/ScheduleMaintain.vue | 28 ++++--------- .../service/ApiPoolDebugService.java | 20 +++++---- .../service/SystemParameterService.java | 41 +++++++------------ .../src/business/menu/appmanage/AppManage.vue | 8 +--- .../business/system/setting/BaseSetting.vue | 20 +-------- .../plan/common/TestPlanRunModeWithEnv.vue | 30 ++++---------- .../plan/components/ScheduleMaintain.vue | 30 ++++---------- 8 files changed, 63 insertions(+), 142 deletions(-) diff --git a/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue b/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue index 8051b42df1..c0b471e7c7 100644 --- a/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue +++ b/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue @@ -56,7 +56,7 @@ style="width: 100%" />
- + {{ $t('run_mode.run_with_resource_pool') }}
{ this.resourcePools = response.data; - }); - }, - query() { - this.loading = true; - this.result = getSystemBaseSetting().then((response) => { - if (!response.data.runMode) { - response.data.runMode = 'LOCAL'; - } - this.runMode = response.data.runMode; - if (this.runMode === 'POOL') { - this.runConfig.runWithinResourcePool = true; - this.getProjectApplication(); - } else { - this.loading = false; - } + this.runConfig.runWithinResourcePool = true; + this.getProjectApplication(); }); }, getProjectApplication() { getProjectConfig(getCurrentProjectID(), '').then((res) => { if (res.data && res.data.poolEnable && res.data.resourcePoolId) { - this.runConfig.resourcePoolId = res.data.resourcePoolId; + this.resourcePools.forEach(item => { + if (item.id === res.data.resourcePoolId) { + this.runConfig.resourcePoolId = res.data.resourcePoolId; + } + }); } - this.loading = false; }); }, setEnvGroup(id) { diff --git a/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue b/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue index 930a9fca88..8b717e289d 100644 --- a/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue +++ b/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue @@ -68,7 +68,7 @@
{{ $t('run_mode.other_config') }}: - + {{ $t('run_mode.run_with_resource_pool') }} { - if (!response.data.runMode) { - response.data.runMode = 'LOCAL'; - } - this.runMode = response.data.runMode; - if (this.runMode === 'POOL') { - this.runConfig.runWithinResourcePool = true; - this.getProjectApplication(); - } else { - this.loading = false; - } - }); - }, getProjectApplication() { getProjectConfig(getCurrentProjectID(), '').then((res) => { if (res.data && res.data.poolEnable && res.data.resourcePoolId) { - this.runConfig.resourcePoolId = res.data.resourcePoolId; + this.resourcePools.forEach(item => { + if (item.id === res.data.resourcePoolId) { + this.runConfig.resourcePoolId = res.data.resourcePoolId; + } + }); } - this.loading = false; }); }, currentUser: () => { @@ -268,6 +255,8 @@ export default { getResourcePools() { this.result = getTestResourcePools().then((response) => { this.resourcePools = response.data; + this.runConfig.runWithinResourcePool = true; + this.getProjectApplication(); }); }, updateTask(param) { @@ -321,7 +310,6 @@ export default { this.activeName = 'first'; this.getResourcePools(); this.getWsProjects(); - this.query(); this.runConfig.environmentType = ENV_TYPE.JSON; }, findSchedule() { diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ApiPoolDebugService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ApiPoolDebugService.java index c891b70818..0b595c55f6 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ApiPoolDebugService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ApiPoolDebugService.java @@ -6,13 +6,14 @@ import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.JSON; import io.metersphere.dto.*; import io.metersphere.utils.LoggerUtil; +import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import jakarta.annotation.Resource; import java.util.List; +import java.util.stream.Collectors; @Service public class ApiPoolDebugService { @@ -66,16 +67,21 @@ public class ApiPoolDebugService { */ public void verifyPool(String projectId, RunModeConfigDTO runConfig) { if (runConfig != null && StringUtils.isEmpty(runConfig.getResourcePoolId())) { - BaseSystemConfigDTO configDTO = systemParameterService.getBaseInfo(); LoggerUtil.info("校验项目为:【" + projectId + "】", runConfig.getReportId()); - if (StringUtils.equals(configDTO.getRunMode(), POOL)) { - ProjectConfig config = baseProjectApplicationService.getProjectConfig(projectId); - if (config == null || !config.getPoolEnable() || StringUtils.isEmpty(config.getResourcePoolId())) { + ProjectConfig config = baseProjectApplicationService.getProjectConfig(projectId); + List poolList = systemParameterService.getTestResourcePool(); + boolean contains = poolList.stream().map(TestResourcePoolDTO::getId).collect(Collectors.toList()).contains(config.getResourcePoolId()); + + if (StringUtils.isEmpty(config.getResourcePoolId()) || !contains) { + String id = systemParameterService.filterQuota(poolList, projectId); + if (StringUtils.isBlank(id)) { MSException.throwException("请在【项目设置-应用管理-接口测试】中选择资源池"); + } else { + config.setResourcePoolId(id); } - runConfig = runConfig == null ? new RunModeConfigDTO() : runConfig; - runConfig.setResourcePoolId(config.getResourcePoolId()); } + runConfig = runConfig == null ? new RunModeConfigDTO() : runConfig; + runConfig.setResourcePoolId(config.getResourcePoolId()); } } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java index 684a172f33..6f004828ae 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/SystemParameterService.java @@ -24,8 +24,6 @@ import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.system.SystemReference; import io.metersphere.notice.domain.MailInfo; -import io.metersphere.notice.domain.Receiver; -import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.sender.impl.MailNoticeSender; import io.metersphere.quota.service.BaseQuotaService; import io.metersphere.request.HeaderRequest; @@ -309,7 +307,7 @@ public class SystemParameterService { return baseTestResourcePoolService.listResourcePools(resourcePoolRequest); } - private String filterQuota(List list, String projectId) { + public String filterQuota(List list, String projectId) { Set pools = baseQuotaService.getQuotaResourcePools(projectId); List poolList = new ArrayList<>(); if (!pools.isEmpty()) { @@ -366,23 +364,20 @@ public class SystemParameterService { } public void saveProjectApplication(String projectId) { - BaseSystemConfigDTO config = getBaseInfo(); - if (config != null && StringUtils.equals(config.getRunMode(), "POOL")) { - List poolList = getTestResourcePool(); - String id = filterQuota(poolList, projectId); - if (StringUtils.isNotBlank(id)) { - ProjectApplication applicationValue = new ProjectApplication(); - applicationValue.setProjectId(projectId); - applicationValue.setType(ProjectApplicationType.RESOURCE_POOL_ID.name()); - applicationValue.setTypeValue(id); - projectApplicationMapper.insert(applicationValue); + List poolList = getTestResourcePool(); + String id = filterQuota(poolList, projectId); + if (StringUtils.isNotBlank(id)) { + ProjectApplication applicationValue = new ProjectApplication(); + applicationValue.setProjectId(projectId); + applicationValue.setType(ProjectApplicationType.RESOURCE_POOL_ID.name()); + applicationValue.setTypeValue(id); + projectApplicationMapper.insert(applicationValue); - ProjectApplication application = new ProjectApplication(); - application.setProjectId(projectId); - application.setType(ProjectApplicationType.POOL_ENABLE.name()); - application.setTypeValue(String.valueOf(true)); - projectApplicationMapper.insert(application); - } + ProjectApplication application = new ProjectApplication(); + application.setProjectId(projectId); + application.setType(ProjectApplicationType.POOL_ENABLE.name()); + application.setTypeValue(String.valueOf(true)); + projectApplicationMapper.insert(application); } } @@ -403,14 +398,6 @@ public class SystemParameterService { } } } - // 启用资源池 - if (param.getParamKey().equals("base.run.mode") && param.getParamValue().equals("POOL")) { - long size = baseProjectService.count(); - List poolList = getTestResourcePool(); - if (CollectionUtils.isNotEmpty(poolList) && size > 0) { - batchSaveProjectApp(poolList, size); - } - } // 去掉路径最后的 / param.setParamValue(StringUtils.removeEnd(param.getParamValue(), "/")); if (StringUtils.equals(param.getParamKey(), "base.url")) { diff --git a/project-management/frontend/src/business/menu/appmanage/AppManage.vue b/project-management/frontend/src/business/menu/appmanage/AppManage.vue index f58738a58d..8dc4834e6a 100644 --- a/project-management/frontend/src/business/menu/appmanage/AppManage.vue +++ b/project-management/frontend/src/business/menu/appmanage/AppManage.vue @@ -107,7 +107,7 @@ + :append-span="4">