mirror of https://github.com/certd/certd
chore: 优化域名match
parent
b421798a1b
commit
1cc1d1c03c
|
@ -0,0 +1,11 @@
|
|||
# 阿里云相关
|
||||
|
||||
|
||||
## 阿里云客户端请求超时配置
|
||||
|
||||
配置环境变量
|
||||
```shell
|
||||
ALIYUN_CLIENT_CONNECT_TIMEOUT=10000 # 连接超时,单位毫秒
|
||||
ALIYUN_CLIENT_READ_TIMEOUT=10000 #读取数据超时,单位毫秒
|
||||
|
||||
```
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
|
@ -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,
|
||||
};
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue