chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -1,66 +1,62 @@
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
import { AwsRegions } from './constants.js';
import { AwsClient } from './libs/aws-client.js';
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
import { AwsRegions } from "./constants.js";
import { AwsClient } from "./libs/aws-client.js";
@IsAccess({
name: 'aws',
title: '亚马逊云aws授权',
desc: '',
icon: 'svg:icon-aws',
name: "aws",
title: "亚马逊云aws授权",
desc: "",
icon: "svg:icon-aws",
})
export class AwsAccess extends BaseAccess {
@AccessInput({
title: 'accessKeyId',
title: "accessKeyId",
component: {
placeholder: 'accessKeyId',
placeholder: "accessKeyId",
},
helper:
'右上角->安全凭证->访问密钥,[点击前往](https://us-east-1.console.aws.amazon.com/iam/home?region=ap-east-1#/security_credentials/access-key-wizard)',
helper: "右上角->安全凭证->访问密钥,[点击前往](https://us-east-1.console.aws.amazon.com/iam/home?region=ap-east-1#/security_credentials/access-key-wizard)",
required: true,
})
accessKeyId = '';
accessKeyId = "";
@AccessInput({
title: 'secretAccessKey',
title: "secretAccessKey",
component: {
placeholder: 'secretAccessKey',
placeholder: "secretAccessKey",
},
required: true,
encrypt: true,
helper: '请妥善保管您的安全访问密钥。您可以在AWS管理控制台的IAM中创建新的访问密钥。',
helper: "请妥善保管您的安全访问密钥。您可以在AWS管理控制台的IAM中创建新的访问密钥。",
})
secretAccessKey = '';
secretAccessKey = "";
@AccessInput({
title: 'region',
title: "region",
component: {
name: "a-select",
options: AwsRegions,
},
required: true,
helper: '请选择您的默认AWS区域,主要区分中国区还是海外区即可',
helper: "请选择您的默认AWS区域,主要区分中国区还是海外区即可",
options: AwsRegions,
})
region = '';
region = "";
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
action: "TestRequest",
},
helper: "测试授权是否正确"
helper: "测试授权是否正确",
})
testRequest = true;
async onTestRequest() {
const client = new AwsClient({ access: this, logger: this.ctx.logger, region: this.region || 'us-east-1' });
const client = new AwsClient({ access: this, logger: this.ctx.logger, region: this.region || "us-east-1" });
await client.getCallerIdentity();
return "ok";
}
}
new AwsAccess();
@@ -1,61 +1,58 @@
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
import { AwsClient } from './libs/aws-client.js';
import { AwsAccess } from './access.js';
import { PageRes, PageSearch } from '@certd/pipeline';
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import { AwsClient } from "./libs/aws-client.js";
import { AwsAccess } from "./access.js";
import { PageRes, PageSearch } from "@certd/pipeline";
@IsDnsProvider({
name: 'aws-route53',
title: 'AWS Route53',
desc: 'AWS Route53 DNS解析提供商',
accessType: 'aws',
icon: 'svg:icon-aws',
order:0,
name: "aws-route53",
title: "AWS Route53",
desc: "AWS Route53 DNS解析提供商",
accessType: "aws",
icon: "svg:icon-aws",
order: 0,
})
export class AwsRoute53Provider extends AbstractDnsProvider {
client: AwsClient;
async onInstance() {
const access: AwsAccess = this.ctx.access as AwsAccess
this.client = new AwsClient({ access: access, logger: this.logger, region:access.region || 'us-east-1' });
const access: AwsAccess = this.ctx.access as AwsAccess;
this.client = new AwsClient({ access: access, logger: this.logger, region: access.region || "us-east-1" });
}
async createRecord(options: CreateRecordOptions): Promise<any> {
const { fullRecord, value, type, domain } = options;
this.logger.info('添加域名解析:', fullRecord, value, domain);
this.logger.info("添加域名解析:", fullRecord, value, domain);
// const domain = await this.matchDomain(fullRecord);
const {ZoneId,ZoneName} = await this.client.route53GetHostedZoneId(domain);
const { ZoneId, ZoneName } = await this.client.route53GetHostedZoneId(domain);
this.logger.info(`获取到hostedZoneId:${ZoneId},name:${ZoneName},domain:${domain}`);
await this.client.route53ChangeRecord({
hostedZoneId: ZoneId,
fullRecord: fullRecord,
type: type,
value: value,
action: 'UPSERT',
action: "UPSERT",
});
return {
hostedZoneId: ZoneId,
}
};
}
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
const { fullRecord, value,type } = options.recordReq;
const { fullRecord, value, type } = options.recordReq;
const record = options.recordRes;
const hostedZoneId = record.hostedZoneId;
try{
try {
await this.client.route53ChangeRecord({
hostedZoneId: hostedZoneId,
fullRecord: fullRecord,
type: type,
value: value,
action: 'DELETE',
action: "DELETE",
});
}catch(e){
this.logger.warn(`删除域名解析失败:${e.message} : ${hostedZoneId} ${fullRecord} ${value} ${type} `, );
} catch (e) {
this.logger.warn(`删除域名解析失败:${e.message} : ${hostedZoneId} ${fullRecord} ${value} ${type} `);
}
}
@@ -1,37 +1,36 @@
export const AwsRegions = [
{ label: '------中国区------', value: 'cn',disabled: true },
{ label: '北京', value: 'cn-north-1' },
{ label: '宁夏', value: 'cn-northwest-1' },
{ label: '------海外-----', value: 'out',disabled: true },
{ label: 'us-east-1', value: 'us-east-1' },
{ label: 'us-east-2', value: 'us-east-2' },
{ label: 'us-west-1', value: 'us-west-1' },
{ label: 'us-west-2', value: 'us-west-2' },
{ label: 'af-south-1', value: 'af-south-1' },
{ label: 'ap-east-1', value: 'ap-east-1' },
{ label: 'ap-northeast-1', value: 'ap-northeast-1' },
{ label: 'ap-northeast-2', value: 'ap-northeast-2' },
{ label: 'ap-northeast-3', value: 'ap-northeast-3' },
{ label: 'ap-south-1', value: 'ap-south-1' },
{ label: 'ap-south-2', value: 'ap-south-2' },
{ label: 'ap-southeast-1', value: 'ap-southeast-1' },
{ label: 'ap-southeast-2', value: 'ap-southeast-2' },
{ label: 'ap-southeast-3', value: 'ap-southeast-3' },
{ label: 'ap-southeast-4', value: 'ap-southeast-4' },
{ label: 'ap-southeast-5', value: 'ap-southeast-5' },
{ label: 'ca-central-1', value: 'ca-central-1' },
{ label: 'ca-west-1', value: 'ca-west-1' },
{ label: 'eu-central-1', value: 'eu-central-1' },
{ label: 'eu-central-2', value: 'eu-central-2' },
{ label: 'eu-north-1', value: 'eu-north-1' },
{ label: 'eu-south-1', value: 'eu-south-1' },
{ label: 'eu-south-2', value: 'eu-south-2' },
{ label: 'eu-west-1', value: 'eu-west-1' },
{ label: 'eu-west-2', value: 'eu-west-2' },
{ label: 'eu-west-3', value: 'eu-west-3' },
{ label: 'il-central-1', value: 'il-central-1' },
{ label: 'me-central-1', value: 'me-central-1' },
{ label: 'me-south-1', value: 'me-south-1' },
{ label: 'sa-east-1', value: 'sa-east-1' },
];
{ label: "------中国区------", value: "cn", disabled: true },
{ label: "北京", value: "cn-north-1" },
{ label: "宁夏", value: "cn-northwest-1" },
{ label: "------海外-----", value: "out", disabled: true },
{ label: "us-east-1", value: "us-east-1" },
{ label: "us-east-2", value: "us-east-2" },
{ label: "us-west-1", value: "us-west-1" },
{ label: "us-west-2", value: "us-west-2" },
{ label: "af-south-1", value: "af-south-1" },
{ label: "ap-east-1", value: "ap-east-1" },
{ label: "ap-northeast-1", value: "ap-northeast-1" },
{ label: "ap-northeast-2", value: "ap-northeast-2" },
{ label: "ap-northeast-3", value: "ap-northeast-3" },
{ label: "ap-south-1", value: "ap-south-1" },
{ label: "ap-south-2", value: "ap-south-2" },
{ label: "ap-southeast-1", value: "ap-southeast-1" },
{ label: "ap-southeast-2", value: "ap-southeast-2" },
{ label: "ap-southeast-3", value: "ap-southeast-3" },
{ label: "ap-southeast-4", value: "ap-southeast-4" },
{ label: "ap-southeast-5", value: "ap-southeast-5" },
{ label: "ca-central-1", value: "ca-central-1" },
{ label: "ca-west-1", value: "ca-west-1" },
{ label: "eu-central-1", value: "eu-central-1" },
{ label: "eu-central-2", value: "eu-central-2" },
{ label: "eu-north-1", value: "eu-north-1" },
{ label: "eu-south-1", value: "eu-south-1" },
{ label: "eu-south-2", value: "eu-south-2" },
{ label: "eu-west-1", value: "eu-west-1" },
{ label: "eu-west-2", value: "eu-west-2" },
{ label: "eu-west-3", value: "eu-west-3" },
{ label: "il-central-1", value: "il-central-1" },
{ label: "me-central-1", value: "me-central-1" },
{ label: "me-south-1", value: "me-south-1" },
{ label: "sa-east-1", value: "sa-east-1" },
];
@@ -1,4 +1,4 @@
export * from './plugins/index.js';
export * from './access.js';
export * from './aws-route53-provider.js';
export * from './constants.js';
export * from "./plugins/index.js";
export * from "./access.js";
export * from "./aws-route53-provider.js";
export * from "./constants.js";
@@ -1,9 +1,9 @@
// 导入所需的 SDK 模块
import { AwsAccess } from '../access.js';
import { CertInfo, DomainRecord } from '@certd/plugin-cert';
import { ILogger, utils } from '@certd/basic';
import { PageRes, PageSearch } from '@certd/pipeline';
type AwsClientOptions = { access: AwsAccess; region: string, logger: ILogger };
import { AwsAccess } from "../access.js";
import { CertInfo, DomainRecord } from "@certd/plugin-cert";
import { ILogger, utils } from "@certd/basic";
import { PageRes, PageSearch } from "@certd/pipeline";
type AwsClientOptions = { access: AwsAccess; region: string; logger: ILogger };
/**
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/route-53-domains/
@@ -21,7 +21,7 @@ export class AwsClient {
}
async importCertificate(certInfo: CertInfo) {
// 创建 ACM 客户端
const { ACMClient, ImportCertificateCommand } = await import('@aws-sdk/client-acm');
const { ACMClient, ImportCertificateCommand } = await import("@aws-sdk/client-acm");
const acmClient = new ACMClient({
region: this.region, // 替换为您的 AWS 区域
credentials: {
@@ -30,7 +30,7 @@ export class AwsClient {
},
});
const cert = certInfo.crt.split('-----END CERTIFICATE-----')[0] + '-----END CERTIFICATE-----';
const cert = certInfo.crt.split("-----END CERTIFICATE-----")[0] + "-----END CERTIFICATE-----";
// 构建上传参数
const data = await acmClient.send(
new ImportCertificateCommand({
@@ -39,17 +39,16 @@ export class AwsClient {
// CertificateChain: certificateChain, // 可选
})
);
console.log('Upload successful:', data);
console.log("Upload successful:", data);
// 返回证书 ARNAmazon Resource Name
return data.CertificateArn;
}
async getCallerIdentity() {
const { STSClient, GetCallerIdentityCommand } = await import ("@aws-sdk/client-sts");
const { STSClient, GetCallerIdentityCommand } = await import("@aws-sdk/client-sts");
const client = new STSClient({
region: this.access.region || 'us-east-1',
region: this.access.region || "us-east-1",
credentials: {
accessKeyId: this.access.accessKeyId, // 从环境变量中读取
secretAccessKey: this.access.secretAccessKey,
@@ -64,9 +63,8 @@ export class AwsClient {
return response;
}
async route53ClientGet() {
const { Route53Client } = await import('@aws-sdk/client-route-53');
const { Route53Client } = await import("@aws-sdk/client-route-53");
return new Route53Client({
region: this.region,
credentials: {
@@ -76,20 +74,21 @@ export class AwsClient {
});
}
async route53GetHostedZoneId(name: string): Promise<{ ZoneId: string, ZoneName: string }> {
async route53GetHostedZoneId(name: string): Promise<{ ZoneId: string; ZoneName: string }> {
const hostedZones = await this.route53ListHostedZones(name);
const zoneId = hostedZones[0].Id.replace('/hostedzone/', '');
const zoneId = hostedZones[0].Id.replace("/hostedzone/", "");
this.logger.info(`获取到hostedZoneId:${zoneId},name:${hostedZones[0].Name}`);
return {
ZoneId: zoneId,
ZoneName: hostedZones[0].Name,
};
}
async route53ListHostedZones(name: string): Promise<{ Id: string, Name: string }[]> {
async route53ListHostedZones(name: string): Promise<{ Id: string; Name: string }[]> {
const { ListHostedZonesByNameCommand } = await import("@aws-sdk/client-route-53"); // ES Modules import
const client = await this.route53ClientGet();
const input = { // ListHostedZonesByNameRequest
const input = {
// ListHostedZonesByNameRequest
DNSName: name,
};
const command = new ListHostedZonesByNameCommand(input);
@@ -105,7 +104,8 @@ export class AwsClient {
const { ListHostedZonesByNameCommand } = await import("@aws-sdk/client-route-53"); // ES Modules import
const client = await this.route53ClientGet();
const input: any = { // ListHostedZonesByNameRequest
const input: any = {
// ListHostedZonesByNameRequest
MaxItems: req.pageSize,
};
if (req.searchKey) {
@@ -115,7 +115,7 @@ export class AwsClient {
const response = await this.doRequest(() => client.send(command));
let list: any[] = response.HostedZones || [];
list = list.map((item: any) => ({
id: item.Id.replace('/hostedzone/', ''),
id: item.Id.replace("/hostedzone/", ""),
domain: item.Name,
}));
return {
@@ -124,24 +124,29 @@ export class AwsClient {
};
}
async route53ChangeRecord(req: {
hostedZoneId: string, fullRecord: string, type: string, value: string, action: "UPSERT" | "DELETE"
}) {
async route53ChangeRecord(req: { hostedZoneId: string; fullRecord: string; type: string; value: string; action: "UPSERT" | "DELETE" }) {
const { ChangeResourceRecordSetsCommand } = await import("@aws-sdk/client-route-53"); // ES Modules import
// const { Route53Client, ChangeResourceRecordSetsCommand } = require("@aws-sdk/client-route-53"); // CommonJS import
// import type { Route53ClientConfig } from "@aws-sdk/client-route-53";
const client = await this.route53ClientGet();
const input = { // ChangeResourceRecordSetsRequest
const input = {
// ChangeResourceRecordSetsRequest
HostedZoneId: req.hostedZoneId, // required
ChangeBatch: { // ChangeBatch
Changes: [ // Changes // required
{ // Change
ChangeBatch: {
// ChangeBatch
Changes: [
// Changes // required
{
// Change
Action: req.action as any, // required
ResourceRecordSet: { // ResourceRecordSet
ResourceRecordSet: {
// ResourceRecordSet
Name: req.fullRecord, // required
Type: req.type.toUpperCase() as any,
ResourceRecords: [ // ResourceRecords
{ // ResourceRecord
ResourceRecords: [
// ResourceRecords
{
// ResourceRecord
Value: `"${req.value}"`, // required
},
],
@@ -154,7 +159,7 @@ export class AwsClient {
this.logger.info(`设置域名解析参数:${JSON.stringify(input)}`);
const command = new ChangeResourceRecordSetsCommand(input);
const response = await this.doRequest(() => client.send(command));
console.log('Add record successful:', JSON.stringify(response));
console.log("Add record successful:", JSON.stringify(response));
await utils.sleep(3000);
return response;
/*
@@ -1,2 +1,2 @@
export * from './plugin-deploy-to-cloudfront.js';
export * from './plugin-upload-to-acm.js'
export * from "./plugin-deploy-to-cloudfront.js";
export * from "./plugin-upload-to-acm.js";
@@ -7,10 +7,10 @@ import { optionsUtils } from "@certd/basic";
import { AwsRegions } from "../constants.js";
@IsTaskPlugin({
name: 'AwsDeployToCloudFront',
title: 'AWS-部署证书到CloudFront',
desc: '部署证书到 AWS CloudFront',
icon: 'svg:icon-aws',
name: "AwsDeployToCloudFront",
title: "AWS-部署证书到CloudFront",
desc: "部署证书到 AWS CloudFront",
icon: "svg:icon-aws",
group: pluginGroups.aws.key,
needPlus: false,
default: {
@@ -21,11 +21,11 @@ import { AwsRegions } from "../constants.js";
})
export class AwsDeployToCloudFront extends AbstractTaskPlugin {
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
title: "域名证书",
helper: "请选择前置任务输出的域名证书",
component: {
name: 'output-selector',
from: [...CertApplyPluginNames, 'AwsUploadToACM'],
name: "output-selector",
from: [...CertApplyPluginNames, "AwsUploadToACM"],
},
required: true,
})
@@ -35,11 +35,11 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
certDomains!: string[];
@TaskInput({
title: '区域',
helper: '证书上传区域',
title: "区域",
helper: "证书上传区域",
component: {
name: 'a-auto-complete',
vModel: 'value',
name: "a-auto-complete",
vModel: "value",
options: AwsRegions,
},
required: true,
@@ -47,11 +47,11 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
region!: string;
@TaskInput({
title: 'Access授权',
helper: 'aws的授权',
title: "Access授权",
helper: "aws的授权",
component: {
name: 'access-selector',
type: 'aws',
name: "access-selector",
type: "aws",
},
required: true,
})
@@ -59,8 +59,8 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
@TaskInput(
createRemoteSelectInputDefine({
title: '分配ID',
helper: '请选择distributions id',
title: "分配ID",
helper: "请选择distributions id",
action: AwsDeployToCloudFront.prototype.onGetDistributions.name,
required: true,
})
@@ -73,13 +73,13 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
const access = await this.getAccess<AwsAccess>(this.accessId);
let certId = this.cert as string;
if (typeof this.cert !== 'string') {
if (typeof this.cert !== "string") {
//先上传
certId = await this.uploadToACM(access, this.cert);
}
//部署到CloudFront
const { CloudFrontClient, UpdateDistributionCommand, GetDistributionConfigCommand } = await import('@aws-sdk/client-cloudfront');
const { CloudFrontClient, UpdateDistributionCommand, GetDistributionConfigCommand } = await import("@aws-sdk/client-cloudfront");
const cloudFrontClient = new CloudFrontClient({
region: this.region,
credentials: {
@@ -112,7 +112,7 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
await cloudFrontClient.send(updateDistributionCommand);
this.logger.info(`部署${distributionId}完成:`);
}
this.logger.info('部署完成');
this.logger.info("部署完成");
}
private async uploadToACM(access: AwsAccess, cert: CertInfo) {
@@ -122,18 +122,18 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
logger: this.logger,
});
const awsCertARN = await acmClient.importCertificate(cert);
this.logger.info('证书上传成功,id=', awsCertARN);
this.logger.info("证书上传成功,id=", awsCertARN);
return awsCertARN;
}
//查找分配ID列表选项
async onGetDistributions() {
if (!this.accessId) {
throw new Error('请选择Access授权');
throw new Error("请选择Access授权");
}
const access = await this.getAccess<AwsAccess>(this.accessId);
const { CloudFrontClient, ListDistributionsCommand } = await import('@aws-sdk/client-cloudfront');
const { CloudFrontClient, ListDistributionsCommand } = await import("@aws-sdk/client-cloudfront");
const cloudFrontClient = new CloudFrontClient({
region: this.region,
credentials: {
@@ -146,7 +146,7 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
const data = await cloudFrontClient.send(listDistributionsCommand);
const distributions = data.DistributionList?.Items;
if (!distributions || distributions.length === 0) {
throw new Error('找不到CloudFront分配ID,您可以手动输入');
throw new Error("找不到CloudFront分配ID,您可以手动输入");
}
const options = distributions.map((item: any) => {
@@ -1,14 +1,14 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
import { CertInfo } from '@certd/plugin-cert';
import { AwsAccess } from '../access.js';
import { AwsClient } from '../libs/aws-client.js';
import { CertApplyPluginNames} from '@certd/plugin-cert';
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
import { CertInfo } from "@certd/plugin-cert";
import { AwsAccess } from "../access.js";
import { AwsClient } from "../libs/aws-client.js";
import { CertApplyPluginNames } from "@certd/plugin-cert";
import { AwsRegions } from "../constants.js";
@IsTaskPlugin({
name: 'AwsUploadToACM',
title: 'AWS-上传证书到ACM',
desc: '上传证书 AWS ACM',
icon: 'svg:icon-aws',
name: "AwsUploadToACM",
title: "AWS-上传证书到ACM",
desc: "上传证书 AWS ACM",
icon: "svg:icon-aws",
group: pluginGroups.aws.key,
default: {
strategy: {
@@ -18,10 +18,10 @@ import { AwsRegions } from "../constants.js";
})
export class AwsUploadToACM extends AbstractTaskPlugin {
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
title: "域名证书",
helper: "请选择前置任务输出的域名证书",
component: {
name: 'output-selector',
name: "output-selector",
from: [...CertApplyPluginNames],
},
required: true,
@@ -29,21 +29,21 @@ export class AwsUploadToACM extends AbstractTaskPlugin {
cert!: CertInfo;
@TaskInput({
title: 'Access授权',
helper: 'aws的授权',
title: "Access授权",
helper: "aws的授权",
component: {
name: 'access-selector',
type: 'aws',
name: "access-selector",
type: "aws",
},
required: true,
})
accessId!: string;
@TaskInput({
title: '区域',
helper: '证书上传区域',
title: "区域",
helper: "证书上传区域",
component: {
name: 'a-auto-complete',
vModel: 'value',
name: "a-auto-complete",
vModel: "value",
options: AwsRegions,
},
required: true,
@@ -51,9 +51,9 @@ export class AwsUploadToACM extends AbstractTaskPlugin {
region!: string;
@TaskOutput({
title: '证书ARN',
title: "证书ARN",
})
awsCertARN = '';
awsCertARN = "";
async onInstance() {}
@@ -66,7 +66,7 @@ export class AwsUploadToACM extends AbstractTaskPlugin {
logger: this.logger,
});
this.awsCertARN = await acmClient.importCertificate(cert);
this.logger.info('证书上传成功,id=', this.awsCertARN);
this.logger.info("证书上传成功,id=", this.awsCertARN);
}
}