mirror of
https://github.com/certd/certd.git
synced 2026-05-15 12:37:30 +08:00
perf: 1panel支持先上传证书再选择证书
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { CertInfo, CertReader, ICertInfoGetter } from '@certd/plugin-lib';
|
||||
import { CertInfoService } from '../../../monitor/index.js';
|
||||
|
||||
export class CertInfoGetter implements ICertInfoGetter {
|
||||
userId: number;
|
||||
projectId: number;
|
||||
certInfoService: CertInfoService;
|
||||
constructor(userId: number, projectId: number, certInfoService: CertInfoService) {
|
||||
this.userId = userId;
|
||||
this.projectId = projectId;
|
||||
this.certInfoService = certInfoService;
|
||||
}
|
||||
async getByPipelineId(pipelineId: number): Promise<CertInfo> {
|
||||
if (!pipelineId) {
|
||||
throw new Error(`流水线id不能为空`)
|
||||
}
|
||||
const query :any= {
|
||||
pipelineId,
|
||||
userId: this.userId,
|
||||
}
|
||||
if (this.projectId) {
|
||||
query.projectId = this.projectId
|
||||
}
|
||||
const entity = await this.certInfoService.findOne({
|
||||
where:query
|
||||
})
|
||||
if (!entity || !entity.certInfo) {
|
||||
throw new Error(`流水线(${pipelineId})还未生成证书,请先运行一次流水线`)
|
||||
}
|
||||
return new CertReader(JSON.parse(entity.certInfo)).cert;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,9 @@ import { SubDomainsGetter } from "./sub-domain-getter.js";
|
||||
import { DomainVerifierGetter } from "./domain-verifier-getter.js";
|
||||
import { DomainService } from "../../../cert/service/domain-service.js";
|
||||
import { SubDomainService } from "../sub-domain-service.js";
|
||||
import { CertInfoGetter } from "./cert-info-getter.js";
|
||||
import { CertInfoService } from "../../../monitor/index.js";
|
||||
import { ICertInfoGetter } from "@certd/plugin-lib";
|
||||
|
||||
const serviceNames = [
|
||||
'ocrService',
|
||||
@@ -34,6 +37,8 @@ export class TaskServiceGetter implements IServiceGetter{
|
||||
return await this.getNotificationService() as T
|
||||
} else if (serviceName === 'domainVerifierGetter') {
|
||||
return await this.getDomainVerifierGetter() as T
|
||||
} else if (serviceName === 'certInfoGetter') {
|
||||
return await this.getCertInfoGetter() as T
|
||||
}else{
|
||||
if(!serviceNames.includes(serviceName)){
|
||||
throw new Error(`${serviceName} not in whitelist`)
|
||||
@@ -51,6 +56,11 @@ export class TaskServiceGetter implements IServiceGetter{
|
||||
return new SubDomainsGetter(this.userId,this.projectId, subDomainsService,domainService)
|
||||
}
|
||||
|
||||
async getCertInfoGetter(): Promise<ICertInfoGetter> {
|
||||
const certInfoService:CertInfoService = await this.appCtx.getAsync("certInfoService")
|
||||
return new CertInfoGetter(this.userId, this.projectId, certInfoService)
|
||||
}
|
||||
|
||||
async getAccessService(): Promise<AccessGetter> {
|
||||
const accessService:AccessService = await this.appCtx.getAsync("accessService")
|
||||
return new AccessGetter(this.userId, this.projectId, accessService.getById.bind(accessService));
|
||||
|
||||
Reference in New Issue
Block a user