perf: 密钥备份

This commit is contained in:
xiaojunnuo
2024-10-15 12:59:40 +08:00
parent 28bb4856be
commit 1c6028abcf
12 changed files with 180 additions and 30 deletions
@@ -0,0 +1,21 @@
import { Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { PipelineService } from '../../modules/pipeline/service/pipeline-service.js';
import { BaseController, Constants } from '@certd/lib-server';
import { StorageService } from '../../modules/pipeline/service/storage-service.js';
@Provide()
@Controller('/api/pi/cert')
export class CertController extends BaseController {
@Inject()
pipelineService: PipelineService;
@Inject()
storeService: StorageService;
@Post('/get', { summary: Constants.per.authOnly })
async getCert(@Query('id') id: number) {
const userId = this.getUserId();
await this.pipelineService.checkUserId(id, userId);
const privateVars = this.storeService.getPipelinePrivateVars(id);
return this.ok(privateVars);
}
}
@@ -80,8 +80,8 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
@Post('/getSysSettings', { summary: 'sys:settings:edit' })
async getSysSettings() {
const publicSettings = await this.service.getPublicSettings();
const privateSettings = await this.service.getPrivateSettings();
privateSettings.removeSecret();
let privateSettings = await this.service.getPrivateSettings();
privateSettings = privateSettings.removeSecret();
return this.ok({ public: publicSettings, private: privateSettings });
}
@@ -43,6 +43,8 @@ export class AutoInitSite {
await this.sysSettingsService.saveSetting(privateInfo);
}
await this.sysSettingsService.backupSecret();
await this.sysSettingsService.reloadPrivateSettings();
// 授权许可
@@ -44,6 +44,9 @@ export class StorageService extends BaseService<StorageEntity> {
}
async findPipelineVars(pipelineIds: number[]) {
if (pipelineIds == null || pipelineIds.length === 0) {
throw new Error('pipelineIds 不能为空');
}
return await this.repository.find({
where: {
scope: 'pipeline',
@@ -52,4 +55,17 @@ export class StorageService extends BaseService<StorageEntity> {
},
});
}
async getPipelinePrivateVars(pipelineId: number) {
if (pipelineId == null) {
throw new Error('pipelineId 不能为空');
}
return await this.repository.find({
where: {
scope: 'pipeline',
namespace: pipelineId + '',
key: 'privateVars',
},
});
}
}