mirror of https://github.com/certd/certd
perf: openapi返回证书时挑选匹配范围最小的那一个;增加format参数,增加返回值p7b格式,增加detail返回
parent
c09c962cb6
commit
2085bcceb6
|
@ -21,6 +21,15 @@ export type CertReaderHandleContext = {
|
||||||
};
|
};
|
||||||
export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise<void>;
|
export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise<void>;
|
||||||
export type HandleOpts = { logger: ILogger; handle: CertReaderHandle };
|
export type HandleOpts = { logger: ILogger; handle: CertReaderHandle };
|
||||||
|
|
||||||
|
const formats = {
|
||||||
|
pem: ["crt", "key", "ic"],
|
||||||
|
one: ["one"],
|
||||||
|
pfx: ["pfx"],
|
||||||
|
der: ["der"],
|
||||||
|
jks: ["jks"],
|
||||||
|
p7b: ["p7b", "key"],
|
||||||
|
};
|
||||||
export class CertReader {
|
export class CertReader {
|
||||||
cert: CertInfo;
|
cert: CertInfo;
|
||||||
|
|
||||||
|
@ -74,10 +83,19 @@ export class CertReader {
|
||||||
return arr[0] + endStr;
|
return arr[0] + endStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
toCertInfo(): CertInfo {
|
toCertInfo(format?: string): CertInfo {
|
||||||
|
if (!format) {
|
||||||
return this.cert;
|
return this.cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatArr = formats[format];
|
||||||
|
const res: any = {};
|
||||||
|
formatArr.forEach((key: string) => {
|
||||||
|
res[key] = this.cert[key];
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
getCrtDetail(crt: string = this.cert.crt) {
|
getCrtDetail(crt: string = this.cert.crt) {
|
||||||
return CertReader.readCertDetail(crt);
|
return CertReader.readCertDetail(crt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ export async function SaveCommPluginConfigs(data: CommPluginConfig): Promise<voi
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function savePluginSetting(req: { id: number; metadata: any }): Promise<void> {
|
export async function savePluginSetting(req: { name: string; sysSetting: any }): Promise<void> {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/saveSetting",
|
url: apiPrefix + "/saveSetting",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import * as api from "/@/views/sys/plugin/api";
|
import * as api from "/@/views/sys/plugin/api";
|
||||||
import { useFormWrapper } from "@fast-crud/fast-crud";
|
import { useFormWrapper } from "@fast-crud/fast-crud";
|
||||||
import { useI18n } from "/@/locales";
|
import { useI18n } from "/@/locales";
|
||||||
import { Modal, notification } from "ant-design-vue";
|
import { notification } from "ant-design-vue";
|
||||||
import ConfigEditor from "./config-editor.vue";
|
import ConfigEditor from "./config-editor.vue";
|
||||||
import { useModal } from "/@/use/use-modal";
|
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { usePluginStore } from "/@/store/plugin";
|
import { usePluginStore } from "/@/store/plugin";
|
||||||
|
|
||||||
export function usePluginConfig() {
|
export function usePluginConfig() {
|
||||||
const { openCrudFormDialog } = useFormWrapper();
|
const { openCrudFormDialog } = useFormWrapper();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const pluginStore = usePluginStore();
|
const pluginStore = usePluginStore();
|
||||||
const modal = useModal();
|
// @ts-ignore
|
||||||
async function openConfigDialog({ row, crudExpose }) {
|
async function openConfigDialog({ row, crudExpose }) {
|
||||||
const configEditorRef = ref();
|
const configEditorRef = ref();
|
||||||
function createCrudOptions() {
|
function createCrudOptions() {
|
||||||
|
|
|
@ -10,6 +10,7 @@ export type CertGetReq = {
|
||||||
domains?: string;
|
domains?: string;
|
||||||
certId: number;
|
certId: number;
|
||||||
autoApply?:boolean;
|
autoApply?:boolean;
|
||||||
|
format?:string; //默认是所有,pem,der,p12,pfx,jks,one,p7b
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,6 +39,7 @@ export class OpenCertController extends BaseOpenController {
|
||||||
domains: req.domains,
|
domains: req.domains,
|
||||||
certId: req.certId,
|
certId: req.certId,
|
||||||
autoApply: req.autoApply??false,
|
autoApply: req.autoApply??false,
|
||||||
|
format: req.format
|
||||||
});
|
});
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class CertInfoFacade {
|
||||||
@Inject()
|
@Inject()
|
||||||
userSettingsService : UserSettingsService
|
userSettingsService : UserSettingsService
|
||||||
|
|
||||||
async getCertInfo(req: { domains?: string; certId?: number; userId: number,autoApply?:boolean }) {
|
async getCertInfo(req: { domains?: string; certId?: number; userId: number,autoApply?:boolean,format?:string }) {
|
||||||
const { domains, certId, userId } = req;
|
const { domains, certId, userId } = req;
|
||||||
if (certId) {
|
if (certId) {
|
||||||
return await this.certInfoService.getCertInfoById({ id: certId, userId });
|
return await this.certInfoService.getCertInfoById({ id: certId, userId });
|
||||||
|
@ -41,7 +41,7 @@ export class CertInfoFacade {
|
||||||
const domainArr = domains.split(',');
|
const domainArr = domains.split(',');
|
||||||
|
|
||||||
const matchedList = await this.certInfoService.getMatchCertList({domains:domainArr,userId})
|
const matchedList = await this.certInfoService.getMatchCertList({domains:domainArr,userId})
|
||||||
let matched: CertInfoEntity = null
|
|
||||||
if (matchedList.length === 0 ) {
|
if (matchedList.length === 0 ) {
|
||||||
if(req.autoApply === true){
|
if(req.autoApply === true){
|
||||||
//自动申请,先创建自动申请流水线
|
//自动申请,先创建自动申请流水线
|
||||||
|
@ -54,13 +54,7 @@ export class CertInfoFacade {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
matched = null;
|
let matched = this.getMinixMatched(matchedList);
|
||||||
for (const item of matchedList) {
|
|
||||||
if (item.expiresTime>0 && item.expiresTime > new Date().getTime()) {
|
|
||||||
matched = item;
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
if(req.autoApply === true){
|
if(req.autoApply === true){
|
||||||
//如果没有找到有效期内的证书,则自动触发一次申请
|
//如果没有找到有效期内的证书,则自动触发一次申请
|
||||||
|
@ -75,7 +69,38 @@ export class CertInfoFacade {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.certInfoService.getCertInfoById({ id: matched.id, userId: userId });
|
return await this.certInfoService.getCertInfoById({ id: matched.id, userId: userId,format:req.format });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMinixMatched(matchedList: CertInfoEntity[]) {
|
||||||
|
let matched: CertInfoEntity = null;
|
||||||
|
for (const item of matchedList) {
|
||||||
|
if (item.expiresTime > 0 && item.expiresTime > new Date().getTime()) {
|
||||||
|
if (matched) {
|
||||||
|
//如果前面已经有match的值,判断范围是否比上一个小
|
||||||
|
const currentStars = `-${item.domains}`.split("*");
|
||||||
|
const matchedStars = `-${matched.domains}`.split("*");
|
||||||
|
|
||||||
|
const currentLength = item.domains.split(",");
|
||||||
|
const matchedLength = matched.domains.split(",");
|
||||||
|
if (currentStars.length < matchedStars.length) {
|
||||||
|
//如果*的数量比上一个少,则替换为当前
|
||||||
|
matched = item;
|
||||||
|
} else if (currentStars.length == matchedStars.length) {
|
||||||
|
//如果*的数量相同,则比较域名数量
|
||||||
|
if (currentLength.length < matchedLength.length) {
|
||||||
|
matched = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
matched = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createAutoPipeline(req:{domains:string[],userId:number}){
|
async createAutoPipeline(req:{domains:string[],userId:number}){
|
||||||
|
|
|
@ -113,7 +113,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCertInfoById(req: { id: number; userId: number }) {
|
async getCertInfoById(req: { id: number; userId: number,format?:string }) {
|
||||||
const entity = await this.info(req.id);
|
const entity = await this.info(req.id);
|
||||||
if (!entity || entity.userId !== req.userId) {
|
if (!entity || entity.userId !== req.userId) {
|
||||||
throw new CodeException(Constants.res.openCertNotFound);
|
throw new CodeException(Constants.res.openCertNotFound);
|
||||||
|
@ -124,7 +124,14 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||||
}
|
}
|
||||||
const certInfo = JSON.parse(entity.certInfo) as CertInfo;
|
const certInfo = JSON.parse(entity.certInfo) as CertInfo;
|
||||||
const certReader = new CertReader(certInfo);
|
const certReader = new CertReader(certInfo);
|
||||||
return certReader.toCertInfo();
|
return {
|
||||||
|
...certReader.toCertInfo(req.format),
|
||||||
|
detail: {
|
||||||
|
id: entity.id,
|
||||||
|
domains: entity.domains.split(','),
|
||||||
|
notAfter: certReader.expires,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateCertByPipelineId(pipelineId: number, cert: CertInfo,file?:string,fromType = 'pipeline') {
|
async updateCertByPipelineId(pipelineId: number, cert: CertInfo,file?:string,fromType = 'pipeline') {
|
||||||
|
|
Loading…
Reference in New Issue