chore: 文件处理统一迁移sdk

This commit is contained in:
fit2-zhao 2023-12-14 11:43:34 +08:00 committed by Craftsman
parent 59c6581165
commit d9b5bcb02e
37 changed files with 210 additions and 93 deletions

View File

@ -2,9 +2,13 @@ package io.metersphere.listener;
import io.metersphere.api.event.ApiEventSource; import io.metersphere.api.event.ApiEventSource;
import io.metersphere.plan.listener.ExecEventListener; import io.metersphere.plan.listener.ExecEventListener;
import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.service.PluginLoadService; import io.metersphere.system.service.PluginLoadService;
import io.minio.MinioClient;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
@ -15,10 +19,15 @@ public class AppStartListener implements ApplicationRunner {
@Resource @Resource
private PluginLoadService pluginLoadService; private PluginLoadService pluginLoadService;
@Resource
private MinioClient minioClient;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
LogUtils.info("================= 应用启动 ================="); LogUtils.info("================= 应用启动 =================");
// 初始化MinIO配置
((MinioRepository) FileCenter.getRepository(StorageType.MINIO)).init(minioClient);
// 注册所有监听源 // 注册所有监听源
LogUtils.info("初始化接口事件源"); LogUtils.info("初始化接口事件源");
ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class); ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class);

View File

