mirror of https://github.com/certd/certd
chore:
parent
d558d50102
commit
fedf90ea78
|
@ -82,7 +82,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
add: {
|
add: {
|
||||||
text: "上传自定义证书",
|
text: "上传自定义证书",
|
||||||
type: "primary",
|
type: "primary",
|
||||||
show: true,
|
show: false,
|
||||||
async click() {
|
async click() {
|
||||||
await openUploadCreateDialog();
|
await openUploadCreateDialog();
|
||||||
},
|
},
|
||||||
|
@ -116,9 +116,11 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
order: 4,
|
order: 4,
|
||||||
title: "更新证书",
|
title: "更新证书",
|
||||||
type: "link",
|
type: "link",
|
||||||
icon: "ph:upload",
|
icon: "ion:upload",
|
||||||
async click({ row }) {
|
async click({ row }) {
|
||||||
await openUpdateCertDialog(row.id);
|
await openUpdateCertDialog({
|
||||||
|
id: row.id,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
remove: {
|
remove: {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="cert-info-updater w-full flex items-center">
|
<div class="cert-info-updater w-full flex items-center">
|
||||||
<div class="flex-o">
|
<div class="flex-o">
|
||||||
<fs-values-format :model-value="modelValue" :dict="certInfoDict" />
|
<fs-values-format :model-value="modelValue" :dict="certInfoDict" />
|
||||||
<fs-button v-if="modelValue" type="primary" size="small" class="ml-1" icon="ion:upload" text="更新证书" @click="onUploadClick" />
|
<fs-button type="primary" size="small" class="ml-1" icon="ion:upload" text="更新证书" @click="onUploadClick" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -24,7 +24,7 @@ const props = defineProps<{
|
||||||
size?: string;
|
size?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}>();
|
}>();
|
||||||
const emit = defineEmits(["updated"]);
|
const emit = defineEmits(["updated", "update:modelValue"]);
|
||||||
|
|
||||||
const certInfoDict = dict({
|
const certInfoDict = dict({
|
||||||
value: "id",
|
value: "id",
|
||||||
|
@ -42,10 +42,19 @@ const certInfoDict = dict({
|
||||||
|
|
||||||
const { openUpdateCertDialog } = useCertUpload();
|
const { openUpdateCertDialog } = useCertUpload();
|
||||||
function onUpdated(res: any) {
|
function onUpdated(res: any) {
|
||||||
|
if (!props.modelValue) {
|
||||||
|
emit("update:modelValue", res.id);
|
||||||
|
}
|
||||||
emit("updated", res);
|
emit("updated", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pipeline: any = inject("pipeline");
|
||||||
function onUploadClick() {
|
function onUploadClick() {
|
||||||
openUpdateCertDialog(props.modelValue, onUpdated);
|
openUpdateCertDialog({
|
||||||
|
id: props.modelValue,
|
||||||
|
pipelineId: pipeline.id,
|
||||||
|
onSubmit: onUpdated,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
|
|
@ -161,7 +161,7 @@ export function useCertUpload() {
|
||||||
wrapperRef.value = wrapper;
|
wrapperRef.value = wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openUpdateCertDialog(id: any, onSubmit?: any) {
|
async function openUpdateCertDialog(opts: { id?: any; onSubmit?: any; pipelineId?: any }) {
|
||||||
function createCrudOptions() {
|
function createCrudOptions() {
|
||||||
return {
|
return {
|
||||||
crudOptions: {
|
crudOptions: {
|
||||||
|
@ -204,14 +204,18 @@ export function useCertUpload() {
|
||||||
title: "更新证书",
|
title: "更新证书",
|
||||||
saveRemind: false,
|
saveRemind: false,
|
||||||
},
|
},
|
||||||
|
async afterSubmit() {
|
||||||
|
notification.success({ message: "更新成功" });
|
||||||
|
},
|
||||||
async doSubmit({ form }: any) {
|
async doSubmit({ form }: any) {
|
||||||
const req = {
|
const req = {
|
||||||
id: id,
|
id: opts.id,
|
||||||
|
pipelineId: opts.pipelineId,
|
||||||
cert: form.cert,
|
cert: form.cert,
|
||||||
};
|
};
|
||||||
const res = await api.UploadCert(req);
|
const res = await api.UploadCert(req);
|
||||||
if (onSubmit) {
|
if (opts.onSubmit) {
|
||||||
await onSubmit(res);
|
await opts.onSubmit(res);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { doRequest } from "/@/components/plugins/lib";
|
||||||
import { ref, useAttrs, inject } from "vue";
|
import { ref, useAttrs, inject } from "vue";
|
||||||
import { useFormWrapper } from "@fast-crud/fast-crud";
|
import { useFormWrapper } from "@fast-crud/fast-crud";
|
||||||
import { notification } from "ant-design-vue";
|
import { notification } from "ant-design-vue";
|
||||||
import { merge } from "lodash-es";
|
import { mergeWith, isArray } from "lodash-es";
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "TaskShortcut",
|
name: "TaskShortcut",
|
||||||
});
|
});
|
||||||
|
@ -112,9 +112,9 @@ const doPluginFormSubmit = async (formData: any) => {
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
.task-shortcut {
|
.task-shortcut {
|
||||||
width: 25px;
|
width: 25px;
|
||||||
height: 25px;
|
height: 22px;
|
||||||
border: 1px solid #e3e3e3;
|
border: 1px solid #e3e3e3;
|
||||||
border-radius: 0 0 6px 6px;
|
border-radius: 0 0 5px 5px;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
|
@ -1091,7 +1091,7 @@ export default defineComponent({
|
||||||
position: relative;
|
position: relative;
|
||||||
.shortcut {
|
.shortcut {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: -15px;
|
bottom: -10px;
|
||||||
left: 20px;
|
left: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ export type UploadCertReq = {
|
||||||
certReader: CertReader;
|
certReader: CertReader;
|
||||||
fromType?: string;
|
fromType?: string;
|
||||||
userId?: number;
|
userId?: number;
|
||||||
|
pipelineId?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpdateCertReq = {
|
export type UpdateCertReq = {
|
||||||
|
@ -25,6 +26,7 @@ export type UpdateCertReq = {
|
||||||
export type CreateUploadPipelineReq = {
|
export type CreateUploadPipelineReq = {
|
||||||
cert: CertInfo;
|
cert: CertInfo;
|
||||||
userId: number;
|
userId: number;
|
||||||
|
pipelineId?: number;
|
||||||
pipeline?:{
|
pipeline?:{
|
||||||
input?:any;
|
input?:any;
|
||||||
notifications?:any[]
|
notifications?:any[]
|
||||||
|
@ -85,77 +87,84 @@ export class CertUploadService extends BaseService<CertInfoEntity> {
|
||||||
}
|
}
|
||||||
const certReader = new CertReader(cert)
|
const certReader = new CertReader(cert)
|
||||||
return await this.transaction(async (tx:EntityManager)=>{
|
return await this.transaction(async (tx:EntityManager)=>{
|
||||||
|
let pipelineId = body.pipelineId;
|
||||||
const newCertInfo = await this.uploadCert(tx,{
|
const newCertInfo = await this.uploadCert(tx,{
|
||||||
certReader: certReader,
|
certReader: certReader,
|
||||||
fromType: 'upload',
|
fromType: 'upload',
|
||||||
userId
|
|
||||||
});
|
|
||||||
|
|
||||||
const pipelineTitle = certReader.getAllDomains()[0] +"上传证书自动部署";
|
|
||||||
const notifications = body.pipeline?.notifications ||[];
|
|
||||||
if(notifications.length === 0){
|
|
||||||
notifications.push({
|
|
||||||
type: "custom",
|
|
||||||
when: ["error", "turnToSuccess", "success"],
|
|
||||||
notificationId: 0,
|
|
||||||
title: "默认通知",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let pipeline = {
|
|
||||||
title: pipelineTitle,
|
|
||||||
runnableType: "pipeline",
|
|
||||||
stages: [
|
|
||||||
{
|
|
||||||
id: nanoid(10),
|
|
||||||
title: "上传证书解析阶段",
|
|
||||||
maxTaskCount: 1,
|
|
||||||
runnableType: "stage",
|
|
||||||
tasks: [
|
|
||||||
{
|
|
||||||
id: nanoid(10),
|
|
||||||
title: "上传证书解析转换",
|
|
||||||
runnableType: "task",
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
id: nanoid(10),
|
|
||||||
title: "上传证书解析转换",
|
|
||||||
runnableType: "step",
|
|
||||||
input: {
|
|
||||||
certInfoId: newCertInfo.id,
|
|
||||||
domains: newCertInfo.domains.split(','),
|
|
||||||
...body.pipeline?.input
|
|
||||||
},
|
|
||||||
strategy: {
|
|
||||||
runStrategy: 0, // 正常执行
|
|
||||||
},
|
|
||||||
type: "CertApplyUpload",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
triggers:[],
|
|
||||||
notifications,
|
|
||||||
}
|
|
||||||
const newPipeline = await tx.getRepository(PipelineEntity).save({
|
|
||||||
userId,
|
userId,
|
||||||
title: pipelineTitle,
|
pipelineId
|
||||||
type:"cert_upload",
|
|
||||||
content: JSON.stringify(pipeline),
|
|
||||||
keepHistory:20,
|
|
||||||
})
|
|
||||||
|
|
||||||
newCertInfo.pipelineId = newPipeline.id;
|
|
||||||
await tx.getRepository(CertInfoEntity).save({
|
|
||||||
id: newCertInfo.id,
|
|
||||||
pipelineId: newPipeline.id
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(!pipelineId){
|
||||||
|
const pipelineTitle = certReader.getAllDomains()[0] +"上传证书自动部署";
|
||||||
|
const notifications = body.pipeline?.notifications ||[];
|
||||||
|
if(notifications.length === 0){
|
||||||
|
notifications.push({
|
||||||
|
type: "custom",
|
||||||
|
when: ["error", "turnToSuccess", "success"],
|
||||||
|
notificationId: 0,
|
||||||
|
title: "默认通知",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let pipeline = {
|
||||||
|
title: pipelineTitle,
|
||||||
|
runnableType: "pipeline",
|
||||||
|
stages: [
|
||||||
|
{
|
||||||
|
id: nanoid(10),
|
||||||
|
title: "上传证书解析阶段",
|
||||||
|
maxTaskCount: 1,
|
||||||
|
runnableType: "stage",
|
||||||
|
tasks: [
|
||||||
|
{
|
||||||
|
id: nanoid(10),
|
||||||
|
title: "上传证书解析转换",
|
||||||
|
runnableType: "task",
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
id: nanoid(10),
|
||||||
|
title: "上传证书解析转换",
|
||||||
|
runnableType: "step",
|
||||||
|
input: {
|
||||||
|
certInfoId: newCertInfo.id,
|
||||||
|
domains: newCertInfo.domains.split(','),
|
||||||
|
...body.pipeline?.input
|
||||||
|
},
|
||||||
|
strategy: {
|
||||||
|
runStrategy: 0, // 正常执行
|
||||||
|
},
|
||||||
|
type: "CertApplyUpload",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
triggers:[],
|
||||||
|
notifications,
|
||||||
|
}
|
||||||
|
const newPipeline = await tx.getRepository(PipelineEntity).save({
|
||||||
|
userId,
|
||||||
|
title: pipelineTitle,
|
||||||
|
type:"cert_upload",
|
||||||
|
content: JSON.stringify(pipeline),
|
||||||
|
keepHistory:20,
|
||||||
|
})
|
||||||
|
|
||||||
|
newCertInfo.pipelineId = newPipeline.id;
|
||||||
|
await tx.getRepository(CertInfoEntity).save({
|
||||||
|
id: newCertInfo.id,
|
||||||
|
pipelineId: newPipeline.id
|
||||||
|
});
|
||||||
|
|
||||||
|
pipelineId = newPipeline.id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id:newCertInfo.id,
|
id:newCertInfo.id,
|
||||||
pipelineId: newPipeline.id,
|
pipelineId: pipelineId,
|
||||||
domains: newCertInfo.domains.split(','),
|
domains: newCertInfo.domains.split(','),
|
||||||
fromType: newCertInfo.fromType,
|
fromType: newCertInfo.fromType,
|
||||||
updateTime: newCertInfo.updateTime,
|
updateTime: newCertInfo.updateTime,
|
||||||
|
@ -183,7 +192,9 @@ export class CertUploadService extends BaseService<CertInfoEntity> {
|
||||||
bean.domainCount = domains.length;
|
bean.domainCount = domains.length;
|
||||||
bean.expiresTime = certReader.expires;
|
bean.expiresTime = certReader.expires;
|
||||||
bean.certProvider = certReader.detail.issuer.commonName;
|
bean.certProvider = certReader.detail.issuer.commonName;
|
||||||
|
if (req.pipelineId){
|
||||||
|
bean.pipelineId = req.pipelineId;
|
||||||
|
}
|
||||||
|
|
||||||
await tx.getRepository(CertInfoEntity).save(bean);
|
await tx.getRepository(CertInfoEntity).save(bean);
|
||||||
return bean;
|
return bean;
|
||||||
|
|
Loading…
Reference in New Issue