mirror of
https://github.com/certd/certd.git
synced 2026-07-06 11:58:58 +08:00
chore: format
This commit is contained in:
@@ -1,33 +1,32 @@
|
||||
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
|
||||
@IsAccess({
|
||||
name: 'aws-cn',
|
||||
title: '亚马逊云科技(国区)授权',
|
||||
desc: '',
|
||||
icon: 'svg:icon-aws',
|
||||
name: "aws-cn",
|
||||
title: "亚马逊云科技(国区)授权",
|
||||
desc: "",
|
||||
icon: "svg:icon-aws",
|
||||
})
|
||||
export class AwsCNAccess extends BaseAccess {
|
||||
@AccessInput({
|
||||
title: 'accessKeyId',
|
||||
title: "accessKeyId",
|
||||
component: {
|
||||
placeholder: 'accessKeyId',
|
||||
placeholder: "accessKeyId",
|
||||
},
|
||||
helper:
|
||||
'右上角->安全凭证->访问密钥,[点击前往](https://cn-north-1.console.amazonaws.cn/iam/home?region=cn-north-1#/security_credentials/access-key-wizard#)',
|
||||
helper: "右上角->安全凭证->访问密钥,[点击前往](https://cn-north-1.console.amazonaws.cn/iam/home?region=cn-north-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 = "";
|
||||
}
|
||||
|
||||
new AwsCNAccess();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const AwsCNRegions = [
|
||||
{ label: 'cn-north-1', value: 'cn-north-1' },
|
||||
{ label: 'cn-northwest-1', value: 'cn-northwest-1' },
|
||||
];
|
||||
{ label: "cn-north-1", value: "cn-north-1" },
|
||||
{ label: "cn-northwest-1", value: "cn-northwest-1" },
|
||||
];
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './plugins/index.js';
|
||||
export * from './access.js';
|
||||
export * from './constants.js';
|
||||
export * from "./plugins/index.js";
|
||||
export * from "./access.js";
|
||||
export * from "./constants.js";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// 导入所需的 SDK 模块
|
||||
import { AwsCNAccess } from '../access.js';
|
||||
import { CertInfo } from '@certd/plugin-cert';
|
||||
import { AwsCNAccess } from "../access.js";
|
||||
import { CertInfo } from "@certd/plugin-cert";
|
||||
|
||||
type AwsIAMClientOptions = { access: AwsCNAccess; region: string };
|
||||
|
||||
@@ -15,7 +15,7 @@ export class AwsIAMClient {
|
||||
}
|
||||
async importCertificate(certInfo: CertInfo, certName: string) {
|
||||
// 创建 IAM 客户端
|
||||
const { IAMClient, UploadServerCertificateCommand } = await import('@aws-sdk/client-iam');
|
||||
const { IAMClient, UploadServerCertificateCommand } = await import("@aws-sdk/client-iam");
|
||||
const iamClient = new IAMClient({
|
||||
region: this.region, // 替换为您的 AWS 区域
|
||||
credentials: {
|
||||
@@ -24,18 +24,18 @@ export class AwsIAMClient {
|
||||
},
|
||||
});
|
||||
|
||||
const cert = certInfo.crt.split('-----END CERTIFICATE-----')[0] + '-----END CERTIFICATE-----';
|
||||
const chain = certInfo.crt.split('-----END CERTIFICATE-----\n')[1];
|
||||
const cert = certInfo.crt.split("-----END CERTIFICATE-----")[0] + "-----END CERTIFICATE-----";
|
||||
const chain = certInfo.crt.split("-----END CERTIFICATE-----\n")[1];
|
||||
// 构建上传参数
|
||||
const command = new UploadServerCertificateCommand({
|
||||
Path: '/cloudfront/',
|
||||
Path: "/cloudfront/",
|
||||
ServerCertificateName: certName,
|
||||
CertificateBody: cert,
|
||||
PrivateKey: certInfo.key,
|
||||
CertificateChain: chain
|
||||
})
|
||||
CertificateChain: chain,
|
||||
});
|
||||
const data = await iamClient.send(command);
|
||||
console.log('Upload successful:', data);
|
||||
console.log("Upload successful:", data);
|
||||
// 返回证书 ID
|
||||
return data.ServerCertificateMetadata.ServerCertificateId;
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './plugin-deploy-to-cloudfront.js';
|
||||
export * from "./plugin-deploy-to-cloudfront.js";
|
||||
|
||||
+28
-29
@@ -3,14 +3,13 @@ import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
||||
import { AwsCNAccess } from "../access.js";
|
||||
import { AwsIAMClient } from "../libs/aws-iam-client.js";
|
||||
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib";
|
||||
import { AwsCNRegions } from '../constants.js';
|
||||
|
||||
import { AwsCNRegions } from "../constants.js";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'AwsCNDeployToCloudFront',
|
||||
title: 'AWS(国区)-部署证书到CloudFront',
|
||||
desc: '部署证书到 AWS CloudFront',
|
||||
icon: 'svg:icon-aws',
|
||||
name: "AwsCNDeployToCloudFront",
|
||||
title: "AWS(国区)-部署证书到CloudFront",
|
||||
desc: "部署证书到 AWS CloudFront",
|
||||
icon: "svg:icon-aws",
|
||||
group: pluginGroups.aws.key,
|
||||
needPlus: false,
|
||||
default: {
|
||||
@@ -21,11 +20,11 @@ import { AwsCNRegions } from '../constants.js';
|
||||
})
|
||||
export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: '域名证书',
|
||||
helper: '请选择前置任务输出的域名证书',
|
||||
title: "域名证书",
|
||||
helper: "请选择前置任务输出的域名证书",
|
||||
component: {
|
||||
name: 'output-selector',
|
||||
from: [...CertApplyPluginNames, 'AwsUploadToACM'],
|
||||
name: "output-selector",
|
||||
from: [...CertApplyPluginNames, "AwsUploadToACM"],
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
@@ -35,11 +34,11 @@ export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
certDomains!: string[];
|
||||
|
||||
@TaskInput({
|
||||
title: '区域',
|
||||
helper: '证书上传区域',
|
||||
title: "区域",
|
||||
helper: "证书上传区域",
|
||||
component: {
|
||||
name: 'a-auto-complete',
|
||||
vModel: 'value',
|
||||
name: "a-auto-complete",
|
||||
vModel: "value",
|
||||
options: AwsCNRegions,
|
||||
},
|
||||
required: true,
|
||||
@@ -47,26 +46,26 @@ export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
region!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: 'Access授权',
|
||||
helper: 'aws的授权',
|
||||
title: "Access授权",
|
||||
helper: "aws的授权",
|
||||
component: {
|
||||
name: 'access-selector',
|
||||
type: 'aws-cn',
|
||||
name: "access-selector",
|
||||
type: "aws-cn",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: '证书名称',
|
||||
helper: '上传后将以此名称作为前缀备注',
|
||||
title: "证书名称",
|
||||
helper: "上传后将以此名称作为前缀备注",
|
||||
})
|
||||
certName!: string;
|
||||
|
||||
@TaskInput(
|
||||
createRemoteSelectInputDefine({
|
||||
title: '分配ID',
|
||||
helper: '请选择distributions id',
|
||||
title: "分配ID",
|
||||
helper: "请选择distributions id",
|
||||
action: AwsCNDeployToCloudFront.prototype.onGetDistributions.name,
|
||||
required: true,
|
||||
})
|
||||
@@ -79,13 +78,13 @@ export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
const access = await this.getAccess<AwsCNAccess>(this.accessId);
|
||||
|
||||
let certId = this.cert as string;
|
||||
if (typeof this.cert !== 'string') {
|
||||
if (typeof this.cert !== "string") {
|
||||
//先上传
|
||||
certId = await this.uploadToIAM(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: {
|
||||
@@ -116,7 +115,7 @@ export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
await cloudFrontClient.send(updateDistributionCommand);
|
||||
this.logger.info(`部署${distributionId}完成:`);
|
||||
}
|
||||
this.logger.info('部署完成');
|
||||
this.logger.info("部署完成");
|
||||
}
|
||||
|
||||
private async uploadToIAM(access: AwsCNAccess, cert: CertInfo) {
|
||||
@@ -125,18 +124,18 @@ export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
region: this.region,
|
||||
});
|
||||
const awsCertID = await acmClient.importCertificate(cert, this.appendTimeSuffix(this.certName));
|
||||
this.logger.info('证书上传成功,id=', awsCertID);
|
||||
this.logger.info("证书上传成功,id=", awsCertID);
|
||||
return awsCertID;
|
||||
}
|
||||
|
||||
//查找分配ID列表选项
|
||||
async onGetDistributions() {
|
||||
if (!this.accessId) {
|
||||
throw new Error('请选择Access授权');
|
||||
throw new Error("请选择Access授权");
|
||||
}
|
||||
|
||||
const access = await this.getAccess<AwsCNAccess>(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: {
|
||||
@@ -149,7 +148,7 @@ export class AwsCNDeployToCloudFront 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) => {
|
||||
|
||||
Reference in New Issue
Block a user