mirror of https://github.com/certd/certd
perf: 上传自定义证书
parent
c89686a2fd
commit
75a38d95f3
|
@ -10,9 +10,8 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import zhCN from "ant-design-vue/es/locale/zh_CN";
|
import zhCN from "ant-design-vue/es/locale/zh_CN";
|
||||||
import enUS from "ant-design-vue/es/locale/en_US";
|
import enUS from "ant-design-vue/es/locale/en_US";
|
||||||
import { nextTick, provide, ref } from "vue";
|
import { provide, ref } from "vue";
|
||||||
import { usePageStore } from "/src/store/modules/page";
|
import { usePageStore } from "/src/store/modules/page";
|
||||||
import { useResourceStore } from "/src/store/modules/resource";
|
|
||||||
import { useSettingStore } from "/@/store/modules/settings";
|
import { useSettingStore } from "/@/store/modules/settings";
|
||||||
import "dayjs/locale/zh-cn";
|
import "dayjs/locale/zh-cn";
|
||||||
import "dayjs/locale/en";
|
import "dayjs/locale/en";
|
||||||
|
|
|
@ -70,7 +70,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
key: "id",
|
key: "id",
|
||||||
type: "number",
|
type: "number",
|
||||||
column: {
|
column: {
|
||||||
width: 100
|
width: 80
|
||||||
},
|
},
|
||||||
form: {
|
form: {
|
||||||
show: false
|
show: false
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { request } from "/src/api/service";
|
import { request } from "/src/api/service";
|
||||||
|
|
||||||
export function createApi() {
|
const apiPrefix = "/monitor/cert";
|
||||||
const apiPrefix = "/monitor/cert";
|
export const certInfoApi = {
|
||||||
return {
|
|
||||||
async GetList(query: any) {
|
async GetList(query: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/page",
|
url: apiPrefix + "/page",
|
||||||
|
@ -47,8 +46,12 @@ export function createApi() {
|
||||||
url: apiPrefix + "/all",
|
url: apiPrefix + "/all",
|
||||||
method: "post"
|
method: "post"
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
async Upload(body: { id?: number; cert: { crt: string; key: string } }) {
|
||||||
|
return await request({
|
||||||
|
url: apiPrefix + "/upload",
|
||||||
|
method: "post",
|
||||||
|
data: body
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
export const pipelineGroupApi = createApi();
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud";
|
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, useFormWrapper, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud";
|
||||||
import { pipelineGroupApi } from "./api";
|
import { certInfoApi } from "./api";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
import { useUserStore } from "/@/store/modules/user";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
|
|
||||||
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const api = pipelineGroupApi;
|
const api = certInfoApi;
|
||||||
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
||||||
return await api.GetList(query);
|
return await api.GetList(query);
|
||||||
};
|
};
|
||||||
|
@ -26,7 +28,8 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
const res = await api.AddObj(form);
|
const res = await api.AddObj(form);
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
const { openCrudFormDialog } = useFormWrapper();
|
||||||
|
const router = useRouter();
|
||||||
return {
|
return {
|
||||||
crudOptions: {
|
crudOptions: {
|
||||||
request: {
|
request: {
|
||||||
|
@ -50,7 +53,67 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
width: 600
|
width: 600
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actionbar: { show: false },
|
actionbar: {
|
||||||
|
show: true,
|
||||||
|
buttons: {
|
||||||
|
add: {
|
||||||
|
text: "上传自定义证书",
|
||||||
|
type: "primary",
|
||||||
|
async click() {
|
||||||
|
function createCrudOptions() {
|
||||||
|
return {
|
||||||
|
crudOptions: {
|
||||||
|
request: {
|
||||||
|
addRequest: async (form: any) => {
|
||||||
|
return await api.Upload(form);
|
||||||
|
},
|
||||||
|
editRequest: async (form: any) => {
|
||||||
|
return await api.Upload(form);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
columns: {
|
||||||
|
id: {
|
||||||
|
title: "ID",
|
||||||
|
type: "number",
|
||||||
|
form: {
|
||||||
|
show: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cert.crt": {
|
||||||
|
title: "证书",
|
||||||
|
type: "textarea",
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
rows: 4
|
||||||
|
},
|
||||||
|
rules: [{ required: true, message: "此项必填" }]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cert.key": {
|
||||||
|
title: "私钥",
|
||||||
|
type: "textarea",
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
rows: 4
|
||||||
|
},
|
||||||
|
rules: [{ required: true, message: "此项必填" }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
wrapper: {
|
||||||
|
title: "上传自定义证书"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const { crudOptions } = createCrudOptions();
|
||||||
|
const wrapperRef = await openCrudFormDialog({ crudOptions });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
rowHandle: {
|
rowHandle: {
|
||||||
width: 200,
|
width: 200,
|
||||||
fixed: "right",
|
fixed: "right",
|
||||||
|
@ -176,7 +239,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pipeline.title": {
|
"pipeline.title": {
|
||||||
title: "已关联流水线",
|
title: "关联流水线",
|
||||||
search: { show: false },
|
search: { show: false },
|
||||||
type: "link",
|
type: "link",
|
||||||
form: {
|
form: {
|
||||||
|
@ -185,7 +248,13 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
column: {
|
column: {
|
||||||
width: 350,
|
width: 350,
|
||||||
sorter: true,
|
sorter: true,
|
||||||
component: {}
|
component: {
|
||||||
|
on: {
|
||||||
|
onClick({ row }) {
|
||||||
|
router.push({ path: "/certd/pipeline/detail", query: { id: row.pipelineId, editMode: "false" } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,15 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||||
});
|
});
|
||||||
return this.ok(list);
|
return this.ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('/upload', { summary: Constants.per.authOnly })
|
||||||
|
async upload(@Body(ALL) body: any) {
|
||||||
|
if (body.id) {
|
||||||
|
await this.service.checkUserId(body.id, this.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await this.service.upload(body);
|
||||||
|
|
||||||
|
return this.ok(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class AutoEPipelineEmitterRegister {
|
||||||
}
|
}
|
||||||
async onCertApplySuccess() {
|
async onCertApplySuccess() {
|
||||||
pipelineEmitter.on(EVENT_CERT_APPLY_SUCCESS, async (event: PipelineEvent<CertReader>) => {
|
pipelineEmitter.on(EVENT_CERT_APPLY_SUCCESS, async (event: PipelineEvent<CertReader>) => {
|
||||||
await this.certInfoService.updateCert(event.pipeline.id, event.event);
|
await this.certInfoService.updateCertByPipelineId(event.pipeline.id, event.event);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||||
import { BaseService, CodeException, Constants, PageReq } from '@certd/lib-server';
|
import { BaseService, CodeException, CommonException, Constants, PageReq } from '@certd/lib-server';
|
||||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { CertInfoEntity } from '../entity/cert-info.js';
|
import { CertInfoEntity } from '../entity/cert-info.js';
|
||||||
import { utils } from '@certd/basic';
|
import { utils } from '@certd/basic';
|
||||||
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||||
|
|
||||||
|
export type UploadCertReq = {
|
||||||
|
id?: number;
|
||||||
|
certReader: CertReader;
|
||||||
|
fromType?: string;
|
||||||
|
};
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||||
export class CertInfoService extends BaseService<CertInfoEntity> {
|
export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||||
|
@ -125,15 +131,27 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||||
return certReader.toCertInfo();
|
return certReader.toCertInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateCert(pipelineId: number, certReader: CertReader) {
|
async updateCertByPipelineId(pipelineId: number, certReader: CertReader, fromType = 'pipeline') {
|
||||||
const found = await this.repository.findOne({
|
const found = await this.repository.findOne({
|
||||||
where: {
|
where: {
|
||||||
pipelineId,
|
pipelineId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const bean = await this.updateCert({
|
||||||
|
id: found?.id,
|
||||||
|
certReader,
|
||||||
|
fromType,
|
||||||
|
});
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateCert(req: UploadCertReq) {
|
||||||
const bean = new CertInfoEntity();
|
const bean = new CertInfoEntity();
|
||||||
if (found) {
|
const { id, fromType, certReader } = req;
|
||||||
bean.id = found.id;
|
if (id) {
|
||||||
|
bean.id = id;
|
||||||
|
} else {
|
||||||
|
bean.fromType = fromType;
|
||||||
}
|
}
|
||||||
const certInfo = certReader.toCertInfo();
|
const certInfo = certReader.toCertInfo();
|
||||||
bean.certInfo = JSON.stringify(certInfo);
|
bean.certInfo = JSON.stringify(certInfo);
|
||||||
|
@ -146,5 +164,19 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||||
bean.certProvider = certReader.detail.issuer.commonName;
|
bean.certProvider = certReader.detail.issuer.commonName;
|
||||||
|
|
||||||
await this.addOrUpdate(bean);
|
await this.addOrUpdate(bean);
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
async upload(body: { id?: number; cert: CertInfo }) {
|
||||||
|
const { id, cert } = body;
|
||||||
|
if (!cert) {
|
||||||
|
throw new CommonException("cert can't be empty");
|
||||||
|
}
|
||||||
|
const res = await this.updateCert({
|
||||||
|
id,
|
||||||
|
certReader: new CertReader(cert),
|
||||||
|
fromType: 'upload',
|
||||||
|
});
|
||||||
|
return res.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue