mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
perf: 支持手动上传证书并部署
This commit is contained in:
@@ -10,9 +10,10 @@ export type UploadCertReq = {
|
||||
id?: number;
|
||||
certReader: CertReader;
|
||||
fromType?: string;
|
||||
userId?: number;
|
||||
};
|
||||
|
||||
@Provide()
|
||||
@Provide("CertInfoService")
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
@InjectEntityModel(CertInfoEntity)
|
||||
@@ -147,7 +148,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
|
||||
private async updateCert(req: UploadCertReq) {
|
||||
const bean = new CertInfoEntity();
|
||||
const { id, fromType, certReader } = req;
|
||||
const { id, fromType,userId, certReader } = req;
|
||||
if (id) {
|
||||
bean.id = id;
|
||||
} else {
|
||||
@@ -162,13 +163,13 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
bean.domainCount = domains.length;
|
||||
bean.expiresTime = certReader.expires;
|
||||
bean.certProvider = certReader.detail.issuer.commonName;
|
||||
|
||||
bean.userId = userId
|
||||
await this.addOrUpdate(bean);
|
||||
return bean;
|
||||
}
|
||||
|
||||
async upload(body: { id?: number; cert: CertInfo }) {
|
||||
const { id, cert } = body;
|
||||
async upload(body: { id?: number; userId?:number ;cert: CertInfo }) {
|
||||
const { id, userId, cert } = body;
|
||||
if (!cert) {
|
||||
throw new CommonException("cert can't be empty");
|
||||
}
|
||||
@@ -176,6 +177,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
id,
|
||||
certReader: new CertReader(cert),
|
||||
fromType: 'upload',
|
||||
userId
|
||||
});
|
||||
return res.id;
|
||||
}
|
||||
|
||||
@@ -182,6 +182,9 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
);
|
||||
}
|
||||
async sendExpiresNotify(site: SiteInfoEntity) {
|
||||
|
||||
const tipDays = 10
|
||||
|
||||
const expires = site.certExpiresTime;
|
||||
const validDays = dayjs(expires).diff(dayjs(), 'day');
|
||||
const url = await this.notificationService.getBindUrl('#/monitor/site');
|
||||
@@ -190,7 +193,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
证书域名: ${site.certDomains} \n
|
||||
证书颁发者: ${site.certProvider} \n
|
||||
过期时间: ${dayjs(site.certExpiresTime).format('YYYY-MM-DD')} \n`;
|
||||
if (validDays >= 0 && validDays < 10) {
|
||||
if (validDays >= 0 && validDays < tipDays) {
|
||||
// 发通知
|
||||
await this.notificationService.send(
|
||||
{
|
||||
|
||||
@@ -475,6 +475,12 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
const siteInfo = await this.sysSettingsService.getSetting<SysSiteInfo>(SysSiteInfo);
|
||||
sysInfo.title = siteInfo.title;
|
||||
}
|
||||
const serviceContainer = {
|
||||
CertInfoService: this.certInfoService
|
||||
}
|
||||
const serviceGetter = (name: string) => {
|
||||
return serviceContainer[name]
|
||||
}
|
||||
const executor = new Executor({
|
||||
user,
|
||||
pipeline,
|
||||
@@ -488,6 +494,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
notificationService: notificationGetter,
|
||||
fileRootDir: this.certdConfig.fileRootDir,
|
||||
sysInfo,
|
||||
serviceGetter
|
||||
});
|
||||
try {
|
||||
runningTasks.set(historyId, executor);
|
||||
|
||||
Reference in New Issue
Block a user