fix: 修复配置了cdn cname后申请失败的bug

pull/78/head
xiaojunnuo 2024-07-02 00:18:28 +08:00
parent 1b7debc6a4
commit 4a5fa767ed
4 changed files with 66 additions and 40 deletions

View File

@ -171,7 +171,6 @@ module.exports = async (client, userOpts) => {
await challengeFunc(authz);
});
function runAllPromise(tasks) {
let promise = Promise.resolve();
tasks.forEach((task) => {
@ -210,12 +209,19 @@ module.exports = async (client, userOpts) => {
}
catch (e) {
log('证书申请失败');
throw e;
log(e);
throw new Error(`证书申请失败:${e.message}`);
}
finally {
log(`清理challenge痕迹length:${clearTasks.length}`);
try {
await runAllPromise(clearTasks);
}
catch (e) {
log('清理challenge失败');
log(e);
}
}
// try {
// await Promise.allSettled(challengePromises);

View File

@ -178,6 +178,7 @@ export class AcmeService {
csr,
email: email,
termsOfServiceAgreed: true,
skipChallengeVerification: true,
challengePriority: ["dns-01"],
challengeCreateFn: async (authz: acme.Authorization, challenge: Challenge, keyAuthorization: string): Promise<any> => {
return await this.challengeCreateFn(authz, challenge, keyAuthorization, dnsProvider);

View File

@ -1,12 +1,17 @@
import { Autowire, HttpClient, ILogger } from "@certd/pipeline";
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import _ from "lodash";
import { DnspodAccess } from "../access";
import { Autowire, HttpClient, ILogger } from '@certd/pipeline';
import {
AbstractDnsProvider,
CreateRecordOptions,
IsDnsProvider,
RemoveRecordOptions,
} from '@certd/plugin-cert';
import _ from 'lodash';
import { DnspodAccess } from '../access';
@IsDnsProvider({
name: 'dnspod',
title: 'dnspod(腾讯云)',
desc: '腾讯云的域名解析接口已迁移到dnspod',
title: 'dnspod(已过时)',
desc: '请尽快换成腾讯云类型',
accessType: 'dnspod',
})
export class DnspodDnsProvider extends AbstractDnsProvider {

View File

@ -1,7 +1,13 @@
import {Autowire, HttpClient, ILogger} from "@certd/pipeline";
import {AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions} from "@certd/plugin-cert";
import {TencentAccess} from "../access";
import { Autowire, HttpClient, ILogger } from '@certd/pipeline';
import {
AbstractDnsProvider,
CreateRecordOptions,
IsDnsProvider,
RemoveRecordOptions,
} from '@certd/plugin-cert';
import { TencentAccess } from '../access';
import tencentcloud from 'tencentcloud-sdk-nodejs/index';
import TencentCloudSDKHttpException from 'tencentcloud-sdk-nodejs/tencentcloud/common/exception/tencent_cloud_sdk_exception';
const DnspodClient = tencentcloud.dnspod.v20210323.Client;
@IsDnsProvider({
@ -24,10 +30,9 @@ export class TencentDnsProvider extends AbstractDnsProvider {
endpoint = 'dnspod.tencentcloudapi.com';
async onInstance() {
const clientConfig = {
credential: this.access,
region: "",
region: '',
profile: {
httpProfile: {
endpoint: this.endpoint,
@ -45,40 +50,49 @@ export class TencentDnsProvider extends AbstractDnsProvider {
const rr = fullRecord.replace('.' + domain, '');
const params = {
"Domain": domain,
"RecordType": type,
"RecordLine": "默认",
"Value": value,
"SubDomain": rr
Domain: domain,
RecordType: type,
RecordLine: '默认',
Value: value,
SubDomain: rr,
};
const ret = await this.client.CreateRecord(params)
/*
{
"RecordId": 162,
"RequestId": "ab4f1426-ea15-42ea-8183-dc1b44151166"
}
*/
try {
const ret = await this.client.CreateRecord(params);
this.logger.info(
'添加域名解析成功:',
fullRecord,
value,
JSON.stringify(ret)
);
/*
{
"RecordId": 162,
"RequestId": "ab4f1426-ea15-42ea-8183-dc1b44151166"
}
*/
return ret;
} catch (e: any) {
if (e instanceof TencentCloudSDKHttpException) {
if (e.code === 'InvalidParameter.DomainRecordExist') {
this.logger.info('域名解析已存在,无需重复添加:', fullRecord, value);
return {};
}
}
throw e;
}
}
async removeRecord(options: RemoveRecordOptions<any>) {
const { fullRecord, value, domain, record } = options;
const params = {
"Domain": domain,
"RecordId": record.RecordId
Domain: domain,
RecordId: record.RecordId,
};
const ret = await this.client.DeleteRecord(params)
const ret = await this.client.DeleteRecord(params);
this.logger.info('删除域名解析成功:', fullRecord, value);
return ret;
}
}
new TencentDnsProvider();