mirror of
https://github.com/certd/certd.git
synced 2026-04-24 20:57:26 +08:00
perf: 1panel支持先上传证书再选择证书
This commit is contained in:
@@ -7,6 +7,9 @@ import { ILogger } from "@certd/basic";
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { uniq } from "lodash-es";
|
import { uniq } from "lodash-es";
|
||||||
|
|
||||||
|
export interface ICertInfoGetter {
|
||||||
|
getByPipelineId: (pipelineId: number) => Promise<CertInfo>;
|
||||||
|
}
|
||||||
export type CertInfo = {
|
export type CertInfo = {
|
||||||
crt: string; //fullchain证书
|
crt: string; //fullchain证书
|
||||||
key: string; //私钥
|
key: string; //私钥
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
export const CertApplyPluginNames = [":cert:"];
|
export const CertApplyPluginNames = [":cert:"];
|
||||||
export const EVENT_CERT_APPLY_SUCCESS = "CertApply.success";
|
export const EVENT_CERT_APPLY_SUCCESS = "CertApply.success";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export * from "./convert.js";
|
export * from "./convert.js";
|
||||||
export * from "./cert-reader.js";
|
export * from "./cert-reader.js";
|
||||||
export * from "./consts.js";
|
export * from "./consts.js";
|
||||||
export * from "./dns-provider/index.js";
|
export * from "./dns-provider/index.js";
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ export function createRemoteSelectInputDefine(opts?: {
|
|||||||
component?: any;
|
component?: any;
|
||||||
value?: any;
|
value?: any;
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
|
uploadCert?: {
|
||||||
|
title?: string;
|
||||||
|
columns?: Record<string, any>;
|
||||||
|
};
|
||||||
}) {
|
}) {
|
||||||
const title = opts?.title || "请选择";
|
const title = opts?.title || "请选择";
|
||||||
const certDomainsInputKey = opts?.certDomainsInputKey || "certDomains";
|
const certDomainsInputKey = opts?.certDomainsInputKey || "certDomains";
|
||||||
@@ -74,6 +78,7 @@ export function createRemoteSelectInputDefine(opts?: {
|
|||||||
multi,
|
multi,
|
||||||
pageSize: opts?.pageSize,
|
pageSize: opts?.pageSize,
|
||||||
watches: [certDomainsInputKey, accessIdInputKey, ...watches],
|
watches: [certDomainsInputKey, accessIdInputKey, ...watches],
|
||||||
|
uploadCert: opts?.uploadCert,
|
||||||
...opts.component,
|
...opts.component,
|
||||||
},
|
},
|
||||||
value: opts.value,
|
value: opts.value,
|
||||||
|
|||||||
@@ -25,8 +25,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</a-select>
|
</a-select>
|
||||||
<div class="ml-5">
|
<div class="ml-5 flex flex-row no-wrap">
|
||||||
<fs-button :loading="loading" title="刷新选项" icon="ion:refresh-outline" @click="refreshOptions"></fs-button>
|
<fs-button :loading="loading" title="刷新选项" icon="ion:refresh-outline" @click="refreshOptions"></fs-button>
|
||||||
|
<UploadCert v-if="uploadCert" class="ml-5" v-bind="uploadCert" @submit="refreshOptions"></UploadCert>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="helper" :class="{ error: hasError }">
|
<div class="helper" :class="{ error: hasError }">
|
||||||
@@ -39,6 +40,8 @@ import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
|||||||
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
|
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
|
||||||
import { PluginDefine } from "@certd/pipeline";
|
import { PluginDefine } from "@certd/pipeline";
|
||||||
import { getInputFromForm } from "./utils";
|
import { getInputFromForm } from "./utils";
|
||||||
|
import UploadCert from "./upload-cert.vue";
|
||||||
|
import { UploadCertProps } from "./types";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "RemoteSelect",
|
name: "RemoteSelect",
|
||||||
@@ -65,9 +68,10 @@ const props = defineProps<
|
|||||||
pager?: boolean;
|
pager?: boolean;
|
||||||
multi?: boolean;
|
multi?: boolean;
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
|
uploadCert?: UploadCertProps;
|
||||||
} & ComponentPropsType
|
} & ComponentPropsType
|
||||||
>();
|
>();
|
||||||
|
debugger;
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
"update:value": any;
|
"update:value": any;
|
||||||
}>();
|
}>();
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export interface UploadCertProps {
|
||||||
|
title?: string;
|
||||||
|
columns?: Record<string, any>;
|
||||||
|
button?: any;
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
<template>
|
||||||
|
<div class="upload-cert">
|
||||||
|
<fs-button v-model:loading="loading" type="primary" text="上传" v-bind="props.button" @click="openUploadCertDialog"></fs-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { message } from "ant-design-vue";
|
||||||
|
import { useFormDialog } from "../../../use/use-dialog";
|
||||||
|
import { computed, inject, ref } from "vue";
|
||||||
|
import { doRequest } from "../lib";
|
||||||
|
import { getInputFromForm } from "./utils";
|
||||||
|
import { UploadCertProps } from "./types";
|
||||||
|
import { merge } from "lodash-es";
|
||||||
|
|
||||||
|
const props = defineProps<UploadCertProps>();
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const emit = defineEmits(["submit"]);
|
||||||
|
const { openFormDialog } = useFormDialog();
|
||||||
|
const pipeline = inject("pipeline", null);
|
||||||
|
|
||||||
|
const getCurrentPluginDefine: any = inject("getCurrentPluginDefine", () => {
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
const getScope: any = inject("get:scope", () => {
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
const getPluginType: any = inject("get:plugin:type", () => {
|
||||||
|
return "plugin";
|
||||||
|
});
|
||||||
|
const title = computed(() => props.title || "上传证书");
|
||||||
|
function openUploadCertDialog() {
|
||||||
|
const columns = merge(
|
||||||
|
{
|
||||||
|
certName: {
|
||||||
|
title: "证书名称",
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
name: "a-input",
|
||||||
|
vModel: "value",
|
||||||
|
},
|
||||||
|
helper: "上传后证书显示名称",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
props.columns
|
||||||
|
);
|
||||||
|
openFormDialog({
|
||||||
|
title: title.value,
|
||||||
|
columns: {
|
||||||
|
certName: {
|
||||||
|
title: "证书名称",
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
name: "a-input",
|
||||||
|
vModel: "value",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...props.columns,
|
||||||
|
},
|
||||||
|
onSubmit: async (form: any) => {
|
||||||
|
const pluginType = getPluginType();
|
||||||
|
const scope = getScope();
|
||||||
|
const { input, record } = getInputFromForm(scope.form, pluginType);
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const res = await doRequest(
|
||||||
|
{
|
||||||
|
type: pluginType,
|
||||||
|
typeName: scope.form.type,
|
||||||
|
action: "onUploadCert",
|
||||||
|
input,
|
||||||
|
record,
|
||||||
|
data: {
|
||||||
|
pipelineId: pipeline?.value?.id,
|
||||||
|
...form,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// onError(err: any) {
|
||||||
|
// message.error(err.message);
|
||||||
|
// },
|
||||||
|
showErrorNotify: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
message.success("上传成功");
|
||||||
|
emit("submit");
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="less">
|
||||||
|
.upload-cert {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { CertInfo, CertReader, ICertInfoGetter } from '@certd/plugin-lib';
|
||||||
|
import { CertInfoService } from '../../../monitor/index.js';
|
||||||
|
|
||||||
|
export class CertInfoGetter implements ICertInfoGetter {
|
||||||
|
userId: number;
|
||||||
|
projectId: number;
|
||||||
|
certInfoService: CertInfoService;
|
||||||
|
constructor(userId: number, projectId: number, certInfoService: CertInfoService) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.projectId = projectId;
|
||||||
|
this.certInfoService = certInfoService;
|
||||||
|
}
|
||||||
|
async getByPipelineId(pipelineId: number): Promise<CertInfo> {
|
||||||
|
if (!pipelineId) {
|
||||||
|
throw new Error(`流水线id不能为空`)
|
||||||
|
}
|
||||||
|
const query :any= {
|
||||||
|
pipelineId,
|
||||||
|
userId: this.userId,
|
||||||
|
}
|
||||||
|
if (this.projectId) {
|
||||||
|
query.projectId = this.projectId
|
||||||
|
}
|
||||||
|
const entity = await this.certInfoService.findOne({
|
||||||
|
where:query
|
||||||
|
})
|
||||||
|
if (!entity || !entity.certInfo) {
|
||||||
|
throw new Error(`流水线(${pipelineId})还未生成证书,请先运行一次流水线`)
|
||||||
|
}
|
||||||
|
return new CertReader(JSON.parse(entity.certInfo)).cert;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,9 @@ import { SubDomainsGetter } from "./sub-domain-getter.js";
|
|||||||
import { DomainVerifierGetter } from "./domain-verifier-getter.js";
|
import { DomainVerifierGetter } from "./domain-verifier-getter.js";
|
||||||
import { DomainService } from "../../../cert/service/domain-service.js";
|
import { DomainService } from "../../../cert/service/domain-service.js";
|
||||||
import { SubDomainService } from "../sub-domain-service.js";
|
import { SubDomainService } from "../sub-domain-service.js";
|
||||||
|
import { CertInfoGetter } from "./cert-info-getter.js";
|
||||||
|
import { CertInfoService } from "../../../monitor/index.js";
|
||||||
|
import { ICertInfoGetter } from "@certd/plugin-lib";
|
||||||
|
|
||||||
const serviceNames = [
|
const serviceNames = [
|
||||||
'ocrService',
|
'ocrService',
|
||||||
@@ -34,6 +37,8 @@ export class TaskServiceGetter implements IServiceGetter{
|
|||||||
return await this.getNotificationService() as T
|
return await this.getNotificationService() as T
|
||||||
} else if (serviceName === 'domainVerifierGetter') {
|
} else if (serviceName === 'domainVerifierGetter') {
|
||||||
return await this.getDomainVerifierGetter() as T
|
return await this.getDomainVerifierGetter() as T
|
||||||
|
} else if (serviceName === 'certInfoGetter') {
|
||||||
|
return await this.getCertInfoGetter() as T
|
||||||
}else{
|
}else{
|
||||||
if(!serviceNames.includes(serviceName)){
|
if(!serviceNames.includes(serviceName)){
|
||||||
throw new Error(`${serviceName} not in whitelist`)
|
throw new Error(`${serviceName} not in whitelist`)
|
||||||
@@ -51,6 +56,11 @@ export class TaskServiceGetter implements IServiceGetter{
|
|||||||
return new SubDomainsGetter(this.userId,this.projectId, subDomainsService,domainService)
|
return new SubDomainsGetter(this.userId,this.projectId, subDomainsService,domainService)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getCertInfoGetter(): Promise<ICertInfoGetter> {
|
||||||
|
const certInfoService:CertInfoService = await this.appCtx.getAsync("certInfoService")
|
||||||
|
return new CertInfoGetter(this.userId, this.projectId, certInfoService)
|
||||||
|
}
|
||||||
|
|
||||||
async getAccessService(): Promise<AccessGetter> {
|
async getAccessService(): Promise<AccessGetter> {
|
||||||
const accessService:AccessService = await this.appCtx.getAsync("accessService")
|
const accessService:AccessService = await this.appCtx.getAsync("accessService")
|
||||||
return new AccessGetter(this.userId, this.projectId, accessService.getById.bind(accessService));
|
return new AccessGetter(this.userId, this.projectId, accessService.getById.bind(accessService));
|
||||||
|
|||||||
+33
-1
@@ -2,7 +2,7 @@ import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput
|
|||||||
|
|
||||||
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
||||||
import { OnePanelAccess } from "../access.js";
|
import { OnePanelAccess } from "../access.js";
|
||||||
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib";
|
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine, ICertInfoGetter } from "@certd/plugin-lib";
|
||||||
import { OnePanelClient } from "../client.js";
|
import { OnePanelClient } from "../client.js";
|
||||||
|
|
||||||
@IsTaskPlugin({
|
@IsTaskPlugin({
|
||||||
@@ -66,6 +66,7 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
|
|||||||
watches: ["accessId"],
|
watches: ["accessId"],
|
||||||
helper: "要更新的1Panel证书id,选择授权之后,从下拉框中选择\nIP需要加白名单,如果是同一台机器部署的,可以试试172.16.0.0/12",
|
helper: "要更新的1Panel证书id,选择授权之后,从下拉框中选择\nIP需要加白名单,如果是同一台机器部署的,可以试试172.16.0.0/12",
|
||||||
required: true,
|
required: true,
|
||||||
|
uploadCert: {}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
sslIds!: string[];
|
sslIds!: string[];
|
||||||
@@ -213,5 +214,36 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
|
|||||||
});
|
});
|
||||||
return this.ctx.utils.options.buildGroupOptions(list, this.certDomains);
|
return this.ctx.utils.options.buildGroupOptions(list, this.certDomains);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async onUploadCert(data: { pipelineId: string, certName: string }) {
|
||||||
|
if (!this.access) {
|
||||||
|
throw new Error("请先选择1panel授权");
|
||||||
|
}
|
||||||
|
const certInfoGetter = await this.ctx.serviceGetter.get<ICertInfoGetter>("certInfoGetter")
|
||||||
|
const cert = await certInfoGetter.getByPipelineId(Number(data.pipelineId));
|
||||||
|
|
||||||
|
const client = new OnePanelClient({
|
||||||
|
access: this.access,
|
||||||
|
http: this.http,
|
||||||
|
logger: this.logger,
|
||||||
|
utils: this.ctx.utils,
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.doRequest({
|
||||||
|
url: `/api/${this.access.apiVersion}/websites/ssl/upload`,
|
||||||
|
method: "post",
|
||||||
|
data: {
|
||||||
|
sslId: 0,
|
||||||
|
certificate: cert.crt,
|
||||||
|
certificatePath: "",
|
||||||
|
description: data.certName,
|
||||||
|
privateKey: cert.key,
|
||||||
|
privateKeyPath: "",
|
||||||
|
type: "paste",
|
||||||
|
},
|
||||||
|
currentNode: this.currentNode,
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
new OnePanelDeployToWebsitePlugin();
|
new OnePanelDeployToWebsitePlugin();
|
||||||
|
|||||||
Reference in New Issue
Block a user