mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
chore: 支持手动上传证书并部署
This commit is contained in:
@@ -121,6 +121,16 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
return this.ok(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Post('/getCert', { summary: Constants.per.authOnly })
|
||||
async getCert(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
const certInfoEntity = await this.service.info(id);
|
||||
const certInfo = JSON.parse(certInfoEntity.certInfo);
|
||||
return this.ok(certInfo);
|
||||
}
|
||||
|
||||
@Post('/upload', { summary: Constants.per.authOnly })
|
||||
async upload(@Body(ALL) body: {cert: CertInfo, pipeline: any, id?: number}) {
|
||||
if (body.id) {
|
||||
@@ -131,23 +141,16 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
userId: this.getUserId(),
|
||||
cert: body.cert,
|
||||
});
|
||||
return this.ok();
|
||||
}else{
|
||||
//添加
|
||||
await this.certUploadService.createUploadCertPipeline({
|
||||
const res = await this.certUploadService.createUploadCertPipeline({
|
||||
userId: this.getUserId(),
|
||||
cert: body.cert,
|
||||
pipeline: body.pipeline,
|
||||
});
|
||||
|
||||
return this.ok(res)
|
||||
}
|
||||
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/getCert', { summary: Constants.per.authOnly })
|
||||
async getCert(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
const certInfoEntity = await this.service.info(id);
|
||||
const certInfo = JSON.parse(certInfoEntity.certInfo);
|
||||
return this.ok(certInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ export type UpdateCertReq = {
|
||||
export type CreateUploadPipelineReq = {
|
||||
cert: CertInfo;
|
||||
userId: number;
|
||||
pipeline?:{
|
||||
input?:any;
|
||||
notifications?:any[]
|
||||
}
|
||||
};
|
||||
|
||||
@Provide("CertUploadService")
|
||||
@@ -86,13 +90,16 @@ export class CertUploadService extends BaseService<CertInfoEntity> {
|
||||
});
|
||||
|
||||
const pipelineTitle = certReader.getAllDomains()[0] +"上传证书自动部署";
|
||||
const notifications = [];
|
||||
notifications.push({
|
||||
type: "custom",
|
||||
when: ["error", "turnToSuccess", "success"],
|
||||
notificationId: 0,
|
||||
title: "默认通知",
|
||||
});
|
||||
const notifications = body.pipeline?.notifications ||[];
|
||||
if(notifications.length === 0){
|
||||
notifications.push({
|
||||
type: "custom",
|
||||
when: ["error", "turnToSuccess", "success"],
|
||||
notificationId: 0,
|
||||
title: "默认通知",
|
||||
});
|
||||
}
|
||||
|
||||
let pipeline = {
|
||||
title: pipelineTitle,
|
||||
runnableType: "pipeline",
|
||||
@@ -115,6 +122,7 @@ export class CertUploadService extends BaseService<CertInfoEntity> {
|
||||
input: {
|
||||
certInfoId: newCertInfo.id,
|
||||
domains: newCertInfo.domains.split(','),
|
||||
...body.pipeline?.input
|
||||
},
|
||||
strategy: {
|
||||
runStrategy: 0, // 正常执行
|
||||
@@ -144,7 +152,10 @@ export class CertUploadService extends BaseService<CertInfoEntity> {
|
||||
pipelineId: newPipeline.id
|
||||
});
|
||||
|
||||
return newCertInfo.id
|
||||
return {
|
||||
id:newCertInfo.id,
|
||||
pipelineId: newPipeline.id
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user