perf: 所有授权增加测试按钮

This commit is contained in:
xiaojunnuo
2026-02-15 18:44:35 +08:00
parent 42c7ec2f75
commit 7a3e68d656
39 changed files with 1876 additions and 662 deletions
@@ -1,5 +1,6 @@
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
import { AwsRegions } from './constants.js';
import { AwsClient } from './libs/aws-client.js';
@IsAccess({
name: 'aws',
@@ -33,7 +34,7 @@ export class AwsAccess extends BaseAccess {
@AccessInput({
title: 'region',
component: {
name:"a-select",
name: "a-select",
options: AwsRegions,
},
required: true,
@@ -41,6 +42,25 @@ export class AwsAccess extends BaseAccess {
options: AwsRegions,
})
region = '';
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
},
helper: "测试授权是否正确"
})
testRequest = true;
async onTestRequest() {
const client = new AwsClient({ access: this, logger: this.ctx.logger, region: this.region || 'us-east-1' });
await client.getCallerIdentity();
return "ok";
}
}
new AwsAccess();
@@ -45,6 +45,26 @@ export class AwsClient {
}
async getCallerIdentity() {
const { STSClient, GetCallerIdentityCommand } = await import ("@aws-sdk/client-sts");
const client = new STSClient({
region: this.access.region || 'us-east-1',
credentials: {
accessKeyId: this.access.accessKeyId, // 从环境变量中读取
secretAccessKey: this.access.secretAccessKey,
},
});
const command = new GetCallerIdentityCommand({});
const response = await client.send(command);
this.logger.info(` 账户ID: ${response.Account}`);
this.logger.info(` ARN: ${response.Arn}`);
this.logger.info(` 用户ID: ${response.UserId}`);
return response;
}
async route53ClientGet() {
const { Route53Client } = await import('@aws-sdk/client-route-53');
return new Route53Client({
@@ -85,7 +105,7 @@ 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) {
@@ -93,7 +113,7 @@ export class AwsClient {
}
const command = new ListHostedZonesByNameCommand(input);
const response = await this.doRequest(() => client.send(command));
let list :any[]= response.HostedZones || [];
let list: any[] = response.HostedZones || [];
list = list.map((item: any) => ({
id: item.Id.replace('/hostedzone/', ''),
domain: item.Name,