mirror of
https://github.com/certd/certd.git
synced 2026-04-14 12:30:54 +08:00
fix: 修复京东云报错不准确的bug
This commit is contained in:
@@ -174,7 +174,7 @@ export default async (client, userOpts) => {
|
||||
|
||||
|
||||
} catch (e) {
|
||||
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message}`);
|
||||
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message || e}`);
|
||||
await deactivateAuth(e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -244,10 +244,11 @@ export class AccessService extends BaseService<AccessEntity> {
|
||||
}
|
||||
const newAccess = {
|
||||
...access,
|
||||
userId:-1,
|
||||
id: undefined,
|
||||
projectId,
|
||||
}
|
||||
await this.add(newAccess);
|
||||
await this.repository.save(newAccess);
|
||||
return newAccess.id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch} from '@certd/pipeline';
|
||||
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||
import { DomainRecord } from '@certd/plugin-lib';
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ export class JDCloudAccess extends BaseAccess {
|
||||
component: {
|
||||
placeholder: 'AccessKeyID',
|
||||
},
|
||||
helper:"[获取密钥](https://uc.jdcloud.com/account/accesskey)",
|
||||
helper: "[获取密钥](https://uc.jdcloud.com/account/accesskey)",
|
||||
required: true,
|
||||
})
|
||||
accessKeyId = '';
|
||||
@@ -34,7 +34,7 @@ export class JDCloudAccess extends BaseAccess {
|
||||
secretAccessKey = '';
|
||||
|
||||
|
||||
@AccessInput({
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
@@ -55,8 +55,8 @@ export class JDCloudAccess extends BaseAccess {
|
||||
}
|
||||
|
||||
|
||||
async getJDDomainService() {
|
||||
const {JDDomainService} = await import("@certd/jdcloud")
|
||||
async getJDDomainService() {
|
||||
const { JDDomainService } = await import("@certd/jdcloud")
|
||||
const service = new JDDomainService({
|
||||
credentials: {
|
||||
accessKeyId: this.accessKeyId,
|
||||
@@ -68,24 +68,34 @@ export class JDCloudAccess extends BaseAccess {
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
const pager = new Pager(req);
|
||||
const service = await this.getJDDomainService();
|
||||
const domainRes = await service.describeDomains({
|
||||
domainName: req.searchKey,
|
||||
pageNumber: pager.pageNo,
|
||||
pageSize: pager.pageSize,
|
||||
})
|
||||
let list = domainRes.result?.dataList || []
|
||||
list = list.map((item: any) => ({
|
||||
id: item.domainId,
|
||||
domain: item.domainName,
|
||||
}));
|
||||
return {
|
||||
total:domainRes.result.totalCount || list.length,
|
||||
list,
|
||||
};
|
||||
const pager = new Pager(req);
|
||||
const service = await this.getJDDomainService();
|
||||
const domainRes = await this.catchCall(() => service.describeDomains({
|
||||
domainName: req.searchKey,
|
||||
pageNumber: pager.pageNo,
|
||||
pageSize: pager.pageSize,
|
||||
}))
|
||||
let list = domainRes.result?.dataList || []
|
||||
list = list.map((item: any) => ({
|
||||
id: item.domainId,
|
||||
domain: item.domainName,
|
||||
}));
|
||||
return {
|
||||
total: domainRes.result.totalCount || list.length,
|
||||
list,
|
||||
};
|
||||
}
|
||||
async catchCall<T=any>(fn: () => Promise<T>): Promise<T> {
|
||||
try {
|
||||
return await fn();
|
||||
} catch (e) {
|
||||
if (e.error) {
|
||||
this.ctx.logger.error(JSON.stringify(e.error))
|
||||
throw new Error(JSON.stringify(e.error))
|
||||
}
|
||||
throw e
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
new JDCloudAccess();
|
||||
|
||||
@@ -8,7 +8,7 @@ import { JDCloudAccess } from "./access.js";
|
||||
desc: "京东云DNS解析提供商",
|
||||
accessType: "jdcloud",
|
||||
icon: "svg:icon-jdcloud",
|
||||
order:3,
|
||||
order: 3,
|
||||
})
|
||||
export class JDCloudDnsProvider extends AbstractDnsProvider {
|
||||
access!: JDCloudAccess;
|
||||
@@ -36,8 +36,8 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
|
||||
}
|
||||
const list = domainRes.result.dataList
|
||||
|
||||
const found = list.find((item) => item.domainName === domain)
|
||||
if (!found){
|
||||
const found = list.find((item) => item.domainName === domain)
|
||||
if (!found) {
|
||||
throw new Error(`域名${domain}在此京东云账号中不存在`)
|
||||
}
|
||||
|
||||
@@ -54,44 +54,33 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
|
||||
* weight Integer False 解析记录的权重,目前支持权重的有:A/AAAA/CNAME/JNAME,A/AAAA权重范围:0-100、CNAME/JNAME权重范围:1-100。
|
||||
* viewValue Integer True 解析线路的ID,请调用describeViewTree接口获取基础解
|
||||
*/
|
||||
try{
|
||||
const res = await service.createResourceRecord({
|
||||
domainId: domainId,
|
||||
req:{
|
||||
hostRecord: hostRecord,
|
||||
hostValue: value,
|
||||
type: type,
|
||||
ttl: 200,
|
||||
viewValue:-1,
|
||||
}
|
||||
})
|
||||
return {
|
||||
recordId: res.result.dataList.id,
|
||||
domainId: domainId
|
||||
};
|
||||
}catch (e) {
|
||||
if (e.error){
|
||||
this.logger.error(JSON.stringify(e.error))
|
||||
throw new Error(JSON.stringify(e.error))
|
||||
const res = await this.access.catchCall(() => service.createResourceRecord({
|
||||
domainId: domainId,
|
||||
req: {
|
||||
hostRecord: hostRecord,
|
||||
hostValue: value,
|
||||
type: type,
|
||||
ttl: 200,
|
||||
viewValue: -1,
|
||||
}
|
||||
throw e
|
||||
}
|
||||
|
||||
|
||||
|
||||
}))
|
||||
return {
|
||||
recordId: res.result.dataList.id,
|
||||
domainId: domainId
|
||||
};
|
||||
}
|
||||
|
||||
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
|
||||
const record = options.recordRes;
|
||||
|
||||
const service = await this.getJDDomainService();
|
||||
await service.deleteResourceRecord({
|
||||
await this.access.catchCall(() => service.deleteResourceRecord({
|
||||
domainId: record.domainId,
|
||||
resourceRecordId: record.recordId
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
private async getJDDomainService() {
|
||||
private async getJDDomainService() {
|
||||
return await this.access.getJDDomainService();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
|
||||
this.logger.info(`开始上传证书`);
|
||||
|
||||
const sslService = await this.getSslClient(access);
|
||||
const res = await sslService.uploadCert({
|
||||
const res = await access.catchCall(() => sslService.uploadCert({
|
||||
// certName String True 证书名称
|
||||
// keyFile String True 私钥
|
||||
// certFile String True 证书
|
||||
@@ -80,7 +80,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
|
||||
keyFile: certInfo.key,
|
||||
certFile: certInfo.crt,
|
||||
aliasName: certName
|
||||
});
|
||||
}));
|
||||
certId = res.result.certId;
|
||||
}
|
||||
|
||||
@@ -152,10 +152,10 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
|
||||
* pageNumber Integer False 1 pageNumber,默认值1
|
||||
* pageSize
|
||||
*/
|
||||
const res = await service.getDomainList({
|
||||
const res = await access.catchCall(() => service.getDomainList({
|
||||
pageNumber: 1,
|
||||
pageSize: 50
|
||||
});
|
||||
}));
|
||||
// @ts-ignore
|
||||
const list = res?.result?.domains;
|
||||
if (!list || list.length === 0) {
|
||||
|
||||
@@ -85,7 +85,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
|
||||
const certInfo = this.cert as CertInfo
|
||||
for (const certId of this.certIds) {
|
||||
this.logger.info(`开始更新证书:${certId}`)
|
||||
const res = await service.updateCert({
|
||||
const res = await access.catchCall(() => service.updateCert({
|
||||
/*
|
||||
@param {string} opts.certId - 证书Id
|
||||
@param {string} opts.certId - 证书ID
|
||||
@@ -96,7 +96,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
|
||||
certId,
|
||||
certFile: certInfo.crt,
|
||||
keyFile:certInfo.key,
|
||||
})
|
||||
}))
|
||||
this.logger.info(`更新证书${certId}成功:${JSON.stringify(res)}`);
|
||||
await this.ctx.utils.sleep(2000)
|
||||
}
|
||||
@@ -126,10 +126,10 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
|
||||
* pageNumber Integer False 1 pageNumber,默认值1
|
||||
* pageSize
|
||||
*/
|
||||
const res = await service.describeCerts({
|
||||
const res = await access.catchCall(() => service.describeCerts({
|
||||
pageNumber: 1,
|
||||
pageSize: 100,
|
||||
})
|
||||
}))
|
||||
// @ts-ignore
|
||||
const list = res?.result?.certListDetails
|
||||
if (!list || list.length === 0) {
|
||||
|
||||
@@ -61,7 +61,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
|
||||
const service = await this.getClient(access);
|
||||
|
||||
const certInfo = this.cert as CertInfo;
|
||||
const res = await service.uploadCert({
|
||||
const res = await access.catchCall(() => service.uploadCert({
|
||||
/*
|
||||
@param {string} opts.certName - 证书名称
|
||||
@param {string} opts.keyFile - 私钥
|
||||
@@ -71,7 +71,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
|
||||
certName: this.appendTimeSuffix(this.certName || "certd"),
|
||||
certFile: certInfo.crt,
|
||||
keyFile: certInfo.key
|
||||
});
|
||||
}));
|
||||
this.jdcloudCertId = res.result.certId;
|
||||
this.logger.info(`上传证书成功:${JSON.stringify(res)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user