2025-01-02 00:28:13 +08:00
|
|
|
import { IsAccess, AccessInput, BaseAccess } from "@certd/pipeline";
|
|
|
|
|
|
2026-06-19 17:44:57 +08:00
|
|
|
const tencentAccessDefine: any = {
|
2025-01-02 00:28:13 +08:00
|
|
|
name: "tencent",
|
|
|
|
|
title: "腾讯云",
|
|
|
|
|
icon: "svg:icon-tencentcloud",
|
2025-08-25 16:19:37 +08:00
|
|
|
order: 0,
|
2026-06-19 17:44:57 +08:00
|
|
|
dependPackages: {
|
|
|
|
|
"tencentcloud-sdk-nodejs": "^4.1.112",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@IsAccess(tencentAccessDefine)
|
2025-01-02 00:28:13 +08:00
|
|
|
export class TencentAccess extends BaseAccess {
|
|
|
|
|
@AccessInput({
|
|
|
|
|
title: "secretId",
|
2025-06-20 16:58:20 +08:00
|
|
|
helper: "使用对应的插件需要有对应的权限,比如上传证书,需要证书管理权限;部署到clb需要clb相关权限\n前往[密钥管理](https://console.cloud.tencent.com/cam/capi)进行创建",
|
2025-01-02 00:28:13 +08:00
|
|
|
component: {
|
|
|
|
|
placeholder: "secretId",
|
|
|
|
|
},
|
|
|
|
|
rules: [{ required: true, message: "该项必填" }],
|
|
|
|
|
})
|
|
|
|
|
secretId = "";
|
|
|
|
|
@AccessInput({
|
|
|
|
|
title: "secretKey",
|
|
|
|
|
component: {
|
|
|
|
|
placeholder: "secretKey",
|
|
|
|
|
},
|
|
|
|
|
encrypt: true,
|
|
|
|
|
rules: [{ required: true, message: "该项必填" }],
|
|
|
|
|
})
|
|
|
|
|
secretKey = "";
|
2025-06-20 16:58:20 +08:00
|
|
|
|
|
|
|
|
@AccessInput({
|
|
|
|
|
title: "站点类型",
|
|
|
|
|
value: "cn",
|
|
|
|
|
component: {
|
|
|
|
|
name: "a-select",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "国内站",
|
|
|
|
|
value: "cn",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "国际站",
|
|
|
|
|
value: "intl",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2025-06-20 23:18:59 +08:00
|
|
|
encrypt: false,
|
2025-06-20 16:58:20 +08:00
|
|
|
rules: [{ required: true, message: "该项必填" }],
|
|
|
|
|
})
|
|
|
|
|
accountType: string;
|
|
|
|
|
|
2025-08-17 23:32:29 +08:00
|
|
|
@AccessInput({
|
|
|
|
|
title: "关闭证书过期通知",
|
|
|
|
|
value: true,
|
|
|
|
|
component: {
|
|
|
|
|
name: "a-switch",
|
|
|
|
|
vModel: "checked",
|
|
|
|
|
},
|
|
|
|
|
})
|
2026-05-31 01:41:33 +08:00
|
|
|
closeExpiresNotify = true;
|
2025-08-17 23:32:29 +08:00
|
|
|
|
2026-02-15 22:45:22 +08:00
|
|
|
@AccessInput({
|
|
|
|
|
title: "测试",
|
|
|
|
|
component: {
|
|
|
|
|
name: "api-test",
|
|
|
|
|
action: "onTestRequest",
|
|
|
|
|
},
|
|
|
|
|
helper: "点击测试接口看是否正常",
|
|
|
|
|
})
|
|
|
|
|
testRequest = true;
|
|
|
|
|
|
|
|
|
|
async onTestRequest() {
|
|
|
|
|
await this.getCallerIdentity();
|
|
|
|
|
return "ok";
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 16:58:20 +08:00
|
|
|
isIntl() {
|
|
|
|
|
return this.accountType === "intl";
|
|
|
|
|
}
|
2025-08-25 16:19:37 +08:00
|
|
|
|
|
|
|
|
intlDomain() {
|
|
|
|
|
return this.isIntl() ? "intl." : "";
|
|
|
|
|
}
|
2025-11-13 00:45:05 +08:00
|
|
|
|
|
|
|
|
buildEndpoint(endpoint: string) {
|
|
|
|
|
return `${this.intlDomain()}${endpoint}`;
|
|
|
|
|
}
|
2026-02-15 22:45:22 +08:00
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
async getCallerIdentity() {
|
2026-02-15 22:45:22 +08:00
|
|
|
const client = await this.getStsClient();
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
// 调用 GetCallerIdentity 接口
|
2026-02-15 22:45:22 +08:00
|
|
|
const result = await client.GetCallerIdentity();
|
2026-05-31 01:41:33 +08:00
|
|
|
|
2026-02-15 22:45:22 +08:00
|
|
|
this.ctx.logger.info("✅ 密钥有效!");
|
|
|
|
|
this.ctx.logger.info(` 账户ID: ${result.AccountId}`);
|
|
|
|
|
this.ctx.logger.info(` ARN: ${result.Arn}`);
|
|
|
|
|
this.ctx.logger.info(` 用户ID: ${result.UserId}`);
|
2026-05-31 01:41:33 +08:00
|
|
|
|
2026-02-15 22:45:22 +08:00
|
|
|
return {
|
|
|
|
|
valid: true,
|
|
|
|
|
accountId: result.AccountId,
|
|
|
|
|
arn: result.Arn,
|
2026-05-31 01:41:33 +08:00
|
|
|
userId: result.UserId,
|
2026-02-15 22:45:22 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
async getStsClient() {
|
2026-06-19 17:44:57 +08:00
|
|
|
const sdk = await (this as any).importRuntime("tencentcloud-sdk-nodejs/tencentcloud/services/sts/v20180813/index.js");
|
2026-02-15 22:45:22 +08:00
|
|
|
const StsClient = sdk.v20180813.Client;
|
|
|
|
|
|
|
|
|
|
const clientConfig = {
|
|
|
|
|
credential: {
|
|
|
|
|
secretId: this.secretId,
|
|
|
|
|
secretKey: this.secretKey,
|
|
|
|
|
},
|
2026-05-31 01:41:33 +08:00
|
|
|
region: "ap-shanghai",
|
2026-02-15 22:45:22 +08:00
|
|
|
profile: {
|
|
|
|
|
httpProfile: {
|
|
|
|
|
endpoint: `sts.${this.intlDomain()}tencentcloudapi.com`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new StsClient(clientConfig);
|
|
|
|
|
}
|
2025-01-02 00:28:13 +08:00
|
|
|
}
|