refactor(项目管理): 配置三方平台key校验

This commit is contained in:
WangXu10 2024-02-01 20:53:26 +08:00 committed by 刘瑞斌
parent cf40902d99
commit 89e3ce9266
3 changed files with 25 additions and 11 deletions

View File

@ -309,7 +309,7 @@ public class ProjectApplicationController {
@PostMapping("/validate/{pluginId}")
@Operation(summary = "插件key校验")
public void validateProjectConfig(@PathVariable("pluginId") String pluginId, @RequestBody Map configs) {
projectApplicationService.validateProjectConfig(pluginId, configs);
projectApplicationService.validateProjectConfig(pluginId, configs, SessionUtils.getCurrentOrganizationId());
}
}

View File

@ -19,7 +19,6 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.Plugin;
import io.metersphere.system.domain.ServiceIntegration;
import io.metersphere.system.domain.ServiceIntegrationExample;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.log.constants.OperationLogModule;
@ -442,19 +441,29 @@ public class ProjectApplicationService {
* @param pluginId
* @param configs
*/
public void validateProjectConfig(String pluginId, Map configs) {
Platform platform = this.getPlatform(pluginId);
public void validateProjectConfig(String pluginId, Map configs, String organizationId) {
Platform platform = this.getPlatform(pluginId, organizationId);
platform.validateProjectConfig(JSON.toJSONString(configs));
}
private Platform getPlatform(String pluginId) {
ServiceIntegrationExample example = new ServiceIntegrationExample();
example.createCriteria().andPluginIdEqualTo(pluginId);
List<ServiceIntegration> serviceIntegrations = serviceIntegrationMapper.selectByExampleWithBLOBs(example);
if (CollectionUtils.isEmpty(serviceIntegrations)) {
private Platform getPlatform(String pluginId, String organizationId) {
Set<String> orgPluginIds = platformPluginService.getOrgEnabledPlatformPlugins(organizationId)
.stream()
.map(Plugin::getId)
.collect(Collectors.toSet());
// 查询服务集成中启用并且支持第三方模板的插件
ServiceIntegration integration = serviceIntegrationService.getServiceIntegrationByOrgId(organizationId)
.stream()
.filter(serviceIntegration -> {
return serviceIntegration.getEnable() // 服务集成开启
&& orgPluginIds.contains(pluginId);
})
.findFirst()
.orElse(null);
if (integration == null) {
throw new MSException(NOT_FOUND);
}
return platformPluginService.getPlatform(pluginId, serviceIntegrations.get(0).getOrganizationId(), new String(serviceIntegrations.get(0).getConfiguration()));
return platformPluginService.getPlatform(pluginId, integration.getOrganizationId(), new String(integration.getConfiguration()));
}
public int getFakeErrorList(String projectId) {

View File

@ -15,6 +15,7 @@ import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.Plugin;
import io.metersphere.system.domain.ServiceIntegration;
import io.metersphere.system.domain.ServiceIntegrationExample;
import io.metersphere.system.dto.request.ServiceIntegrationUpdateRequest;
import io.metersphere.system.mapper.ServiceIntegrationMapper;
import jakarta.annotation.Resource;
@ -639,7 +640,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
request.setEnable(true);
request.setPluginId(plugin.getId());
request.setConfiguration(integrationConfigMap);
request.setOrganizationId("100001100001");
request.setOrganizationId("100001");
this.requestPostWithOkAndReturn("/service/integration/add", request);
mockServerClient
.when(
@ -660,6 +661,10 @@ public class ProjectApplicationControllerTests extends BaseTest {
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
//测试完清掉
ServiceIntegrationExample example = new ServiceIntegrationExample();
example.createCriteria().andPluginIdEqualTo(plugin.getId()).andOrganizationIdEqualTo("100001").andEnableEqualTo(true);
serviceIntegrationMapper.deleteByExample(example);
}
@Getter