Files
certd/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-live/index.ts
T

131 lines
3.6 KiB
TypeScript
Raw Normal View History

2025-05-10 15:04:57 +08:00
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
import { createRemoteSelectInputDefine } from "@certd/plugin-lib";
import { TencentAccess } from "../../../plugin-lib/tencent/access.js";
import { TencentSslClient } from "../../../plugin-lib/tencent/index.js";
2025-05-10 15:04:57 +08:00
2025-01-19 14:12:16 +08:00
@IsTaskPlugin({
2026-05-31 01:41:33 +08:00
name: "TencentDeployCertToLive",
title: "腾讯云-部署到腾讯云直播",
icon: "svg:icon-tencentcloud",
desc: "https://console.cloud.tencent.com/live/",
2025-01-19 14:12:16 +08:00
group: pluginGroups.tencent.key,
2025-05-10 15:04:57 +08:00
needPlus: false,
dependPlugins: {
"access:tencent": "*",
},
2025-01-19 14:12:16 +08:00
default: {
strategy: {
runStrategy: RunStrategy.SkipWhenSucceed,
},
},
})
2025-05-10 15:04:57 +08:00
export class TencentDeployCertToLive extends AbstractTaskPlugin {
2025-01-19 14:12:16 +08:00
@TaskInput({
2026-05-31 01:41:33 +08:00
title: "Access提供者",
helper: "access 授权",
2025-01-19 14:12:16 +08:00
component: {
2026-05-31 01:41:33 +08:00
name: "access-selector",
type: "tencent",
2025-01-19 14:12:16 +08:00
},
required: true,
})
accessId!: string;
@TaskInput(
createRemoteSelectInputDefine({
2026-05-31 01:41:33 +08:00
title: "直播域名",
helper: "请选择域名或输入域名",
typeName: "TencentDeployCertToLive",
2025-01-19 14:12:16 +08:00
action: TencentDeployCertToLive.prototype.onGetDomainList.name,
})
)
domains!: string[];
@TaskInput({
2026-05-31 01:41:33 +08:00
title: "域名证书",
helper: "请选择前置任务输出的域名证书,或者选择前置任务“上传证书到腾讯云”任务的证书ID",
2025-01-19 14:12:16 +08:00
component: {
2026-05-31 01:41:33 +08:00
name: "output-selector",
from: [...CertApplyPluginNames, "UploadCertToTencent"],
2025-01-19 14:12:16 +08:00
},
required: true,
})
cert!: CertInfo | string;
async onInstance() {}
async execute(): Promise<void> {
const access = await this.getAccess<TencentAccess>(this.accessId);
2025-01-19 14:12:16 +08:00
let tencentCertId = this.cert as string;
2026-05-31 01:41:33 +08:00
if (typeof this.cert !== "string") {
2025-01-19 14:12:16 +08:00
const sslClient = new TencentSslClient({
access,
logger: this.logger,
});
tencentCertId = await sslClient.uploadToTencent({
2026-05-31 01:41:33 +08:00
certName: this.appendTimeSuffix("certd"),
2025-01-19 14:12:16 +08:00
cert: this.cert,
});
}
const client = await this.getLiveClient();
const domainNames = this.domains.map((item: any) => {
return {
DomainName: item,
Status: -1,
};
});
const params = {
DomainInfos: domainNames,
CloudCertId: tencentCertId,
};
const res = await client.ModifyLiveDomainCertBindings(params);
this.checkRet(res);
2026-05-31 01:41:33 +08:00
this.logger.info("部署完成", JSON.stringify(res));
2025-01-19 14:12:16 +08:00
}
checkRet(ret: any) {
if (!ret || ret.Error) {
2026-05-31 01:41:33 +08:00
throw new Error("执行失败:" + ret.Error.Code + "," + ret.Error.Message);
2025-01-19 14:12:16 +08:00
}
}
async getLiveClient() {
const accessProvider = await this.getAccess<TencentAccess>(this.accessId);
const sdk = await this.importRuntime("tencentcloud-sdk-nodejs/tencentcloud/services/live/v20180801/index.js");
2025-01-19 14:12:16 +08:00
const CssClient = sdk.v20180801.Client;
const clientConfig = {
credential: {
secretId: accessProvider.secretId,
secretKey: accessProvider.secretKey,
},
2026-05-31 01:41:33 +08:00
region: "",
2025-01-19 14:12:16 +08:00
profile: {
httpProfile: {
2025-08-25 16:19:37 +08:00
endpoint: `live.${accessProvider.intlDomain()}tencentcloudapi.com`,
2025-01-19 14:12:16 +08:00
},
},
};
return new CssClient(clientConfig);
}
async onGetDomainList(data: any) {
const client = await this.getLiveClient();
const res = await client.DescribeLiveDomains({
PageSize: 100,
});
this.checkRet(res);
return res.DomainList.map((item: any) => {
return {
label: item.Name,
value: item.Name,
};
});
}
}