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,4 +1,6 @@
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from "@certd/pipeline";
import { DomainRecord } from "@certd/plugin-lib";
import { AliyunAccess } from "./aliyun-access.js";
@IsAccess({
name: "aliesa",
@@ -40,6 +42,68 @@ export class AliesaAccess extends BaseAccess {
required: true,
})
region = "";
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
},
helper: "点击测试接口是否正常"
})
testRequest = true;
async onTestRequest() {
await this.getDomainListPage({
pageNo: 1,
pageSize: 1,
});
return "ok"
}
async getEsaClient(){
const access: AliesaAccess = this
const aliAccess = await this.ctx.accessService.getById(access.accessId) as AliyunAccess
const endpoint = `esa.${access.region}.aliyuncs.com`
return aliAccess.getClient(endpoint)
}
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
const pager = new Pager(req)
const client = await this.getEsaClient()
const ret = await client.doRequest({
// 接口名称
action: "ListSites",
// 接口版本
version: "2024-09-10",
// 接口协议
protocol: "HTTPS",
// 接口 HTTP 方法
method: "GET",
authType: "AK",
style: "RPC",
data: {
query: {
SiteName: req.searchKey,
// ["SiteSearchType"] = "exact";
SiteSearchType: "fuzzy",
AccessType: "NS",
PageSize: pager.pageSize,
PageNumber: pager.pageNo,
}
}
})
const list = ret.Sites?.map(item => ({
domain: item.SiteName,
id: item.SiteId,
}))
return {
list: list || [],
total: ret.TotalCount,
}
}
}
new AliesaAccess();
@@ -1,5 +1,6 @@
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
import { AliyunClientV2 } from "../lib/aliyun-client-v2.js";
import { AliyunSslClient } from "../lib/ssl-client.js";
@IsAccess({
name: "aliyun",
title: "阿里云授权",
@@ -28,6 +29,67 @@ export class AliyunAccess extends BaseAccess {
})
accessKeySecret = "";
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
},
helper: "点击测试接口是否正常"
})
testRequest = true;
async onTestRequest() {
await this.getCallerIdentity();
return "ok"
}
async getStsClient() {
const StsClient = await import('@alicloud/sts-sdk');
// 配置凭证
const sts = new StsClient.default({
endpoint: 'sts.aliyuncs.com',
accessKeyId: this.accessKeyId,
accessKeySecret: this.accessKeySecret,
});
return sts
}
async getCallerIdentity() {
const sts = await this.getStsClient();
// 调用 GetCallerIdentity 接口
const result = await sts.getCallerIdentity();
this.ctx.logger.log("✅ 密钥有效!");
this.ctx.logger.log(` 账户ID: ${result.AccountId}`);
this.ctx.logger.log(` ARN: ${result.Arn}`);
this.ctx.logger.log(` 用户ID: ${result.UserId}`);
return {
valid: true,
accountId: result.AccountId,
arn: result.Arn,
userId: result.UserId
};
}
getSslClient({ endpoint }: { endpoint: string }) {
const client = new AliyunSslClient({
access: this,
logger: this.ctx.logger,
endpoint,
});
return client
}
getClient(endpoint: string) {
return new AliyunClientV2({
access: this,