refactor(接口测试): 去掉本地执行,统一使用资源池执行
--story=1012025 --user=王孝刚 彻底去除本地执行,统一放到资源池执行,解决安全隐患 https://www.tapd.cn/55049933/s/1371917
This commit is contained in:
parent
3a0a2a0f97
commit
08096bf044
|
@ -56,7 +56,7 @@
|
|||
style="width: 100%" />
|
||||
</div>
|
||||
<div class="mode-row">
|
||||
<el-checkbox v-model="runConfig.runWithinResourcePool" :disabled="runMode === 'POOL'">
|
||||
<el-checkbox v-model="runConfig.runWithinResourcePool" :disabled="true">
|
||||
{{ $t('run_mode.run_with_resource_pool') }} </el-checkbox
|
||||
><br />
|
||||
<el-select
|
||||
|
@ -106,7 +106,6 @@ export default {
|
|||
components: { MsDialogFooter, EnvSelectPopover },
|
||||
data() {
|
||||
return {
|
||||
runMode: '',
|
||||
loading: false,
|
||||
runModeVisible: false,
|
||||
testType: null,
|
||||
|
@ -154,7 +153,6 @@ export default {
|
|||
this.runModeVisible = true;
|
||||
this.getResourcePools();
|
||||
this.getWsProjects();
|
||||
this.query();
|
||||
this.showPopover();
|
||||
this.runConfig.environmentType = ENV_TYPE.JSON;
|
||||
},
|
||||
|
@ -198,29 +196,19 @@ export default {
|
|||
getResourcePools() {
|
||||
this.result = getTestResourcePools().then((response) => {
|
||||
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) {
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
</div>
|
||||
<div class="ms-mode-div">
|
||||
<span class="ms-mode-span">{{ $t('run_mode.other_config') }}:</span>
|
||||
<el-checkbox v-model="runConfig.runWithinResourcePool" :disabled="runMode === 'POOL'">
|
||||
<el-checkbox v-model="runConfig.runWithinResourcePool" :disabled="true">
|
||||
{{ $t('run_mode.run_with_resource_pool') }}
|
||||
</el-checkbox>
|
||||
<el-select
|
||||
|
@ -168,7 +168,6 @@ export default {
|
|||
}
|
||||
};
|
||||
return {
|
||||
runMode: '',
|
||||
loading: false,
|
||||
scheduleReceiverOptions: [],
|
||||
operation: true,
|
||||
|
@ -206,27 +205,15 @@ export default {
|
|||
};
|
||||
},
|
||||
methods: {
|
||||
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;
|
||||
}
|
||||
});
|
||||
},
|
||||
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() {
|
||||
|
|
|
@ -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<TestResourcePoolDTO> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<TestResourcePoolDTO> list, String projectId) {
|
||||
public String filterQuota(List<TestResourcePoolDTO> list, String projectId) {
|
||||
Set<String> pools = baseQuotaService.getQuotaResourcePools(projectId);
|
||||
List<TestResourcePoolDTO> 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<TestResourcePoolDTO> 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<TestResourcePoolDTO> 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<TestResourcePoolDTO> poolList = getTestResourcePool();
|
||||
if (CollectionUtils.isNotEmpty(poolList) && size > 0) {
|
||||
batchSaveProjectApp(poolList, size);
|
||||
}
|
||||
}
|
||||
// 去掉路径最后的 /
|
||||
param.setParamValue(StringUtils.removeEnd(param.getParamValue(), "/"));
|
||||
if (StringUtils.equals(param.getParamKey(), "base.url")) {
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
|
||||
<!-- 接口测试资源池 -->
|
||||
<app-manage-item :title="$t('pj.api_run_pool_title')" :prepend-span="8" :middle-span="12"
|
||||
:append-span="4" v-if="isPool">
|
||||
:append-span="4">
|
||||
<template #middle>
|
||||
<el-select v-model="config.resourcePoolId"
|
||||
size="mini"
|
||||
|
@ -418,7 +418,6 @@ export default {
|
|||
},
|
||||
created() {
|
||||
this.init();
|
||||
this.getBase();
|
||||
this.getResourcePools();
|
||||
this.isXpack = !!hasLicense();
|
||||
},
|
||||
|
@ -428,11 +427,6 @@ export default {
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
getBase() {
|
||||
this.result = getSystemBaseSetting().then(response => {
|
||||
this.isPool = response.data.runMode === 'POOL';
|
||||
})
|
||||
},
|
||||
getResourcePools() {
|
||||
this.result = getTestResourcePools().then(response => {
|
||||
this.resourcePools = response.data;
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
<el-form-item :label="$t('commons.help_documentation')" prop="docUrl">
|
||||
<el-input v-model="formInline.docUrl" placeholder="https://metersphere.io/docs/index.html"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('system.api_default_run')" prop="runMode">
|
||||
<el-switch active-value="LOCAL" inactive-value="POOL" v-model="formInline.runMode" @change="modeChange"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
@ -95,20 +92,6 @@ export default {
|
|||
})
|
||||
});
|
||||
},
|
||||
modeChange(v){
|
||||
if(v === 'POOL'){
|
||||
this.formInline.runMode = 'LOCAL';
|
||||
this.$alert(this.$t('system.api_default_run_message'), '', {
|
||||
confirmButtonText: this.$t('commons.confirm'),
|
||||
cancelButtonText: this.$t('commons.cancel'),
|
||||
callback: (action) => {
|
||||
if (action === 'confirm') {
|
||||
this.formInline.runMode = v;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
edit() {
|
||||
this.showEdit = false;
|
||||
this.showSave = true;
|
||||
|
@ -129,8 +112,7 @@ export default {
|
|||
{paramKey: "base.concurrency", paramValue: this.formInline.concurrency, type: "text", sort: 2},
|
||||
{paramKey: "base.prometheus.host", paramValue: this.formInline.prometheusHost, type: "text", sort: 1},
|
||||
{paramKey: "base.selenium.docker.url", paramValue: this.formInline.seleniumDockerUrl, type: "text", sort: 1},
|
||||
{paramKey: "base.doc.url", paramValue: this.formInline.docUrl, type: "text", sort: 1},
|
||||
{paramKey: "base.run.mode", paramValue: this.formInline.runMode, type: "text", sort: 5}
|
||||
{paramKey: "base.doc.url", paramValue: this.formInline.docUrl, type: "text", sort: 1}
|
||||
];
|
||||
this.loading = saveSystemBaseSetting(param).then(res => {
|
||||
if (res.success) {
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
v-model="runConfig.runWithinResourcePool"
|
||||
style="padding-right: 10px"
|
||||
class="radio-change"
|
||||
:disabled="runMode === 'POOL'"
|
||||
:disabled="true"
|
||||
>
|
||||
{{ $t("run_mode.run_with_resource_pool") }} </el-checkbox
|
||||
><br />
|
||||
|
@ -104,7 +104,7 @@
|
|||
v-model="runConfig.runWithinResourcePool"
|
||||
style="padding-right: 10px"
|
||||
class="radio-change"
|
||||
:disabled="runMode === 'POOL'"
|
||||
:disabled="true"
|
||||
>
|
||||
{{ $t("run_mode.run_with_resource_pool") }} </el-checkbox
|
||||
><br />
|
||||
|
@ -241,7 +241,6 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
runMode: "",
|
||||
btnStyle: {
|
||||
width: "260px",
|
||||
},
|
||||
|
@ -329,29 +328,16 @@ export default {
|
|||
this.getResourcePools();
|
||||
this.getWsProjects();
|
||||
this.showPopover();
|
||||
this.query();
|
||||
},
|
||||
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;
|
||||
}
|
||||
});
|
||||
},
|
||||
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;
|
||||
});
|
||||
},
|
||||
changeMode() {
|
||||
|
@ -380,6 +366,8 @@ export default {
|
|||
getResourcePools() {
|
||||
getQuotaValidResourcePools().then((response) => {
|
||||
this.resourcePools = response.data;
|
||||
this.runConfig.runWithinResourcePool = true;
|
||||
this.getProjectApplication();
|
||||
});
|
||||
},
|
||||
setDefaultEnv(projectId, envId) {
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
<el-checkbox
|
||||
v-model="runConfig.runWithinResourcePool"
|
||||
style="padding-right: 10px"
|
||||
:disabled="runMode === 'POOL'"
|
||||
:disabled="true"
|
||||
>
|
||||
{{ $t("run_mode.run_with_resource_pool") }}
|
||||
</el-checkbox>
|
||||
|
@ -151,7 +151,7 @@
|
|||
<el-checkbox
|
||||
v-model="runConfig.runWithinResourcePool"
|
||||
style="padding-right: 10px"
|
||||
:disabled="runMode === 'POOL'"
|
||||
:disabled="true"
|
||||
>
|
||||
{{ $t("run_mode.run_with_resource_pool") }}
|
||||
</el-checkbox>
|
||||
|
@ -350,7 +350,6 @@ export default {
|
|||
}
|
||||
};
|
||||
return {
|
||||
runMode: "",
|
||||
result: {},
|
||||
scheduleReceiverOptions: [],
|
||||
operation: true,
|
||||
|
@ -400,27 +399,15 @@ export default {
|
|||
};
|
||||
},
|
||||
methods: {
|
||||
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;
|
||||
}
|
||||
});
|
||||
},
|
||||
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: () => {
|
||||
|
@ -451,7 +438,6 @@ export default {
|
|||
return param;
|
||||
},
|
||||
open(row) {
|
||||
this.query();
|
||||
this.planId = row.id;
|
||||
//测试计划页面跳转来的
|
||||
let paramTestId = row.id;
|
||||
|
@ -612,6 +598,8 @@ export default {
|
|||
getResourcePools() {
|
||||
this.result = getQuotaValidResourcePools().then((response) => {
|
||||
this.resourcePools = response.data;
|
||||
this.runConfig.runWithinResourcePool = true;
|
||||
this.getProjectApplication();
|
||||
});
|
||||
},
|
||||
changeMode() {
|
||||
|
|
Loading…
Reference in New Issue