@cloudbase/manager-node 4.6.6-beta.0 → 4.6.7-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/context.js +6 -1
- package/lib/env/index.js +3 -2
- package/lib/index.js +6 -2
- package/lib/storage/index.js +3 -2
- package/lib/utils/cloud-api-request.js +2 -1
- package/package.json +1 -1
- package/types/context.d.ts +4 -1
- package/types/index.d.ts +2 -0
package/lib/context.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CloudBaseContext = void 0;
|
|
4
|
+
const constant_1 = require("./constant");
|
|
4
5
|
class CloudBaseContext {
|
|
5
|
-
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
|
|
6
|
+
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined }) {
|
|
6
7
|
this.secretId = secretId;
|
|
7
8
|
this.secretKey = secretKey;
|
|
8
9
|
this.token = token;
|
|
9
10
|
this.proxy = proxy;
|
|
10
11
|
this.region = region;
|
|
11
12
|
this.envType = envType;
|
|
13
|
+
this.useInternalEndpoint = useInternalEndpoint;
|
|
14
|
+
}
|
|
15
|
+
isInternalEndpoint() {
|
|
16
|
+
return this.useInternalEndpoint !== undefined ? this.useInternalEndpoint : constant_1.USE_INTERNAL_ENDPOINT;
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
exports.CloudBaseContext = CloudBaseContext;
|
package/lib/env/index.js
CHANGED
|
@@ -280,19 +280,20 @@ class EnvService {
|
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
282
|
getCos() {
|
|
283
|
+
const internalEndpoint = this.environment.cloudBaseContext.isInternalEndpoint();
|
|
283
284
|
const { secretId, secretKey, token } = this.environment.getAuthConfig();
|
|
284
285
|
const cosConfig = {
|
|
285
286
|
SecretId: secretId,
|
|
286
287
|
SecretKey: secretKey,
|
|
287
288
|
SecurityToken: token,
|
|
288
|
-
Domain:
|
|
289
|
+
Domain: internalEndpoint ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
289
290
|
};
|
|
290
291
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
291
292
|
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
292
293
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
293
294
|
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
294
295
|
}
|
|
295
|
-
if (
|
|
296
|
+
if (internalEndpoint) {
|
|
296
297
|
cosConfig.Protocol = 'http:';
|
|
297
298
|
}
|
|
298
299
|
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
package/lib/index.js
CHANGED
|
@@ -18,7 +18,7 @@ class CloudBase {
|
|
|
18
18
|
}
|
|
19
19
|
constructor(config = {}) {
|
|
20
20
|
this.cloudBaseConfig = {};
|
|
21
|
-
let { secretId, secretKey, token, envId, proxy, region, envType } = config;
|
|
21
|
+
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint } = config;
|
|
22
22
|
// config 中传入的 secretId secretkey 必须同时存在
|
|
23
23
|
if ((secretId && !secretKey) || (!secretId && secretKey)) {
|
|
24
24
|
throw new Error('secretId and secretKey must be a pair');
|
|
@@ -30,7 +30,8 @@ class CloudBase {
|
|
|
30
30
|
envId,
|
|
31
31
|
envType,
|
|
32
32
|
proxy,
|
|
33
|
-
region
|
|
33
|
+
region,
|
|
34
|
+
useInternalEndpoint
|
|
34
35
|
};
|
|
35
36
|
// 初始化 context
|
|
36
37
|
this.context = new context_1.CloudBaseContext(this.cloudBaseConfig);
|
|
@@ -85,5 +86,8 @@ class CloudBase {
|
|
|
85
86
|
getManagerConfig() {
|
|
86
87
|
return this.cloudBaseConfig;
|
|
87
88
|
}
|
|
89
|
+
get isInternalEndpoint() {
|
|
90
|
+
return this.context.isInternalEndpoint();
|
|
91
|
+
}
|
|
88
92
|
}
|
|
89
93
|
module.exports = CloudBase;
|
package/lib/storage/index.js
CHANGED
|
@@ -838,6 +838,7 @@ class StorageService {
|
|
|
838
838
|
* 获取 COS 配置
|
|
839
839
|
*/
|
|
840
840
|
getCos(parallel = 20) {
|
|
841
|
+
const internalEndpoint = this.environment.cloudBaseContext.isInternalEndpoint();
|
|
841
842
|
const { secretId, secretKey, token, proxy } = this.environment.getAuthConfig();
|
|
842
843
|
const cosProxy = process.env.TCB_COS_PROXY;
|
|
843
844
|
const cosConfig = {
|
|
@@ -846,14 +847,14 @@ class StorageService {
|
|
|
846
847
|
SecretKey: secretKey,
|
|
847
848
|
Proxy: cosProxy || proxy,
|
|
848
849
|
SecurityToken: token,
|
|
849
|
-
Domain:
|
|
850
|
+
Domain: internalEndpoint ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
850
851
|
};
|
|
851
852
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
852
853
|
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
853
854
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
854
855
|
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
855
856
|
}
|
|
856
|
-
if (
|
|
857
|
+
if (internalEndpoint) {
|
|
857
858
|
cosConfig.Protocol = 'http:';
|
|
858
859
|
}
|
|
859
860
|
// COSSDK 默认开启 KeepAlive,这里提供关闭的方式
|
|
@@ -61,6 +61,7 @@ class CloudService {
|
|
|
61
61
|
this.cloudBaseContext = context;
|
|
62
62
|
}
|
|
63
63
|
get baseUrl() {
|
|
64
|
+
const internalEndpoint = this.cloudBaseContext.isInternalEndpoint();
|
|
64
65
|
const tcb = process.env.TCB_BASE_URL || 'https://tcb.tencentcloudapi.com';
|
|
65
66
|
const urlMap = {
|
|
66
67
|
tcb,
|
|
@@ -74,7 +75,7 @@ class CloudService {
|
|
|
74
75
|
const intranetUrlMap = Object.keys(urlMap).map((service) => ({
|
|
75
76
|
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
76
77
|
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
77
|
-
if (
|
|
78
|
+
if (internalEndpoint) {
|
|
78
79
|
return intranetUrlMap[this.service];
|
|
79
80
|
}
|
|
80
81
|
if (urlMap[this.service]) {
|
package/package.json
CHANGED
package/types/context.d.ts
CHANGED
|
@@ -6,12 +6,15 @@ export declare class CloudBaseContext {
|
|
|
6
6
|
readonly envId: string;
|
|
7
7
|
readonly region: string;
|
|
8
8
|
readonly envType: string;
|
|
9
|
-
|
|
9
|
+
readonly useInternalEndpoint?: boolean;
|
|
10
|
+
constructor({ secretId, secretKey, token, proxy, region, envType, useInternalEndpoint }: {
|
|
10
11
|
secretId?: string;
|
|
11
12
|
secretKey?: string;
|
|
12
13
|
token?: string;
|
|
13
14
|
proxy?: string;
|
|
14
15
|
region?: string;
|
|
15
16
|
envType?: string;
|
|
17
|
+
useInternalEndpoint?: any;
|
|
16
18
|
});
|
|
19
|
+
isInternalEndpoint(): boolean;
|
|
17
20
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ interface CloudBaseConfig {
|
|
|
20
20
|
proxy?: string;
|
|
21
21
|
region?: string;
|
|
22
22
|
envType?: string;
|
|
23
|
+
useInternalEndpoint?: boolean;
|
|
23
24
|
}
|
|
24
25
|
declare class CloudBase {
|
|
25
26
|
private static cloudBase;
|
|
@@ -52,5 +53,6 @@ declare class CloudBase {
|
|
|
52
53
|
get user(): UserService;
|
|
53
54
|
getEnvironmentManager(): EnvironmentManager;
|
|
54
55
|
getManagerConfig(): CloudBaseConfig;
|
|
56
|
+
get isInternalEndpoint(): Boolean;
|
|
55
57
|
}
|
|
56
58
|
export = CloudBase;
|