mirror of
https://github.com/certd/certd.git
synced 2026-06-27 14:07:33 +08:00
chore: 完善第三方依赖动态加载
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ export class AliyunDnsProvider extends AbstractDnsProvider {
|
||||
async onInstance() {
|
||||
const access: AliyunAccess = this.ctx.access as AliyunAccess;
|
||||
|
||||
this.client = new AliyunClient({ logger: this.logger });
|
||||
this.client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
await this.client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
@@ -241,7 +241,7 @@ export class DeployCertToAliyunAckPlugin extends AbstractTaskPlugin {
|
||||
}
|
||||
|
||||
async getClient(aliyunProvider: any, regionId: string) {
|
||||
const client = new AliyunClient({ logger: this.logger, useROAClient: true });
|
||||
const client = new AliyunClient({ logger: this.logger, useROAClient: true, importRuntime: aliyunProvider.importRuntime.bind(aliyunProvider) });
|
||||
await client.init({
|
||||
accessKeyId: aliyunProvider.accessKeyId,
|
||||
accessKeySecret: aliyunProvider.accessKeySecret,
|
||||
|
||||
@@ -128,7 +128,7 @@ export class AliyunDeployCertToALB extends AbstractTaskPlugin {
|
||||
async onInstance() {}
|
||||
|
||||
async getLBClient(access: AliyunAccess, region: string) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
const client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
|
||||
const version = "2020-06-16";
|
||||
await client.init({
|
||||
|
||||
@@ -231,7 +231,7 @@ export class DeployCertToAliyunApig extends AbstractTaskPlugin {
|
||||
return {
|
||||
list: records,
|
||||
total: res?.data?.totalSize || 0,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async onGetRegionList(data: any) {
|
||||
|
||||
+2
-2
@@ -134,7 +134,7 @@ export class DeployCertToAliyunApiGateway extends AbstractTaskPlugin {
|
||||
const access = await this.getAccess<AliyunAccess>(this.accessId);
|
||||
const client = access.getClient(this.regionEndpoint);
|
||||
|
||||
const pager = new Pager(data)
|
||||
const pager = new Pager(data);
|
||||
const res = await client.doRequest({
|
||||
// 接口名称
|
||||
action: "DescribeApiGroups",
|
||||
@@ -162,7 +162,7 @@ export class DeployCertToAliyunApiGateway extends AbstractTaskPlugin {
|
||||
return {
|
||||
list: records,
|
||||
total: res?.TotalCount || 0,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async onGetDomainList(data: any) {
|
||||
|
||||
@@ -209,7 +209,7 @@ export class DeployCertToAliyunCDN extends AbstractTaskPlugin {
|
||||
}
|
||||
|
||||
async getClient(access: AliyunAccess) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
const client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
await client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
@@ -143,7 +143,7 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin {
|
||||
}
|
||||
|
||||
async getClient(access: AliyunAccess) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
const client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
await client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
@@ -137,8 +137,8 @@ export class AliyunDeployCertToFC extends AbstractTaskPlugin {
|
||||
|
||||
const client = await this.getClient(access);
|
||||
|
||||
const $Util = await import("@alicloud/tea-util");
|
||||
const $OpenApi = await import("@alicloud/openapi-client");
|
||||
const $Util = await access.importRuntime("@alicloud/tea-util");
|
||||
const $OpenApi = await access.importRuntime("@alicloud/openapi-client");
|
||||
|
||||
let privateKey = this.cert.key;
|
||||
try {
|
||||
@@ -204,7 +204,7 @@ export class AliyunDeployCertToFC extends AbstractTaskPlugin {
|
||||
}
|
||||
|
||||
async getClient(access: AliyunAccess) {
|
||||
const $OpenApi = await import("@alicloud/openapi-client");
|
||||
const $OpenApi = await access.importRuntime("@alicloud/openapi-client");
|
||||
const config = new $OpenApi.Config({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
@@ -221,8 +221,8 @@ export class AliyunDeployCertToFC extends AbstractTaskPlugin {
|
||||
const access = await this.getAccess<AliyunAccess>(this.accessId);
|
||||
const client = await this.getClient(access);
|
||||
|
||||
const $OpenApi = await import("@alicloud/openapi-client");
|
||||
const $Util = await import("@alicloud/tea-util");
|
||||
const $OpenApi = await access.importRuntime("@alicloud/openapi-client");
|
||||
const $Util = await access.importRuntime("@alicloud/tea-util");
|
||||
const params = new $OpenApi.Params({
|
||||
// 接口名称
|
||||
action: "ListCustomDomains",
|
||||
|
||||
@@ -117,7 +117,7 @@ export class AliyunDeployCertToNLB extends AbstractTaskPlugin {
|
||||
async onInstance() {}
|
||||
|
||||
async getLBClient(access: AliyunAccess, region: string) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
const client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
|
||||
const version = "2022-04-30";
|
||||
await client.init({
|
||||
|
||||
@@ -196,7 +196,7 @@ export class DeployCertToAliyunOSS extends AbstractTaskPlugin {
|
||||
|
||||
async getClient(access: AliyunAccess) {
|
||||
// @ts-ignore
|
||||
const OSS = await import("ali-oss");
|
||||
const OSS = await access.importRuntime("ali-oss");
|
||||
return new OSS.default({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
@@ -130,7 +130,7 @@ export class AliyunDeployCertToSLB extends AbstractTaskPlugin {
|
||||
async onInstance() {}
|
||||
|
||||
async getLBClient(access: AliyunAccess, region: string) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
const client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
const version = "2014-05-15";
|
||||
await client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ export class AliyunDeployCertToWafCloud extends AbstractTaskPlugin {
|
||||
async onInstance() {}
|
||||
|
||||
async getWafClient(access: AliyunAccess) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
const client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
await client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ export class AliyunDeployCertToWaf extends AbstractTaskPlugin {
|
||||
async onInstance() {}
|
||||
|
||||
async getWafClient(access: AliyunAccess) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
const client = new AliyunClient({ logger: this.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
await client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
@@ -15,7 +15,7 @@ export class AwsIAMClient {
|
||||
}
|
||||
async importCertificate(certInfo: CertInfo, certName: string) {
|
||||
// 创建 IAM 客户端
|
||||
const { IAMClient, UploadServerCertificateCommand } = await import("@aws-sdk/client-iam");
|
||||
const { IAMClient, UploadServerCertificateCommand } = await this.access.importRuntime("@aws-sdk/client-iam");
|
||||
const iamClient = new IAMClient({
|
||||
region: this.region, // 替换为您的 AWS 区域
|
||||
credentials: {
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
}
|
||||
//部署到CloudFront
|
||||
|
||||
const { CloudFrontClient, UpdateDistributionCommand, GetDistributionConfigCommand } = await import("@aws-sdk/client-cloudfront");
|
||||
const { CloudFrontClient, UpdateDistributionCommand, GetDistributionConfigCommand } = await this.importRuntime("@aws-sdk/client-cloudfront");
|
||||
const cloudFrontClient = new CloudFrontClient({
|
||||
region: this.region,
|
||||
credentials: {
|
||||
@@ -135,7 +135,7 @@ export class AwsCNDeployToCloudFront extends AbstractTaskPlugin {
|
||||
}
|
||||
|
||||
const access = await this.getAccess<AwsCNAccess>(this.accessId);
|
||||
const { CloudFrontClient, ListDistributionsCommand } = await import("@aws-sdk/client-cloudfront");
|
||||
const { CloudFrontClient, ListDistributionsCommand } = await this.importRuntime("@aws-sdk/client-cloudfront");
|
||||
const cloudFrontClient = new CloudFrontClient({
|
||||
region: this.region,
|
||||
credentials: {
|
||||
|
||||
@@ -21,7 +21,7 @@ export class AwsClient {
|
||||
}
|
||||
async importCertificate(certInfo: CertInfo) {
|
||||
// 创建 ACM 客户端
|
||||
const { ACMClient, ImportCertificateCommand } = await import("@aws-sdk/client-acm");
|
||||
const { ACMClient, ImportCertificateCommand } = await this.access.importRuntime("@aws-sdk/client-acm");
|
||||
const acmClient = new ACMClient({
|
||||
region: this.region, // 替换为您的 AWS 区域
|
||||
credentials: {
|
||||
@@ -49,7 +49,7 @@ export class AwsClient {
|
||||
}
|
||||
|
||||
async getCallerIdentity() {
|
||||
const { STSClient, GetCallerIdentityCommand } = await import("@aws-sdk/client-sts");
|
||||
const { STSClient, GetCallerIdentityCommand } = await this.access.importRuntime("@aws-sdk/client-sts");
|
||||
|
||||
const client = new STSClient({
|
||||
region: this.access.region || "us-east-1",
|
||||
@@ -68,7 +68,7 @@ export class AwsClient {
|
||||
}
|
||||
|
||||
async route53ClientGet() {
|
||||
const { Route53Client } = await import("@aws-sdk/client-route-53");
|
||||
const { Route53Client } = await this.access.importRuntime("@aws-sdk/client-route-53");
|
||||
return new Route53Client({
|
||||
region: this.region,
|
||||
credentials: {
|
||||
@@ -88,7 +88,7 @@ export class AwsClient {
|
||||
};
|
||||
}
|
||||
async route53ListHostedZones(name: string): Promise<{ Id: string; Name: string }[]> {
|
||||
const { ListHostedZonesByNameCommand } = await import("@aws-sdk/client-route-53"); // ES Modules import
|
||||
const { ListHostedZonesByNameCommand } = await this.access.importRuntime("@aws-sdk/client-route-53"); // ES Modules import
|
||||
|
||||
const client = await this.route53ClientGet();
|
||||
const input = {
|
||||
@@ -96,7 +96,7 @@ export class AwsClient {
|
||||
DNSName: name,
|
||||
};
|
||||
const command = new ListHostedZonesByNameCommand(input);
|
||||
const response = await this.doRequest(() => client.send(command));
|
||||
const response: any = await this.doRequest(() => client.send(command));
|
||||
if (response.HostedZones.length === 0) {
|
||||
throw new Error(`找不到 HostedZone ${name}`);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ export class AwsClient {
|
||||
}
|
||||
|
||||
async route53ListHostedZonesPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
const { ListHostedZonesByNameCommand } = await import("@aws-sdk/client-route-53"); // ES Modules import
|
||||
const { ListHostedZonesByNameCommand } = await this.access.importRuntime("@aws-sdk/client-route-53"); // ES Modules import
|
||||
|
||||
const client = await this.route53ClientGet();
|
||||
const input: any = {
|
||||
@@ -116,7 +116,7 @@ export class AwsClient {
|
||||
input.DNSName = req.searchKey;
|
||||
}
|
||||
const command = new ListHostedZonesByNameCommand(input);
|
||||
const response = await this.doRequest(() => client.send(command));
|
||||
const response: any = await this.doRequest(() => client.send(command));
|
||||
let list: any[] = response.HostedZones || [];
|
||||
list = list.map((item: any) => ({
|
||||
id: item.Id.replace("/hostedzone/", ""),
|
||||
@@ -129,7 +129,7 @@ export class AwsClient {
|
||||
}
|
||||
|
||||
async route53ChangeRecord(req: { hostedZoneId: string; fullRecord: string; type: string; value: string; action: "UPSERT" | "DELETE" }) {
|
||||
const { ChangeResourceRecordSetsCommand } = await import("@aws-sdk/client-route-53"); // ES Modules import
|
||||
const { ChangeResourceRecordSetsCommand } = await this.access.importRuntime("@aws-sdk/client-route-53"); // ES Modules import
|
||||
// const { Route53Client, ChangeResourceRecordSetsCommand } = require("@aws-sdk/client-route-53"); // CommonJS import
|
||||
// import type { Route53ClientConfig } from "@aws-sdk/client-route-53";
|
||||
const client = await this.route53ClientGet();
|
||||
|
||||
+2
-2
@@ -79,7 +79,7 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
|
||||
}
|
||||
//部署到CloudFront
|
||||
|
||||
const { CloudFrontClient, UpdateDistributionCommand, GetDistributionConfigCommand } = await import("@aws-sdk/client-cloudfront");
|
||||
const { CloudFrontClient, UpdateDistributionCommand, GetDistributionConfigCommand } = await this.importRuntime("@aws-sdk/client-cloudfront");
|
||||
const cloudFrontClient = new CloudFrontClient({
|
||||
region: this.region,
|
||||
credentials: {
|
||||
@@ -133,7 +133,7 @@ export class AwsDeployToCloudFront extends AbstractTaskPlugin {
|
||||
}
|
||||
|
||||
const access = await this.getAccess<AwsAccess>(this.accessId);
|
||||
const { CloudFrontClient, ListDistributionsCommand } = await import("@aws-sdk/client-cloudfront");
|
||||
const { CloudFrontClient, ListDistributionsCommand } = await this.importRuntime("@aws-sdk/client-cloudfront");
|
||||
const cloudFrontClient = new CloudFrontClient({
|
||||
region: this.region,
|
||||
credentials: {
|
||||
|
||||
@@ -122,7 +122,7 @@ export class AzureAccess extends BaseAccess {
|
||||
|
||||
this.ctx.logger.info(`找到 DNS 区域: ${matchingZone.name}, ID: ${matchingZone.id}`);
|
||||
return {
|
||||
id: matchingZone.id.split("/").pop()!,
|
||||
id: matchingZone.id.split("/").pop() || "",
|
||||
name: matchingZone.name,
|
||||
};
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export class AzureAccess extends BaseAccess {
|
||||
}
|
||||
|
||||
list = list.map((item: any) => ({
|
||||
id: item.id.split("/").pop()!,
|
||||
id: item.id.split("/").pop() || "",
|
||||
domain: item.name,
|
||||
}));
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ export class CmccClient {
|
||||
async getToken(): Promise<string> {
|
||||
// 检查是否有有效的token
|
||||
if (this.isTokenValid()) {
|
||||
return this.token!;
|
||||
return this.token;
|
||||
}
|
||||
|
||||
const datetime = this.getCurrentIsoTime();
|
||||
|
||||
@@ -36,10 +36,10 @@ export class DynadotDnsProvider extends AbstractDnsProvider<DynadotRecord> {
|
||||
record_type: type.toLowerCase(),
|
||||
record_value1: value,
|
||||
record_value2: "",
|
||||
}
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
await this.postRecords(domain, {subRecords, mainRecords: [], addToCurrent: true});
|
||||
await this.postRecords(domain, { subRecords, mainRecords: [], addToCurrent: true });
|
||||
|
||||
this.logger.info("添加域名解析成功:", fullRecord, value);
|
||||
return {
|
||||
@@ -79,8 +79,8 @@ export class DynadotDnsProvider extends AbstractDnsProvider<DynadotRecord> {
|
||||
record_type: "txt",
|
||||
record_value1: "init_txt_by_certd",
|
||||
record_value2: "",
|
||||
}
|
||||
]
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
await this.postRecords(domain, {
|
||||
@@ -132,7 +132,7 @@ export class DynadotDnsProvider extends AbstractDnsProvider<DynadotRecord> {
|
||||
return { mainRecords, subRecords };
|
||||
}
|
||||
|
||||
private async postRecords(domain: string, records: { mainRecords: MainRecordItem[]; subRecords: SubRecordItem[] ,addToCurrent: boolean}): Promise<void> {
|
||||
private async postRecords(domain: string, records: { mainRecords: MainRecordItem[]; subRecords: SubRecordItem[]; addToCurrent: boolean }): Promise<void> {
|
||||
await this.access.doRequest({
|
||||
method: "POST",
|
||||
path: `/restful/v2/domains/${domain}/records`,
|
||||
|
||||
@@ -101,7 +101,7 @@ export class AliossAccess extends BaseAccess {
|
||||
|
||||
async getClient(access: AliyunAccess) {
|
||||
// @ts-ignore
|
||||
const OSS = await import("ali-oss");
|
||||
const OSS = await access.importRuntime("ali-oss");
|
||||
return new OSS.default({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
@@ -45,7 +45,7 @@ export class AliyunAccess extends BaseAccess {
|
||||
}
|
||||
|
||||
async getStsClient() {
|
||||
const StsClient = await import("@alicloud/sts-sdk");
|
||||
const StsClient = await this.importRuntime("@alicloud/sts-sdk");
|
||||
|
||||
// 配置凭证
|
||||
const sts = new StsClient.default({
|
||||
|
||||
@@ -30,7 +30,7 @@ export class AliyunClientV2 {
|
||||
if (this.client) {
|
||||
return this.client;
|
||||
}
|
||||
const $OpenApi = await import("@alicloud/openapi-client");
|
||||
const $OpenApi = await this.access.importRuntime("@alicloud/openapi-client");
|
||||
// const Credential = await import("@alicloud/credentials");
|
||||
// //@ts-ignore
|
||||
// const credential = new Credential.default.default({
|
||||
@@ -52,9 +52,9 @@ export class AliyunClientV2 {
|
||||
async doRequest(req: AliyunClientV2Req) {
|
||||
const client = await this.getClient();
|
||||
|
||||
const $OpenApi = await import("@alicloud/openapi-client");
|
||||
const $Util = await import("@alicloud/tea-util");
|
||||
const OpenApiUtil = await import("@alicloud/openapi-util");
|
||||
const $OpenApi = await this.access.importRuntime("@alicloud/openapi-client");
|
||||
const $Util = await this.access.importRuntime("@alicloud/tea-util");
|
||||
const OpenApiUtil = await this.access.importRuntime("@alicloud/openapi-util");
|
||||
const params = new $OpenApi.Params({
|
||||
// 接口名称
|
||||
action: req.action,
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { getGlobalAgents, ILogger } from "@certd/basic";
|
||||
import { ImportRuntime } from "@certd/pipeline";
|
||||
|
||||
export class AliyunClient {
|
||||
client: any;
|
||||
logger: ILogger;
|
||||
agent: any;
|
||||
useROAClient: boolean;
|
||||
importRuntime: ImportRuntime;
|
||||
|
||||
constructor(opts: { logger: ILogger; useROAClient?: boolean }) {
|
||||
constructor(opts: { logger: ILogger; useROAClient?: boolean; importRuntime?: ImportRuntime }) {
|
||||
this.logger = opts.logger;
|
||||
this.useROAClient = opts.useROAClient || false;
|
||||
this.importRuntime = opts.importRuntime || (async (specifier: string) => await import(specifier));
|
||||
const agents = getGlobalAgents();
|
||||
this.agent = agents.httpsAgent;
|
||||
}
|
||||
@@ -17,13 +20,12 @@ export class AliyunClient {
|
||||
if (this.useROAClient) {
|
||||
return await this.getROAClient();
|
||||
}
|
||||
const Core = await import("@alicloud/pop-core");
|
||||
const Core = await this.importRuntime("@alicloud/pop-core");
|
||||
return Core.default;
|
||||
}
|
||||
|
||||
async getROAClient() {
|
||||
const Core = await import("@alicloud/pop-core");
|
||||
console.log("aliyun sdk", Core);
|
||||
const Core = await this.importRuntime("@alicloud/pop-core");
|
||||
// @ts-ignore
|
||||
return Core.ROAClient;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export class AliossClient {
|
||||
return;
|
||||
}
|
||||
// @ts-ignore
|
||||
const OSS = await import("ali-oss");
|
||||
const OSS = await this.access.importRuntime("ali-oss");
|
||||
const ossClient = new OSS.default({
|
||||
accessKeyId: this.access.accessKeyId,
|
||||
accessKeySecret: this.access.accessKeySecret,
|
||||
|
||||
@@ -55,7 +55,7 @@ export class AliyunSslClient {
|
||||
|
||||
async getClient() {
|
||||
const access = this.opts.access;
|
||||
const client = new AliyunClient({ logger: this.opts.logger });
|
||||
const client = new AliyunClient({ logger: this.opts.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
|
||||
let endpoint = this.opts.endpoint || "cas.aliyuncs.com";
|
||||
if (this.opts.endpoint == null && this.opts.region) {
|
||||
|
||||
@@ -16,7 +16,7 @@ export default class S3OssClientImpl extends BaseOssClient<S3Access> {
|
||||
async init() {
|
||||
// import { S3Client } from "@aws-sdk/client-s3";
|
||||
//@ts-ignore
|
||||
const { S3Client } = await import("@aws-sdk/client-s3");
|
||||
const { S3Client } = await this.access.importRuntime("@aws-sdk/client-s3");
|
||||
this.client = new S3Client({
|
||||
forcePathStyle: true,
|
||||
//@ts-ignore
|
||||
@@ -32,7 +32,7 @@ export default class S3OssClientImpl extends BaseOssClient<S3Access> {
|
||||
|
||||
async download(filePath: string, savePath: string): Promise<void> {
|
||||
// @ts-ignore
|
||||
const { GetObjectCommand } = await import("@aws-sdk/client-s3");
|
||||
const { GetObjectCommand } = await this.access.importRuntime("@aws-sdk/client-s3");
|
||||
const key = path.join(this.rootDir, filePath);
|
||||
const params = {
|
||||
Bucket: this.access.bucket, // The name of the bucket. For example, 'sample_bucket_101'.
|
||||
@@ -47,7 +47,7 @@ export default class S3OssClientImpl extends BaseOssClient<S3Access> {
|
||||
|
||||
async listDir(dir: string): Promise<OssFileItem[]> {
|
||||
// @ts-ignore
|
||||
const { ListObjectsCommand } = await import("@aws-sdk/client-s3");
|
||||
const { ListObjectsCommand } = await this.access.importRuntime("@aws-sdk/client-s3");
|
||||
const dirKey = this.join(this.rootDir, dir);
|
||||
const params = {
|
||||
Bucket: this.access.bucket, // The name of the bucket. For example, 'sample_bucket_101'.
|
||||
@@ -67,7 +67,7 @@ export default class S3OssClientImpl extends BaseOssClient<S3Access> {
|
||||
}
|
||||
async upload(filePath: string, fileContent: Buffer | string) {
|
||||
// @ts-ignore
|
||||
const { PutObjectCommand } = await import("@aws-sdk/client-s3");
|
||||
const { PutObjectCommand } = await this.access.importRuntime("@aws-sdk/client-s3");
|
||||
const key = path.join(this.rootDir, filePath);
|
||||
this.logger.info(`开始上传文件: ${key}`);
|
||||
const params = {
|
||||
@@ -88,7 +88,7 @@ export default class S3OssClientImpl extends BaseOssClient<S3Access> {
|
||||
}
|
||||
const key = filePath;
|
||||
// @ts-ignore
|
||||
const { DeleteObjectCommand } = await import("@aws-sdk/client-s3");
|
||||
const { DeleteObjectCommand } = await this.access.importRuntime("@aws-sdk/client-s3");
|
||||
await this.client.send(
|
||||
new DeleteObjectCommand({
|
||||
Bucket: this.access.bucket,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { TencentAccess } from "../access.js";
|
||||
import { ILogger, safePromise } from "@certd/basic";
|
||||
import { ImportRuntime } from "@certd/pipeline";
|
||||
import fs from "fs";
|
||||
|
||||
export class TencentCosClient {
|
||||
@@ -7,16 +8,18 @@ export class TencentCosClient {
|
||||
logger: ILogger;
|
||||
region: string;
|
||||
bucket: string;
|
||||
importRuntime: ImportRuntime;
|
||||
|
||||
constructor(opts: { access: TencentAccess; logger: ILogger; region: string; bucket: string }) {
|
||||
constructor(opts: { access: TencentAccess; logger: ILogger; region: string; bucket: string; importRuntime?: ImportRuntime }) {
|
||||
this.access = opts.access;
|
||||
this.logger = opts.logger;
|
||||
this.bucket = opts.bucket;
|
||||
this.region = opts.region;
|
||||
this.importRuntime = opts.importRuntime || (async (specifier: string) => await import(specifier));
|
||||
}
|
||||
|
||||
async getCosClient() {
|
||||
const sdk = await import("cos-nodejs-sdk-v5");
|
||||
const sdk = await this.importRuntime("cos-nodejs-sdk-v5");
|
||||
const clientConfig = {
|
||||
SecretId: this.access.secretId,
|
||||
SecretKey: this.access.secretKey,
|
||||
|
||||
Reference in New Issue
Block a user