mirror of https://github.com/certd/certd
perf: cname校验配置增加未校验通过提示
parent
8f79107d2b
commit
77cc3c4a5c
|
@ -10,6 +10,7 @@ export type CnameRecord = {
|
|||
hostRecord: string;
|
||||
recordValue: string;
|
||||
cnameProvider: CnameProvider;
|
||||
status: string;
|
||||
};
|
||||
export type ICnameProxyService = {
|
||||
getByDomain: (domain: string) => Promise<CnameRecord>;
|
||||
|
|
|
@ -100,6 +100,7 @@ export class CertApplyPlugin extends CertApplyBasePlugin {
|
|||
component: {
|
||||
name: "domains-verify-plan-editor",
|
||||
},
|
||||
rules: [{ type: "checkCnameVerifyPlan" }],
|
||||
required: true,
|
||||
helper: "如果选择CNAME方式,请按照上面的显示,给域名添加CNAME记录,添加后,点击验证,验证成功后不要删除记录,申请和续期证书会一直用它",
|
||||
col: {
|
||||
|
|
|
@ -77,21 +77,12 @@ import { dict, FsDictSelect } from "@fast-crud/fast-crud";
|
|||
import AccessSelector from "/@/views/certd/access/access-selector/index.vue";
|
||||
import CnameVerifyPlan from "./cname-verify-plan.vue";
|
||||
import psl from "psl";
|
||||
import { Form } from "ant-design-vue";
|
||||
import { DomainsVerifyPlanInput } from "./type";
|
||||
defineOptions({
|
||||
name: "DomainsVerifyPlanEditor"
|
||||
});
|
||||
|
||||
type DomainVerifyPlanInput = {
|
||||
domain: string;
|
||||
type: "cname" | "dns";
|
||||
dnsProviderType?: string;
|
||||
dnsProviderAccessId?: number;
|
||||
cnameVerifyPlan?: Record<string, CnameRecord>;
|
||||
};
|
||||
type DomainsVerifyPlanInput = {
|
||||
[key: string]: DomainVerifyPlanInput;
|
||||
};
|
||||
|
||||
const challengeTypeOptions = ref<any[]>([
|
||||
{
|
||||
label: "DNS验证",
|
||||
|
@ -122,8 +113,12 @@ const planRef = ref<DomainsVerifyPlanInput>(props.modelValue || {});
|
|||
const dnsProviderTypeDict = dict({
|
||||
url: "pi/dnsProvider/dnsProviderTypeDict"
|
||||
});
|
||||
|
||||
const formItemContext = Form.useInjectFormItemContext();
|
||||
function onPlanChanged() {
|
||||
console.log("plan changed", planRef.value);
|
||||
emit("update:modelValue", planRef.value);
|
||||
formItemContext.onFieldChange();
|
||||
}
|
||||
|
||||
const errorMessageRef = ref<string>("");
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import { CnameRecord } from "@certd/pipeline";
|
||||
|
||||
export type DomainVerifyPlanInput = {
|
||||
domain: string;
|
||||
type: "cname" | "dns";
|
||||
dnsProviderType?: string;
|
||||
dnsProviderAccessId?: number;
|
||||
cnameVerifyPlan?: Record<string, CnameRecord>;
|
||||
};
|
||||
export type DomainsVerifyPlanInput = {
|
||||
[key: string]: DomainVerifyPlanInput;
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
import Validator from "async-validator";
|
||||
import { DomainsVerifyPlanInput } from "./type";
|
||||
|
||||
function checkCnameVerifyPlan(rule, value: DomainsVerifyPlanInput) {
|
||||
debugger;
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
for (const domain in value) {
|
||||
if (value[domain].type === "cname") {
|
||||
const subDomains = Object.keys(value[domain].cnameVerifyPlan);
|
||||
if (subDomains.length > 0) {
|
||||
for (const subDomain of subDomains) {
|
||||
const plan = value[domain].cnameVerifyPlan[subDomain];
|
||||
if (plan.status !== "valid") {
|
||||
throw new Error(`域名${subDomain}的CNAME未验证通过,请先设置CNAME记录,点击验证按钮`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (value[domain].dnsProviderType == null || value[domain].dnsProviderAccessId == null) {
|
||||
throw new Error(`DNS模式下,域名${domain}的DNS类型和授权信息必须填写`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// 注册自定义验证器
|
||||
Validator.register("checkCnameVerifyPlan", checkCnameVerifyPlan);
|
|
@ -0,0 +1 @@
|
|||
export * from "./domains-verify-plan-editor/validator.js";
|
|
@ -5,7 +5,7 @@ import OutputSelector from "/@/components/plugins/common/output-selector/index.v
|
|||
import DnsProviderSelector from "/@/components/plugins/cert/dns-provider-selector/index.vue";
|
||||
import DomainsVerifyPlanEditor from "/@/components/plugins/cert/domains-verify-plan-editor/index.vue";
|
||||
import AccessSelector from "/@/views/certd/access/access-selector/index.vue";
|
||||
|
||||
export * from "./cert/index.js";
|
||||
export default {
|
||||
install(app: any) {
|
||||
app.component("OutputSelector", OutputSelector);
|
||||
|
|
Loading…
Reference in New Issue