chore: 文件处理统一迁移sdk
This commit is contained in:
parent
59c6581165
commit
d9b5bcb02e
|
@ -2,9 +2,13 @@ package io.metersphere.listener;
|
|||
|
||||
import io.metersphere.api.event.ApiEventSource;
|
||||
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.LogUtils;
|
||||
import io.metersphere.system.service.PluginLoadService;
|
||||
import io.minio.MinioClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
|
@ -15,10 +19,15 @@ public class AppStartListener implements ApplicationRunner {
|
|||
|
||||
@Resource
|
||||
private PluginLoadService pluginLoadService;
|
||||
@Resource
|
||||
private MinioClient minioClient;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
LogUtils.info("================= 应用启动 =================");
|
||||
// 初始化MinIO配置
|
||||
((MinioRepository) FileCenter.getRepository(StorageType.MINIO)).init(minioClient);
|
||||
|
||||
// 注册所有监听源
|
||||
LogUtils.info("初始化接口事件源");
|
||||
ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class);
|
||||
|
|
|
@ -217,6 +217,14 @@
|
|||
<artifactId>otp-java</artifactId>
|
||||
<version>${otp-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- jgit -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jgit</groupId>
|
||||
<artifactId>org.eclipse.jgit</artifactId>
|
||||
<version>${jgit.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.system.dto.sdk;
|
||||
package io.metersphere.sdk.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.AllArgsConstructor;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.system.dto;
|
||||
package io.metersphere.sdk.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.system.file;
|
||||
package io.metersphere.sdk.file;
|
||||
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
|
@ -7,15 +7,16 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class FileCenter {
|
||||
private FileCenter() {
|
||||
}
|
||||
|
||||
public static FileRepository getRepository(StorageType storageType) {
|
||||
Map<StorageType, FileRepository> repositoryMap = new HashMap<>() {{
|
||||
put(StorageType.MINIO, CommonBeanFactory.getBean(MinioRepository.class));
|
||||
put(StorageType.LOCAL, CommonBeanFactory.getBean(LocalFileRepository.class));
|
||||
put(StorageType.GIT, CommonBeanFactory.getBean(GitRepository.class));
|
||||
}};
|
||||
FileRepository fileRepository = repositoryMap.get(storageType);
|
||||
return fileRepository == null ? getDefaultRepository() : fileRepository;
|
||||
return switch (storageType) {
|
||||
case MINIO -> CommonBeanFactory.getBean(MinioRepository.class);
|
||||
case LOCAL -> CommonBeanFactory.getBean(LocalFileRepository.class);
|
||||
case GIT -> CommonBeanFactory.getBean(GitRepository.class);
|
||||
default -> getDefaultRepository();
|
||||
};
|
||||
}
|
||||
|
||||
public static FileRepository getRepository(String storage) {
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.system.file;
|
||||
package io.metersphere.sdk.file;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.system.file;
|
||||
package io.metersphere.sdk.file;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.system.file;
|
||||
package io.metersphere.sdk.file;
|
||||
|
||||
import io.metersphere.project.domain.FileMetadataRepository;
|
||||
import io.metersphere.project.domain.FileModuleRepository;
|
||||
import io.metersphere.sdk.dto.FileMetadataRepositoryDTO;
|
||||
import io.metersphere.sdk.dto.FileModuleRepositoryDTO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class FileRequest {
|
|||
//Git文件信息
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.system.file;
|
||||
package io.metersphere.sdk.file;
|
||||
|
||||
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.web.multipart.MultipartFile;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.system.file;
|
||||
package io.metersphere.sdk.file;
|
||||
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.MsFileUtils;
|
|
@ -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.system.config.MinioConfig;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.minio.*;
|
||||
import io.minio.messages.Item;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
@ -15,14 +16,57 @@ import java.io.FileOutputStream;
|
|||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class MinioRepository implements FileRepository {
|
||||
|
||||
@Resource
|
||||
private MinioClient client;
|
||||
// 缓冲区大小
|
||||
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) {
|
||||
String folder = request.getFolder();
|
||||
|
@ -37,7 +81,7 @@ public class MinioRepository implements FileRepository {
|
|||
// 文件存储路径
|
||||
String filePath = getPath(request);
|
||||
client.putObject(PutObjectArgs.builder()
|
||||
.bucket(MinioConfig.BUCKET)
|
||||
.bucket(BUCKET)
|
||||
.object(filePath)
|
||||
.stream(file.getInputStream(), file.getSize(), -1) // 文件内容
|
||||
.build());
|
||||
|
@ -49,7 +93,7 @@ public class MinioRepository implements FileRepository {
|
|||
String filePath = getPath(request);
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) {
|
||||
client.putObject(PutObjectArgs.builder()
|
||||
.bucket(MinioConfig.BUCKET)
|
||||
.bucket(BUCKET)
|
||||
.object(filePath)
|
||||
.stream(inputStream, bytes.length, -1)
|
||||
.build());
|
||||
|
@ -66,19 +110,19 @@ public class MinioRepository implements FileRepository {
|
|||
public void delete(FileRequest request) throws Exception {
|
||||
String filePath = getPath(request);
|
||||
// 删除单个文件
|
||||
removeObject(MinioConfig.BUCKET, filePath);
|
||||
removeObject(BUCKET, filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFolder(FileRequest request) throws Exception {
|
||||
String filePath = getPath(request);
|
||||
// 删除文件夹
|
||||
removeObjects(MinioConfig.BUCKET, filePath);
|
||||
removeObjects(BUCKET, filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFolderFileNames(FileRequest request) throws Exception {
|
||||
return listObjects(MinioConfig.BUCKET, getPath(request));
|
||||
return listObjects(BUCKET, getPath(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,10 +130,10 @@ public class MinioRepository implements FileRepository {
|
|||
String sourcePath = StringUtils.join(request.getCopyFolder(), "/", request.getCopyfileName());
|
||||
String targetPath = getPath(request);
|
||||
client.copyObject(CopyObjectArgs.builder()
|
||||
.bucket(MinioConfig.BUCKET)
|
||||
.bucket(BUCKET)
|
||||
.object(targetPath)
|
||||
.source(CopySource.builder()
|
||||
.bucket(MinioConfig.BUCKET)
|
||||
.bucket(BUCKET)
|
||||
.object(sourcePath)
|
||||
.build())
|
||||
.build());
|
||||
|
@ -142,7 +186,7 @@ public class MinioRepository implements FileRepository {
|
|||
// 下载对象到本地文件
|
||||
try (InputStream inputStream = client.getObject(
|
||||
GetObjectArgs.builder()
|
||||
.bucket(MinioConfig.BUCKET)
|
||||
.bucket(BUCKET)
|
||||
.object(fileName)
|
||||
.build());
|
||||
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(fullPath))) {
|
||||
|
@ -158,7 +202,7 @@ public class MinioRepository implements FileRepository {
|
|||
public InputStream getFileAsStream(FileRequest request) throws Exception {
|
||||
String fileName = getPath(request);
|
||||
return client.getObject(GetObjectArgs.builder()
|
||||
.bucket(MinioConfig.BUCKET) // 存储桶
|
||||
.bucket(BUCKET) // 存储桶
|
||||
.object(fileName) // 文件名
|
||||
.build());
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package io.metersphere.system.utils;
|
||||
package io.metersphere.sdk.util;
|
||||
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.dto.RepositoryQuery;
|
||||
import io.metersphere.system.dto.sdk.RemoteFileAttachInfo;
|
||||
import io.metersphere.sdk.dto.RemoteFileAttachInfo;
|
||||
import io.metersphere.sdk.dto.RepositoryQuery;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.jgit.api.Git;
|
|
@ -11,10 +11,10 @@ import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileCopyRequest;
|
||||
import io.metersphere.system.file.FileRepository;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
import io.metersphere.sdk.file.FileCopyRequest;
|
||||
import io.metersphere.sdk.file.FileRepository;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
|
|
@ -42,8 +42,8 @@ import io.metersphere.system.domain.TestResourcePoolOrganizationExample;
|
|||
import io.metersphere.system.dto.pool.TestResourceDTO;
|
||||
import io.metersphere.system.dto.pool.TestResourceNodeDTO;
|
||||
import io.metersphere.system.dto.pool.TestResourcePoolDTO;
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.TestResourcePoolBlobMapper;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
|
|
|
@ -22,8 +22,8 @@ import io.metersphere.sdk.util.*;
|
|||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.BaseCondition;
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
|
|
|
@ -26,9 +26,9 @@ import io.metersphere.sdk.util.JSON;
|
|||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.file.MinioRepository;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.uid.NumGenerator;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
|
|
|
@ -26,7 +26,7 @@ import io.metersphere.sdk.util.Translator;
|
|||
import io.metersphere.system.domain.Template;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
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.mapper.BaseUserMapper;
|
||||
import io.metersphere.system.mapper.TemplateMapper;
|
||||
|
|
|
@ -20,7 +20,7 @@ import io.metersphere.sdk.constants.StorageType;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
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.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
|
|
|
@ -15,7 +15,7 @@ import io.metersphere.sdk.exception.MSException;
|
|||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
|
|
|
@ -21,8 +21,8 @@ import io.metersphere.sdk.util.Translator;
|
|||
import io.metersphere.system.dto.sdk.BaseSystemConfigDTO;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.file.MinioRepository;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
|
|
|
@ -8,7 +8,7 @@ import io.metersphere.sdk.constants.ModuleConstants;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.TempFileUtils;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
|
@ -17,18 +17,16 @@ import io.metersphere.project.utils.FileMetadataUtils;
|
|||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
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.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.TempFileUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
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.sdk.file.FileRepository;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.file.MinioRepository;
|
||||
import io.metersphere.sdk.util.*;
|
||||
import io.metersphere.system.mapper.BaseUserMapper;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.utils.GitRepositoryUtil;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -346,7 +344,12 @@ public class FileMetadataService {
|
|||
if (StringUtils.equals(fileMetadata.getStorage(), StorageType.GIT.name())) {
|
||||
FileModuleRepository fileModuleRepository = fileModuleRepositoryMapper.selectByPrimaryKey(fileMetadata.getModuleId());
|
||||
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);
|
||||
|
@ -432,6 +435,7 @@ public class FileMetadataService {
|
|||
throw new MSException(Translator.get("file.size.is.too.large"));
|
||||
}
|
||||
}
|
||||
|
||||
private static final String FILE_MODULE_COUNT_MY = "my";
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,9 +18,9 @@ import io.metersphere.sdk.constants.StorageType;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
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.utils.GitRepositoryUtil;
|
||||
import io.metersphere.sdk.util.GitRepositoryUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ import io.metersphere.system.base.BaseTest;
|
|||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.file.MinioRepository;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
|
@ -29,7 +29,7 @@ import io.metersphere.system.controller.handler.ResultHolder;
|
|||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
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.OperationLogType;
|
||||
import io.metersphere.system.service.CommonProjectService;
|
||||
|
|
|
@ -139,13 +139,6 @@
|
|||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>${springdoc-openapi-ui.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- jgit -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jgit</groupId>
|
||||
<artifactId>org.eclipse.jgit</artifactId>
|
||||
<version>${jgit.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -2,11 +2,14 @@ package io.metersphere.system.config;
|
|||
|
||||
|
||||
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.RsaUtils;
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileRepository;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.minio.MinioClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
|
@ -14,6 +17,8 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
@Configuration
|
||||
public class RsaConfig implements ApplicationRunner {
|
||||
@Resource
|
||||
private MinioClient client;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
|
@ -21,6 +26,8 @@ public class RsaConfig implements ApplicationRunner {
|
|||
request.setFileName("rsa.key");
|
||||
request.setFolder(DefaultRepositoryDir.getSystemRootDir());
|
||||
FileRepository fileRepository = FileCenter.getDefaultRepository();
|
||||
// 初始化MinIO配置
|
||||
((MinioRepository) fileRepository).init(client);
|
||||
|
||||
try {
|
||||
byte[] file = fileRepository.getFile(request);
|
||||
|
|
|
@ -3,8 +3,8 @@ package io.metersphere.system.service;
|
|||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.system.domain.SystemParameter;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.file.MinioRepository;
|
||||
import io.metersphere.system.mapper.SystemParameterMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
|
|
@ -6,8 +6,8 @@ import io.metersphere.sdk.constants.LocalRepositoryDir;
|
|||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.system.controller.handler.result.CommonResultCode;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.plugin.MsPluginManager;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
|
|
|
@ -2,10 +2,13 @@ package io.metersphere.system.base;
|
|||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.sdk.constants.UserRoleType;
|
||||
import io.metersphere.sdk.domain.OperationLogExample;
|
||||
import io.metersphere.sdk.exception.IResultCode;
|
||||
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.util.JSON;
|
||||
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.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import io.minio.MinioClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -79,6 +83,8 @@ public abstract class BaseTest {
|
|||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private MockServerClient mockServerClient;
|
||||
@Resource
|
||||
private MinioClient client;
|
||||
|
||||
protected static final String DEFAULT_LIST = "list";
|
||||
protected static final String DEFAULT_GET = "get/{0}";
|
||||
|
@ -103,6 +109,9 @@ public abstract class BaseTest {
|
|||
this.sessionId = this.adminAuthInfo.getSessionId();
|
||||
this.csrfToken = this.adminAuthInfo.getCsrfToken();
|
||||
}
|
||||
// 初始化MinIO配置
|
||||
((MinioRepository) FileCenter.getRepository(StorageType.MINIO)).init(client);
|
||||
|
||||
if (permissionAuthInfoMap.isEmpty()) {
|
||||
// 获取系统,组织,项目对应的权限测试用户的认证信息
|
||||
List<String> permissionUserNames = Arrays.asList(UserRoleType.SYSTEM.name(), UserRoleType.ORGANIZATION.name(), UserRoleType.PROJECT.name());
|
||||
|
@ -239,6 +248,7 @@ public abstract class BaseTest {
|
|||
|
||||
/**
|
||||
* 设置 mock get 接口
|
||||
*
|
||||
* @param path
|
||||
* @param mockBody
|
||||
*/
|
||||
|
@ -258,6 +268,7 @@ public abstract class BaseTest {
|
|||
|
||||
/**
|
||||
* 设置 mock post 接口
|
||||
*
|
||||
* @param path
|
||||
* @param mockBody
|
||||
*/
|
||||
|
|
|
@ -3,8 +3,8 @@ package io.metersphere.system.controller;
|
|||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.file.MinioRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import io.metersphere.system.mock.CleanupTestResourceService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -15,7 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@AutoConfigureMockMvc
|
||||
public class CleanupResourceTests {
|
||||
public class CleanupResourceTests extends BaseTest {
|
||||
private final ProjectServiceInvoker serviceInvoker;
|
||||
@Resource
|
||||
private CleanupTestResourceService cleanupTestResourceService;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import io.metersphere.system.file.FileCenter;
|
||||
import io.metersphere.system.file.FileRepository;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
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 jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
|
|
|
@ -12,8 +12,8 @@ import io.metersphere.system.domain.*;
|
|||
import io.metersphere.system.dto.OrganizationDTO;
|
||||
import io.metersphere.system.dto.PluginDTO;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.LocalFileRepository;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.file.LocalFileRepository;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.PluginMapper;
|
||||
import io.metersphere.system.mapper.PluginOrganizationMapper;
|
||||
|
|
Loading…
Reference in New Issue