mirror of https://github.com/certd/certd
				
				
				
			fix: 修复配置了cdn cname后申请失败的bug
							parent
							
								
									1b7debc6a4
								
							
						
					
					
						commit
						4a5fa767ed
					
				| 
						 | 
				
			
			@ -171,7 +171,6 @@ module.exports = async (client, userOpts) => {
 | 
			
		|||
        await challengeFunc(authz);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    function runAllPromise(tasks) {
 | 
			
		||||
        let promise = Promise.resolve();
 | 
			
		||||
        tasks.forEach((task) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -210,11 +209,18 @@ module.exports = async (client, userOpts) => {
 | 
			
		|||
    }
 | 
			
		||||
    catch (e) {
 | 
			
		||||
        log('证书申请失败');
 | 
			
		||||
        throw e;
 | 
			
		||||
        log(e);
 | 
			
		||||
        throw new Error(`证书申请失败:${e.message}`);
 | 
			
		||||
    }
 | 
			
		||||
    finally {
 | 
			
		||||
        log(`清理challenge痕迹,length:${clearTasks.length}`);
 | 
			
		||||
        await runAllPromise(clearTasks);
 | 
			
		||||
        try {
 | 
			
		||||
            await runAllPromise(clearTasks);
 | 
			
		||||
        }
 | 
			
		||||
        catch (e) {
 | 
			
		||||
            log('清理challenge失败');
 | 
			
		||||
            log(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // try {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			@ -35,50 +40,59 @@ export class TencentDnsProvider extends AbstractDnsProvider {
 | 
			
		|||
      },
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
// 实例化要请求产品的client对象,clientProfile是可选的
 | 
			
		||||
    // 实例化要请求产品的client对象,clientProfile是可选的
 | 
			
		||||
    this.client = new DnspodClient(clientConfig);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async createRecord(options: CreateRecordOptions): Promise<any> {
 | 
			
		||||
    const { fullRecord, value, type,domain } = options;
 | 
			
		||||
    const { fullRecord, value, type, domain } = options;
 | 
			
		||||
    this.logger.info('添加域名解析:', fullRecord, value);
 | 
			
		||||
    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"
 | 
			
		||||
	}
 | 
			
		||||
     */
 | 
			
		||||
    this.logger.info(
 | 
			
		||||
      '添加域名解析成功:',
 | 
			
		||||
      fullRecord,
 | 
			
		||||
      value,
 | 
			
		||||
      JSON.stringify(ret)
 | 
			
		||||
    );
 | 
			
		||||
    return ret;
 | 
			
		||||
    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 { 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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue