diff --git a/docs/guide/use/aliyun/index.md b/docs/guide/use/aliyun/index.md new file mode 100644 index 00000000..a73b1c5a --- /dev/null +++ b/docs/guide/use/aliyun/index.md @@ -0,0 +1,11 @@ +# 阿里云相关 + + +## 阿里云客户端请求超时配置 + +配置环境变量 +```shell +ALIYUN_CLIENT_CONNECT_TIMEOUT=10000 # 连接超时,单位毫秒 +ALIYUN_CLIENT_READ_TIMEOUT=10000 #读取数据超时,单位毫秒 + +``` \ No newline at end of file diff --git a/packages/core/basic/src/utils/index.ts b/packages/core/basic/src/utils/index.ts index d3b9c001..1d9abbd6 100644 --- a/packages/core/basic/src/utils/index.ts +++ b/packages/core/basic/src/utils/index.ts @@ -17,6 +17,8 @@ import { fileUtils } from './util.file.js'; import * as _ from 'lodash-es'; import { cache } from './util.cache.js'; import dayjs from 'dayjs'; +import { domainUtils } from './util.domain.js'; +import { optionsUtils } from './util.options.js'; export const utils = { sleep, @@ -30,4 +32,6 @@ export const utils = { cache, nanoid, dayjs, + domain: domainUtils, + options: optionsUtils, }; diff --git a/packages/core/basic/src/utils/util.domain.ts b/packages/core/basic/src/utils/util.domain.ts new file mode 100644 index 00000000..75907083 --- /dev/null +++ b/packages/core/basic/src/utils/util.domain.ts @@ -0,0 +1,51 @@ +//域名是否匹配,支持通配符 +function match(targetDomains: string | string[], inDomains: string[]) { + if (!targetDomains || targetDomains.length == 0) { + return false; + } + if (!inDomains || inDomains.length == 0) { + return false; + } + + if (typeof targetDomains === 'string') { + targetDomains = [targetDomains]; + } + for (let targetDomain of targetDomains) { + let matched = false; + if (targetDomain.startsWith('.')) { + targetDomain = '*' + targetDomain; + } + for (let inDomain of inDomains) { + if (inDomain.startsWith('.')) { + inDomain = '*' + inDomain; + } + if (targetDomain === inDomain) { + matched = true; + break; + } + + if (!inDomain.startsWith('*.')) { + //不可能匹配 + break; + } + //子域名匹配通配符即可 + if (targetDomain === inDomain.substring(2)) { + matched = true; + break; + } + } + //有一个没有匹配上,就失败 + if (matched) { + //这个匹配上了,检查下一个 + break; + } else { + return false; + } + } + //没有提前return 全部匹配上了 + return true; +} + +export const domainUtils = { + match, +}; diff --git a/packages/core/basic/src/utils/util.options.ts b/packages/core/basic/src/utils/util.options.ts new file mode 100644 index 00000000..f5a0097e --- /dev/null +++ b/packages/core/basic/src/utils/util.options.ts @@ -0,0 +1,42 @@ +import { domainUtils } from './util.domain.js'; + +function groupByDomain(options: any[], inDomains: string[]) { + const matched = []; + const notMatched = []; + for (const item of options) { + if (domainUtils.match(item.domain, inDomains)) { + matched.push(item); + } else { + notMatched.push(item); + } + } + return { + matched, + notMatched, + }; +} + +function buildGroupOptions(options: any[], inDomains: string[]) { + const grouped = groupByDomain(options, inDomains); + const groupOptions = []; + groupOptions.push({ value: '', disabled: true, label: '----已匹配----' }); + if (grouped.matched.length === 0) { + options.push({ value: '', disabled: true, label: '没有可以匹配的域名' }); + } else { + for (const matched of grouped.matched) { + groupOptions.push(matched); + } + } + if (grouped.notMatched.length > 0) { + groupOptions.push({ value: '', disabled: true, label: '----未匹配----' }); + for (const notMatched of grouped.notMatched) { + groupOptions.push(notMatched); + } + } + return groupOptions; +} + +export const optionsUtils = { + groupByDomain, + buildGroupOptions, +}; diff --git a/packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue b/packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue index 918ed97c..ee32ad0a 100644 --- a/packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue +++ b/packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue @@ -38,19 +38,23 @@ function findStepFromPipeline(targetStepId: string) { } const errorRef = ref(""); -function getDomainFromPipeline(inputKey: string) { +function getStepIdFromInputKey(inputKey: string) { if (!inputKey) { errorRef.value = "请先选择域名证书"; return; } - const targetStepId = inputKey.split(".")[1]; + return inputKey.split(".")[1]; +} +function getDomainFromPipeline(inputKey: string) { + let targetStepId = getStepIdFromInputKey(inputKey); let certStep = findStepFromPipeline(targetStepId); if (!certStep) { errorRef.value = "找不到目标步骤,请先选择域名证书"; return; } - if (certStep.type !== "CertApply" || certStep.type !== "CertApplyLego") { - certStep = findStepFromPipeline(certStep.input?.cert); + if (certStep.type !== "CertApply" && certStep.type !== "CertApplyLego") { + targetStepId = getStepIdFromInputKey(certStep.input?.cert); + certStep = findStepFromPipeline(targetStepId); if (!certStep) { errorRef.value = "找不到目标步骤,请先选择域名证书"; return;