ci: 保存rsakey到minio

This commit is contained in:
CaptainB 2023-08-24 15:27:51 +08:00 committed by 刘瑞斌
parent 5b662b92d4
commit 193b54a02c
1 changed files with 28 additions and 5 deletions

View File

@ -1,19 +1,42 @@
package io.metersphere.sdk.config; package io.metersphere.sdk.config;
import io.metersphere.sdk.file.FileRepository;
import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.log.constants.OperationLogModule;
import io.metersphere.sdk.util.RsaKey;
import io.metersphere.sdk.util.RsaUtil;
import jakarta.annotation.Resource;
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;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class RsaConfig implements ApplicationRunner { public class RsaConfig implements ApplicationRunner {
// @Resource @Resource
// private FileService fileService; private FileRepository fileRepository;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
// // todo 从数据库中获取 RSA 密钥对 FileRequest request = new FileRequest();
// RsaKey value = fileService.checkRsaKey(); request.setFileName("rsa.key");
// RsaUtil.setRsaKey(value); request.setProjectId("system");
request.setResourceId(OperationLogModule.SYSTEM_PARAMETER_SETTING);
//
try {
byte[] file = fileRepository.getFile(request);
if (file != null) {
RsaKey rsaKey = SerializationUtils.deserialize(file);
RsaUtil.setRsaKey(rsaKey);
return;
}
} catch (Exception ignored) {
}
// 保存到minio
RsaKey rsaKey = RsaUtil.getRsaKey();
byte[] bytes = SerializationUtils.serialize(rsaKey);
fileRepository.saveFile(bytes, request);
RsaUtil.setRsaKey(rsaKey);
} }
} }