@ -217,6 +217,14 @@
<artifactId>otp-java</artifactId> <artifactId>otp-java</artifactId>
<version>${otp-java.version}</version> <version>${otp-java.version}</version>
</dependency> </dependency>
<!-- jgit -->
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>${jgit.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -0,0 +1,18 @@
package io.metersphere.sdk.dto;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class FileMetadataRepositoryDTO implements Serializable {
private String fileMetadataId;
private String branch;
private String commitId;
private String commitMessage;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,22 @@
package io.metersphere.sdk.dto;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class FileModuleRepositoryDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String fileModuleId;
private String platform;
private String url;
private String token;
private String userName;
}

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto.sdk; package io.metersphere.sdk.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto; package io.metersphere.sdk.dto;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.file; package io.metersphere.sdk.file;
import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
@ -7,15 +7,16 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class FileCenter { public class FileCenter {
private FileCenter() {
}
public static FileRepository getRepository(StorageType storageType) { public static FileRepository getRepository(StorageType storageType) {
Map<StorageType, FileRepository> repositoryMap = new HashMap<>() {{ return switch (storageType) {
put(StorageType.MINIO, CommonBeanFactory.getBean(MinioRepository.class)); case MINIO -> CommonBeanFactory.getBean(MinioRepository.class);
put(StorageType.LOCAL, CommonBeanFactory.getBean(LocalFileRepository.class)); case LOCAL -> CommonBeanFactory.getBean(LocalFileRepository.class);
put(StorageType.GIT, CommonBeanFactory.getBean(GitRepository.class)); case GIT -> CommonBeanFactory.getBean(GitRepository.class);
}}; default -> getDefaultRepository();
FileRepository fileRepository = repositoryMap.get(storageType); };
return fileRepository == null ? getDefaultRepository() : fileRepository;
} }
public static FileRepository getRepository(String storage) { public static FileRepository getRepository(String storage) {

View File

@ -1,4 +1,4 @@
package io.metersphere.system.file; package io.metersphere.sdk.file;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.file; package io.metersphere.sdk.file;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

View File

@ -1,7 +1,7 @@
package io.metersphere.system.file; package io.metersphere.sdk.file;
import io.metersphere.project.domain.FileMetadataRepository; import io.metersphere.sdk.dto.FileMetadataRepositoryDTO;
import io.metersphere.project.domain.FileModuleRepository; import io.metersphere.sdk.dto.FileModuleRepositoryDTO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -19,7 +19,7 @@ public class FileRequest {
//Git文件信息 //Git文件信息
private GitFileRequest gitFileRequest; private GitFileRequest gitFileRequest;
public void setGitFileRequest(FileModuleRepository repository, FileMetadataRepository file) { public void setGitFileRequest(FileModuleRepositoryDTO repository, FileMetadataRepositoryDTO file) {
gitFileRequest = new GitFileRequest(repository.getUrl(), repository.getToken(), repository.getUserName(), file.getBranch(), file.getCommitId()); gitFileRequest = new GitFileRequest(repository.getUrl(), repository.getToken(), repository.getUserName(), file.getBranch(), file.getCommitId());
} }
} }

View File

@ -1,7 +1,7 @@
package io.metersphere.system.file; package io.metersphere.sdk.file;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.utils.GitRepositoryUtil; import io.metersphere.sdk.util.GitRepositoryUtil;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.file; package io.metersphere.sdk.file;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.MsFileUtils; import io.metersphere.sdk.util.MsFileUtils;

View File

@ -1,10 +1,11 @@
package io.metersphere.system.file; package io.metersphere.sdk.file;
import io.metersphere.plugin.sdk.util.PluginUtils;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.config.MinioConfig; import io.metersphere.sdk.util.LogUtils;
import io.minio.*; import io.minio.*;
import io.minio.messages.Item; import io.minio.messages.Item;
import jakarta.annotation.Resource; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -15,14 +16,57 @@ import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@Component @Component
public class MinioRepository implements FileRepository { public class MinioRepository implements FileRepository {
@Resource
private MinioClient client; private MinioClient client;
// 缓冲区大小 // 缓冲区大小
private static final int BUFFER_SIZE = 8192; private static final int BUFFER_SIZE = 8192;
public static final String BUCKET = "metersphere";
public static final String ENDPOINT = "endpoint";
public static final String ACCESS_KEY = "accessKey";
public static final String SECRET_KEY = "secretKey";
/**
* 初始化
*/
public void init(MinioClient client) {
if (this.client == null) {
this.client = client;
}
}
/**
* 根据配置信息动态创建
*/
public void init(Map<String, Object> minioConfig) {
if (minioConfig == null || minioConfig.isEmpty()) {
LogUtils.info("MinIO初始化失败参数[minioConfig]为空");
return;
}
try {
Object serverUrl = minioConfig.get(ENDPOINT).toString();
if (ObjectUtils.isNotEmpty(serverUrl)) {
LogUtils.info("开始初始化MinIO插件。配置", PluginUtils.toJSONString(minioConfig));
// 创建 MinioClient 客户端
client = MinioClient.builder()
.endpoint(minioConfig.get(ENDPOINT).toString())
.credentials(minioConfig.get(ACCESS_KEY).toString(), minioConfig.get(SECRET_KEY).toString())
.build();
boolean exist = client.bucketExists(BucketExistsArgs.builder().bucket(BUCKET).build());
if (!exist) {
client.makeBucket(MakeBucketArgs.builder().bucket(BUCKET).build());
}
LogUtils.info("初始化MinIO成功");
}
} catch (Exception e) {
LogUtils.error("MinIOClient初始化失败", e);
}
}
private String getPath(FileRequest request) { private String getPath(FileRequest request) {
String folder = request.getFolder(); String folder = request.getFolder();
@ -37,7 +81,7 @@ public class MinioRepository implements FileRepository {
// 文件存储路径 // 文件存储路径
String filePath = getPath(request); String filePath = getPath(request);
client.putObject(PutObjectArgs.builder() client.putObject(PutObjectArgs.builder()
.bucket(MinioConfig.BUCKET) .bucket(BUCKET)
.object(filePath) .object(filePath)
.stream(file.getInputStream(), file.getSize(), -1) // 文件内容 .stream(file.getInputStream(), file.getSize(), -1) // 文件内容
.build()); .build());
@ -49,7 +93,7 @@ public class MinioRepository implements FileRepository {
String filePath = getPath(request); String filePath = getPath(request);
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) {
client.putObject(PutObjectArgs.builder() client.putObject(PutObjectArgs.builder()
.bucket(MinioConfig.BUCKET) .bucket(BUCKET)
.object(filePath) .object(filePath)
.stream(inputStream, bytes.length, -1) .stream(inputStream, bytes.length, -1)
.build()); .build());
@ -66,19 +110,19 @@ public class MinioRepository implements FileRepository {
public void delete(FileRequest request) throws Exception { public void delete(FileRequest request) throws Exception {
String filePath = getPath(request); String filePath = getPath(request);
// 删除单个文件 // 删除单个文件
removeObject(MinioConfig.BUCKET, filePath); removeObject(BUCKET, filePath);
} }
@Override @Override
public void deleteFolder(FileRequest request) throws Exception { public void deleteFolder(FileRequest request) throws Exception {
String filePath = getPath(request); String filePath = getPath(request);
// 删除文件夹 // 删除文件夹
removeObjects(MinioConfig.BUCKET, filePath); removeObjects(BUCKET, filePath);
} }
@Override @Override
public List<String> getFolderFileNames(FileRequest request) throws Exception { public List<String> getFolderFileNames(FileRequest request) throws Exception {
return listObjects(MinioConfig.BUCKET, getPath(request)); return listObjects(BUCKET, getPath(request));
} }
@Override @Override
@ -86,10 +130,10 @@ public class MinioRepository implements FileRepository {
String sourcePath = StringUtils.join(request.getCopyFolder(), "/", request.getCopyfileName()); String sourcePath = StringUtils.join(request.getCopyFolder(), "/", request.getCopyfileName());
String targetPath = getPath(request); String targetPath = getPath(request);
client.copyObject(CopyObjectArgs.builder() client.copyObject(CopyObjectArgs.builder()
.bucket(MinioConfig.BUCKET) .bucket(BUCKET)
.object(targetPath) .object(targetPath)
.source(CopySource.builder() .source(CopySource.builder()
.bucket(MinioConfig.BUCKET) .bucket(BUCKET)
.object(sourcePath) .object(sourcePath)
.build()) .build())
.build()); .build());
@ -142,7 +186,7 @@ public class MinioRepository implements FileRepository {
// 下载对象到本地文件 // 下载对象到本地文件
try (InputStream inputStream = client.getObject( try (InputStream inputStream = client.getObject(
GetObjectArgs.builder() GetObjectArgs.builder()
.bucket(MinioConfig.BUCKET) .bucket(BUCKET)
.object(fileName) .object(fileName)
.build()); .build());
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(fullPath))) { BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(fullPath))) {
@ -158,7 +202,7 @@ public class MinioRepository implements FileRepository {
public InputStream getFileAsStream(FileRequest request) throws Exception { public InputStream getFileAsStream(FileRequest request) throws Exception {
String fileName = getPath(request); String fileName = getPath(request);
return client.getObject(GetObjectArgs.builder() return client.getObject(GetObjectArgs.builder()
.bucket(MinioConfig.BUCKET) // 存储桶 .bucket(BUCKET) // 存储桶
.object(fileName) // 文件名 .object(fileName) // 文件名
.build()); .build());
} }

View File

@ -1,8 +1,7 @@
package io.metersphere.system.utils; package io.metersphere.sdk.util;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.dto.RemoteFileAttachInfo;
import io.metersphere.system.dto.RepositoryQuery; import io.metersphere.sdk.dto.RepositoryQuery;
import io.metersphere.system.dto.sdk.RemoteFileAttachInfo;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;

View File

@ -11,10 +11,10 @@ import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.system.file.FileCopyRequest; import io.metersphere.sdk.file.FileCopyRequest;
import io.metersphere.system.file.FileRepository; import io.metersphere.sdk.file.FileRepository;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;

View File

@ -42,8 +42,8 @@ import io.metersphere.system.domain.TestResourcePoolOrganizationExample;
import io.metersphere.system.dto.pool.TestResourceDTO; import io.metersphere.system.dto.pool.TestResourceDTO;
import io.metersphere.system.dto.pool.TestResourceNodeDTO; import io.metersphere.system.dto.pool.TestResourceNodeDTO;
import io.metersphere.system.dto.pool.TestResourcePoolDTO; import io.metersphere.system.dto.pool.TestResourcePoolDTO;
import io.metersphere.system.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.TestResourcePoolBlobMapper; import io.metersphere.system.mapper.TestResourcePoolBlobMapper;
import io.metersphere.system.mapper.TestResourcePoolMapper; import io.metersphere.system.mapper.TestResourcePoolMapper;

View File

@ -22,8 +22,8 @@ import io.metersphere.sdk.util.*;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.sdk.BaseCondition; import io.metersphere.system.dto.sdk.BaseCondition;
import io.metersphere.system.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;

View File

@ -26,9 +26,9 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.uid.NumGenerator;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;

View File

@ -26,7 +26,7 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.Template; import io.metersphere.system.domain.Template;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.sdk.TemplateDTO; import io.metersphere.system.dto.sdk.TemplateDTO;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.mapper.BaseUserMapper;
import io.metersphere.system.mapper.TemplateMapper; import io.metersphere.system.mapper.TemplateMapper;

View File

@ -20,7 +20,7 @@ import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.FileAssociationSourceUtil; import io.metersphere.sdk.util.FileAssociationSourceUtil;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;

View File

@ -15,7 +15,7 @@ import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;

View File

@ -21,8 +21,8 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.sdk.BaseSystemConfigDTO; import io.metersphere.system.dto.sdk.BaseSystemConfigDTO;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;

View File

@ -8,7 +8,7 @@ import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.TempFileUtils; import io.metersphere.sdk.util.TempFileUtils;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -17,18 +17,16 @@ import io.metersphere.project.utils.FileMetadataUtils;
import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.dto.FileMetadataRepositoryDTO;
import io.metersphere.sdk.dto.FileModuleRepositoryDTO;
import io.metersphere.sdk.dto.RemoteFileAttachInfo;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.file.FileRepository;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.util.TempFileUtils; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.*;
import io.metersphere.system.dto.sdk.RemoteFileAttachInfo;
import io.metersphere.system.file.FileRepository;
import io.metersphere.system.file.FileRequest;
import io.metersphere.system.file.MinioRepository;
import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.mapper.BaseUserMapper;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.GitRepositoryUtil;
import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -346,7 +344,12 @@ public class FileMetadataService {
if (StringUtils.equals(fileMetadata.getStorage(), StorageType.GIT.name())) { if (StringUtils.equals(fileMetadata.getStorage(), StorageType.GIT.name())) {
FileModuleRepository fileModuleRepository = fileModuleRepositoryMapper.selectByPrimaryKey(fileMetadata.getModuleId()); FileModuleRepository fileModuleRepository = fileModuleRepositoryMapper.selectByPrimaryKey(fileMetadata.getModuleId());
FileMetadataRepository fileMetadataRepository = fileMetadataRepositoryMapper.selectByPrimaryKey(fileMetadata.getId()); FileMetadataRepository fileMetadataRepository = fileMetadataRepositoryMapper.selectByPrimaryKey(fileMetadata.getId());
fileRequest.setGitFileRequest(fileModuleRepository, fileMetadataRepository);
FileModuleRepositoryDTO repositoryDTO = new FileModuleRepositoryDTO();
BeanUtils.copyBean(repositoryDTO, fileModuleRepository);
FileMetadataRepositoryDTO metadataRepositoryDTO = new FileMetadataRepositoryDTO();
BeanUtils.copyBean(metadataRepositoryDTO, fileMetadataRepository);
fileRequest.setGitFileRequest(repositoryDTO, metadataRepositoryDTO);
} }
return fileService.download(fileRequest); return fileService.download(fileRequest);
@ -432,6 +435,7 @@ public class FileMetadataService {
throw new MSException(Translator.get("file.size.is.too.large")); throw new MSException(Translator.get("file.size.is.too.large"));
} }
} }
private static final String FILE_MODULE_COUNT_MY = "my"; private static final String FILE_MODULE_COUNT_MY = "my";
/** /**

View File

@ -18,9 +18,9 @@ import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.RemoteFileAttachInfo; import io.metersphere.sdk.dto.RemoteFileAttachInfo;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.GitRepositoryUtil; import io.metersphere.sdk.util.GitRepositoryUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;

View File

@ -1,7 +1,7 @@
package io.metersphere.project.service; package io.metersphere.project.service;
import io.metersphere.system.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

View File

@ -35,8 +35,8 @@ import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -29,7 +29,7 @@ import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.request.NodeMoveRequest; import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.service.CommonProjectService; import io.metersphere.system.service.CommonProjectService;

View File

@ -139,13 +139,6 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version> <version>${springdoc-openapi-ui.version}</version>
</dependency> </dependency>
<!-- jgit -->
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>${jgit.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -2,11 +2,14 @@ package io.metersphere.system.config;
import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.FileRepository;
import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.util.RsaKey; import io.metersphere.sdk.util.RsaKey;
import io.metersphere.sdk.util.RsaUtils; import io.metersphere.sdk.util.RsaUtils;
import io.metersphere.system.file.FileCenter; import io.minio.MinioClient;
import io.metersphere.system.file.FileRepository; import jakarta.annotation.Resource;
import io.metersphere.system.file.FileRequest;
import org.apache.commons.lang3.SerializationUtils; import org.apache.commons.lang3.SerializationUtils;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
@ -14,6 +17,8 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class RsaConfig implements ApplicationRunner { public class RsaConfig implements ApplicationRunner {
@Resource
private MinioClient client;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
@ -21,6 +26,8 @@ public class RsaConfig implements ApplicationRunner {
request.setFileName("rsa.key"); request.setFileName("rsa.key");
request.setFolder(DefaultRepositoryDir.getSystemRootDir()); request.setFolder(DefaultRepositoryDir.getSystemRootDir());
FileRepository fileRepository = FileCenter.getDefaultRepository(); FileRepository fileRepository = FileCenter.getDefaultRepository();
// 初始化MinIO配置
((MinioRepository) fileRepository).init(client);
try { try {
byte[] file = fileRepository.getFile(request); byte[] file = fileRepository.getFile(request);

View File

@ -3,8 +3,8 @@ package io.metersphere.system.service;
import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.domain.SystemParameter; import io.metersphere.system.domain.SystemParameter;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.system.mapper.SystemParameterMapper; import io.metersphere.system.mapper.SystemParameterMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;

View File

@ -6,8 +6,8 @@ import io.metersphere.sdk.constants.LocalRepositoryDir;
import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.constants.StorageType;
import io.metersphere.system.controller.handler.result.CommonResultCode; import io.metersphere.system.controller.handler.result.CommonResultCode;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.plugin.MsPluginManager; import io.metersphere.sdk.plugin.MsPluginManager;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;

View File

@ -2,10 +2,13 @@ package io.metersphere.system.base;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.constants.UserRoleType;
import io.metersphere.sdk.domain.OperationLogExample; import io.metersphere.sdk.domain.OperationLogExample;
import io.metersphere.sdk.exception.IResultCode; import io.metersphere.sdk.exception.IResultCode;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.mapper.OperationLogMapper; import io.metersphere.sdk.mapper.OperationLogMapper;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.param.InvalidateParamInfo; import io.metersphere.system.base.param.InvalidateParamInfo;
@ -20,6 +23,7 @@ import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated; import io.metersphere.validation.groups.Updated;
import io.minio.MinioClient;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -79,6 +83,8 @@ public abstract class BaseTest {
private UserMapper userMapper; private UserMapper userMapper;
@Resource @Resource
private MockServerClient mockServerClient; private MockServerClient mockServerClient;
@Resource
private MinioClient client;
protected static final String DEFAULT_LIST = "list"; protected static final String DEFAULT_LIST = "list";
protected static final String DEFAULT_GET = "get/{0}"; protected static final String DEFAULT_GET = "get/{0}";
@ -103,6 +109,9 @@ public abstract class BaseTest {
this.sessionId = this.adminAuthInfo.getSessionId(); this.sessionId = this.adminAuthInfo.getSessionId();
this.csrfToken = this.adminAuthInfo.getCsrfToken(); this.csrfToken = this.adminAuthInfo.getCsrfToken();
} }
// 初始化MinIO配置
((MinioRepository) FileCenter.getRepository(StorageType.MINIO)).init(client);
if (permissionAuthInfoMap.isEmpty()) { if (permissionAuthInfoMap.isEmpty()) {
// 获取系统组织项目对应的权限测试用户的认证信息 // 获取系统组织项目对应的权限测试用户的认证信息
List<String> permissionUserNames = Arrays.asList(UserRoleType.SYSTEM.name(), UserRoleType.ORGANIZATION.name(), UserRoleType.PROJECT.name()); List<String> permissionUserNames = Arrays.asList(UserRoleType.SYSTEM.name(), UserRoleType.ORGANIZATION.name(), UserRoleType.PROJECT.name());
@ -239,6 +248,7 @@ public abstract class BaseTest {
/** /**
* 设置 mock get 接口 * 设置 mock get 接口
*
* @param path * @param path
* @param mockBody * @param mockBody
*/ */
@ -258,6 +268,7 @@ public abstract class BaseTest {
/** /**
* 设置 mock post 接口 * 设置 mock post 接口
*
* @param path * @param path
* @param mockBody * @param mockBody
*/ */

View File

@ -3,8 +3,8 @@ package io.metersphere.system.controller;
import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.MethodOrderer;

View File

@ -1,5 +1,6 @@
package io.metersphere.system.controller; package io.metersphere.system.controller;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.invoker.ProjectServiceInvoker; import io.metersphere.system.invoker.ProjectServiceInvoker;
import io.metersphere.system.mock.CleanupTestResourceService; import io.metersphere.system.mock.CleanupTestResourceService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -15,7 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc @AutoConfigureMockMvc
public class CleanupResourceTests { public class CleanupResourceTests extends BaseTest {
private final ProjectServiceInvoker serviceInvoker; private final ProjectServiceInvoker serviceInvoker;
@Resource @Resource
private CleanupTestResourceService cleanupTestResourceService; private CleanupTestResourceService cleanupTestResourceService;

View File

@ -1,9 +1,9 @@
package io.metersphere.system.controller; package io.metersphere.system.controller;
import io.metersphere.system.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.system.file.FileRepository; import io.metersphere.sdk.file.FileRepository;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;

View File

@ -12,8 +12,8 @@ import io.metersphere.system.domain.*;
import io.metersphere.system.dto.OrganizationDTO; import io.metersphere.system.dto.OrganizationDTO;
import io.metersphere.system.dto.PluginDTO; import io.metersphere.system.dto.PluginDTO;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.system.file.LocalFileRepository; import io.metersphere.sdk.file.LocalFileRepository;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.PluginMapper; import io.metersphere.system.mapper.PluginMapper;
import io.metersphere.system.mapper.PluginOrganizationMapper; import io.metersphere.system.mapper.PluginOrganizationMapper;