mirror of https://github.com/certd/certd
perf: 上传自定义证书
parent
c89686a2fd
commit
75a38d95f3
|
@ -10,9 +10,8 @@
|
|||
<script lang="ts" setup>
|
||||
import zhCN from "ant-design-vue/es/locale/zh_CN";
|
||||
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 { useResourceStore } from "/src/store/modules/resource";
|
||||
import { useSettingStore } from "/@/store/modules/settings";
|
||||
import "dayjs/locale/zh-cn";
|
||||
import "dayjs/locale/en";
|
||||
|
|
|
@ -70,7 +70,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|||
key: "id",
|
||||
type: "number",
|
||||
column: {
|
||||
width: 100
|
||||
width: 80
|
||||
},
|
||||
form: {
|
||||
show: false
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { request } from "/src/api/service";
|
||||
|
||||
export function createApi() {
|
||||
const apiPrefix = "/monitor/cert";
|
||||
return {
|
||||
export const certInfoApi = {
|
||||
async GetList(query: any) {
|
||||
return await request({
|
||||
url: apiPrefix + "/page",
|
||||
|
@ -47,8 +46,12 @@ export function createApi() {
|
|||
url: apiPrefix + "/all",
|
||||
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
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud";
|
||||
import { pipelineGroupApi } from "./api";
|
||||
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, useFormWrapper, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud";
|
||||
import { certInfoApi } from "./api";
|
||||
import dayjs from "dayjs";
|
||||
import { useUserStore } from "/@/store/modules/user";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
||||
const { t } = useI18n();
|
||||
const api = pipelineGroupApi;
|
||||
const api = certInfoApi;
|
||||
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
||||
return await api.GetList(query);
|
||||
};
|
||||
|
@ -26,7 +28,8 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|||
const res = await api.AddObj(form);
|
||||
return res;
|
||||
};
|
||||
|
||||
const { openCrudFormDialog } = useFormWrapper();
|
||||
const router = useRouter();
|
||||
return {
|
||||
crudOptions: {
|
||||
request: {
|
||||
|
@ -50,7 +53,67 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|||
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: {
|
||||
width: 200,
|
||||
fixed: "right",
|
||||
|
@ -176,7 +239,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|||
}
|
||||
},
|
||||
"pipeline.title": {
|
||||
title: "已关联流水线",
|
||||
title: "关联流水线",
|
||||
search: { show: false },
|
||||
type: "link",
|
||||
form: {
|
||||
|
@ -185,7 +248,13 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
|||
column: {
|
||||
width: 350,
|
||||
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);
|
||||
}
|
||||
|
||||
@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() {
|
||||
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 { BaseService, CodeException, Constants, PageReq } from '@certd/lib-server';
|
||||
import { BaseService, CodeException, CommonException, Constants, PageReq } from '@certd/lib-server';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CertInfoEntity } from '../entity/cert-info.js';
|
||||
import { utils } from '@certd/basic';
|
||||
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||
|
||||
export type UploadCertReq = {
|
||||
id?: number;
|
||||
certReader: CertReader;
|
||||
fromType?: string;
|
||||
};
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
|
@ -125,15 +131,27 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
|||
return certReader.toCertInfo();
|
||||
}
|
||||
|
||||
async updateCert(pipelineId: number, certReader: CertReader) {
|
||||
async updateCertByPipelineId(pipelineId: number, certReader: CertReader, fromType = 'pipeline') {
|
||||
const found = await this.repository.findOne({
|
||||
where: {
|
||||
pipelineId,
|
||||
},
|
||||
});
|
||||
const bean = await this.updateCert({
|
||||
id: found?.id,
|
||||
certReader,
|
||||
fromType,
|
||||
});
|
||||
return bean;
|
||||
}
|
||||
|
||||
private async updateCert(req: UploadCertReq) {
|
||||
const bean = new CertInfoEntity();
|
||||
if (found) {
|
||||
bean.id = found.id;
|
||||
const { id, fromType, certReader } = req;
|
||||
if (id) {
|
||||
bean.id = id;
|
||||
} else {
|
||||
bean.fromType = fromType;
|
||||
}
|
||||
const certInfo = certReader.toCertInfo();
|
||||
bean.certInfo = JSON.stringify(certInfo);
|
||||
|
@ -146,5 +164,19 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
|||
bean.certProvider = certReader.detail.issuer.commonName;
|
||||
|
||||
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