mirror of
https://github.com/certd/certd.git
synced 2026-06-24 19:47:34 +08:00
refactor(plugins): 部分插件改用运行时导入依赖替代静态导入
将所有插件内的静态依赖导入改为通过access.importRuntime动态导入,并调整package.json依赖顺序
This commit is contained in:
@@ -75,7 +75,7 @@ export class AzureAccess extends BaseAccess {
|
||||
this.ctx.logger.info("开始测试 Azure 认证...");
|
||||
|
||||
// 1. 先测试身份认证,获取访问令牌
|
||||
const { ClientSecretCredential } = await import("@azure/identity");
|
||||
const { ClientSecretCredential } = await this.importRuntime("@azure/identity");
|
||||
|
||||
const credential = new ClientSecretCredential(this.tenantId, this.clientId, this.clientSecret);
|
||||
|
||||
@@ -88,8 +88,8 @@ export class AzureAccess extends BaseAccess {
|
||||
}
|
||||
|
||||
async getDnsManagementClient() {
|
||||
const { DnsManagementClient } = await import("@azure/arm-dns");
|
||||
const { ClientSecretCredential } = await import("@azure/identity");
|
||||
const { DnsManagementClient } = await this.importRuntime("@azure/arm-dns");
|
||||
const { ClientSecretCredential } = await this.importRuntime("@azure/identity");
|
||||
|
||||
const credential = new ClientSecretCredential(this.tenantId, this.clientId, this.clientSecret);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export class GoogleClient {
|
||||
}
|
||||
async getEab() {
|
||||
// https://cloud.google.com/docs/authentication/api-keys-use#using-with-client-libs
|
||||
const { v1 } = await import("@google-cloud/publicca");
|
||||
const { v1 } = await this.access.importRuntime("@google-cloud/publicca");
|
||||
// process.env.HTTPS_PROXY = "http://127.0.0.1:10811";
|
||||
const access = this.access;
|
||||
if (!access.serviceAccountSecret) {
|
||||
|
||||
@@ -52,7 +52,7 @@ export class GoogleCloudDnsProvider extends AbstractDnsProvider<GoogleCloudDnsRe
|
||||
}
|
||||
|
||||
private async getGoogleDnsClient() {
|
||||
const { DNS } = await import("@google-cloud/dns");
|
||||
const { DNS } = await this.importRuntime("@google-cloud/dns");
|
||||
return new DNS({ credentials: this.credentials });
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ export class HuaweiAccess extends BaseAccess {
|
||||
async getProjectList() {
|
||||
const endpoint = "https://iam.cn-north-4.myhuaweicloud.com";
|
||||
|
||||
const { BasicCredentials } = await import("@huaweicloud/huaweicloud-sdk-core");
|
||||
const iam = await import("@huaweicloud/huaweicloud-sdk-iam/v3/public-api.js");
|
||||
const { BasicCredentials } = await this.importRuntime("@huaweicloud/huaweicloud-sdk-core");
|
||||
const iam = await this.importRuntime("@huaweicloud/huaweicloud-sdk-iam/v3/public-api.js");
|
||||
//恢复华为云把log4j的config改了的问题
|
||||
resetLogConfigure();
|
||||
const credentials: any = new BasicCredentials().withAk(this.accessKeyId).withSk(this.accessKeySecret);
|
||||
|
||||
@@ -120,8 +120,8 @@ export class HauweiDeployCertToCDN extends AbstractTaskPlugin {
|
||||
|
||||
async getCdnClient() {
|
||||
const access = await this.getAccess<HuaweiAccess>(this.accessId);
|
||||
const { BasicCredentials } = await import("@huaweicloud/huaweicloud-sdk-core");
|
||||
const cdn = await import("@huaweicloud/huaweicloud-sdk-cdn/v2/public-api.js");
|
||||
const { BasicCredentials } = await this.importRuntime("@huaweicloud/huaweicloud-sdk-core");
|
||||
const cdn = await this.importRuntime("@huaweicloud/huaweicloud-sdk-cdn/v2/public-api.js");
|
||||
//恢复华为云把log4j的config改了的问题
|
||||
resetLogConfigure();
|
||||
const credentials = new BasicCredentials().withAk(access.accessKeyId).withSk(access.accessKeySecret);
|
||||
|
||||
@@ -103,8 +103,8 @@ export class HauweiDeployCertToELB extends AbstractTaskPlugin {
|
||||
throw new Error("项目ID不能为空");
|
||||
}
|
||||
const access = await this.getAccess<HuaweiAccess>(this.accessId);
|
||||
const { BasicCredentials } = await import("@huaweicloud/huaweicloud-sdk-core");
|
||||
const elb = await import("@huaweicloud/huaweicloud-sdk-elb/v3/public-api.js");
|
||||
const { BasicCredentials } = await this.importRuntime("@huaweicloud/huaweicloud-sdk-core");
|
||||
const elb = await this.importRuntime("@huaweicloud/huaweicloud-sdk-elb/v3/public-api.js");
|
||||
//恢复华为云把log4j的config改了的问题
|
||||
resetLogConfigure();
|
||||
const projectArr = this.projectId.split("_");
|
||||
|
||||
@@ -91,7 +91,7 @@ export class HauweiDeployCertToOBS extends AbstractTaskPlugin {
|
||||
const regionStr = region ? `${region}.` : "cn-north-4.";
|
||||
const bucketStr = bucket ? `${bucket}.` : "";
|
||||
const access = await this.getAccess<HuaweiAccess>(this.accessId);
|
||||
const sdk = await import("esdk-obs-nodejs");
|
||||
const sdk = await this.importRuntime("esdk-obs-nodejs");
|
||||
const obsClient = new sdk.default({
|
||||
// 推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险
|
||||
// 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html
|
||||
|
||||
@@ -62,8 +62,8 @@ export class HauweiUploadToCCM extends AbstractTaskPlugin {
|
||||
|
||||
async getCcmClient() {
|
||||
const access = await this.getAccess<HuaweiAccess>(this.accessId);
|
||||
const { BasicCredentials } = await import("@huaweicloud/huaweicloud-sdk-core");
|
||||
const { ClientBuilder } = await import("@huaweicloud/huaweicloud-sdk-core/ClientBuilder.js");
|
||||
const { BasicCredentials } = await this.importRuntime("@huaweicloud/huaweicloud-sdk-core");
|
||||
const { ClientBuilder } = await this.importRuntime("@huaweicloud/huaweicloud-sdk-core/ClientBuilder.js");
|
||||
//@ts-ignore
|
||||
const { HuaweiCcmClient } = await import("./ccm-client.js");
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export class FtpClient {
|
||||
}
|
||||
|
||||
async connect(callback: (client: FtpClient) => Promise<any>) {
|
||||
const ftp = await import("basic-ftp");
|
||||
const ftp = await this.access.importRuntime("basic-ftp");
|
||||
const Client = ftp.Client;
|
||||
const client = new Client();
|
||||
client.ftp.verbose = true;
|
||||
|
||||
@@ -43,7 +43,7 @@ export class QiniuClient {
|
||||
}
|
||||
|
||||
async doRequest(url: string, method: string, body?: any) {
|
||||
const { generateAccessToken } = await import("qiniu/qiniu/util.js");
|
||||
const { generateAccessToken } = await this.access.importRuntime("qiniu/qiniu/util.js");
|
||||
const token = generateAccessToken(this.access, url);
|
||||
const res = await this.http.request({
|
||||
url,
|
||||
@@ -65,8 +65,8 @@ export class QiniuClient {
|
||||
}
|
||||
|
||||
async doRequestV2(opts: { url: string; method: string; body?: any; contentType: string }) {
|
||||
const { HttpClient } = await import("qiniu/qiniu/httpc/client.js");
|
||||
const { QiniuAuthMiddleware } = await import("qiniu/qiniu/httpc/middleware/qiniuAuth.js");
|
||||
const { HttpClient } = await this.access.importRuntime("qiniu/qiniu/httpc/client.js");
|
||||
const { QiniuAuthMiddleware } = await this.access.importRuntime("qiniu/qiniu/httpc/middleware/qiniuAuth.js");
|
||||
// X-Qiniu-Date: 20060102T150405Z
|
||||
const auth = new QiniuAuthMiddleware({
|
||||
mac: {
|
||||
@@ -100,7 +100,7 @@ export class QiniuClient {
|
||||
}
|
||||
|
||||
async uploadFile(bucket: string, key: string, content: Buffer | string) {
|
||||
const sdk = await import("qiniu");
|
||||
const sdk = await this.access.importRuntime("qiniu");
|
||||
const qiniu = sdk.default;
|
||||
const mac = new qiniu.auth.digest.Mac(this.access.accessKey, this.access.secretKey);
|
||||
const options = {
|
||||
@@ -161,7 +161,7 @@ export class QiniuClient {
|
||||
}
|
||||
|
||||
private async getBucketManager() {
|
||||
const sdk = await import("qiniu");
|
||||
const sdk = await this.access.importRuntime("qiniu");
|
||||
const qiniu = sdk.default;
|
||||
const mac = new qiniu.auth.digest.Mac(this.access.accessKey, this.access.secretKey);
|
||||
const config = new qiniu.conf.Config();
|
||||
|
||||
@@ -73,7 +73,7 @@ export class UCloudAccess extends BaseAccess {
|
||||
if (this.client) {
|
||||
return this.client;
|
||||
}
|
||||
const { Client } = await import("@ucloud-sdks/ucloud-sdk-js");
|
||||
const { Client } = await this.importRuntime("@ucloud-sdks/ucloud-sdk-js");
|
||||
const client = new Client({
|
||||
config: {
|
||||
region: region || "cn-bj2",
|
||||
@@ -197,7 +197,7 @@ export class UCloudAccess extends BaseAccess {
|
||||
}
|
||||
|
||||
async invoke(req: { Action: string; [key: string]: any }) {
|
||||
const { Request } = await import("@ucloud-sdks/ucloud-sdk-js");
|
||||
const { Request } = await this.importRuntime("@ucloud-sdks/ucloud-sdk-js");
|
||||
const client = await this.getClient();
|
||||
const resp = await client.invoke(
|
||||
new Request({
|
||||
|
||||
@@ -14,7 +14,7 @@ export class VolcengineCdnClient {
|
||||
if (this.service) {
|
||||
return this.service;
|
||||
}
|
||||
const { cdn } = await import("@volcengine/openapi");
|
||||
const { cdn } = await this.opts.access.importRuntime("@volcengine/openapi");
|
||||
const service = new cdn.CdnService();
|
||||
// 设置ak、sk
|
||||
service.setAccessKeyId(this.opts.access.accessKeyId);
|
||||
|
||||
@@ -21,7 +21,7 @@ export class VolcengineDnsClient {
|
||||
}
|
||||
|
||||
async doRequest(req: VolcengineReq) {
|
||||
const { Signer } = await import("@volcengine/openapi");
|
||||
const { Signer } = await this.opts.access.importRuntime("@volcengine/openapi");
|
||||
|
||||
// http request data
|
||||
const openApiRequestData: any = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { VolcengineAccess } from "./access.js";
|
||||
import { VolcengineAccess } from "./access.js";
|
||||
import { HttpClient, ILogger } from "@certd/basic";
|
||||
|
||||
export type VolcengineOpts = {
|
||||
@@ -140,7 +140,7 @@ export class VolcengineClient {
|
||||
}
|
||||
|
||||
async getTOSService(opts: { region?: string }) {
|
||||
const { TosClient } = await import("@volcengine/tos-sdk");
|
||||
const { TosClient } = await this.opts.access.importRuntime("@volcengine/tos-sdk");
|
||||
|
||||
const client = new TosClient({
|
||||
accessKeyId: this.opts.access.accessKeyId,
|
||||
@@ -169,7 +169,7 @@ export class VolcengineClient {
|
||||
if (this.CommonService) {
|
||||
return this.CommonService;
|
||||
}
|
||||
const { Service } = await import("@volcengine/openapi");
|
||||
const { Service } = await this.opts.access.importRuntime("@volcengine/openapi");
|
||||
|
||||
class CommonService extends Service {
|
||||
Generic: any;
|
||||
|
||||
Reference in New Issue
Block a user