tencentcloud-sdk-nodejs 4.1.120 → 4.1.121
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/es/common/credential.js +209 -0
- package/es/common/index.js +1 -0
- package/es/common/sdk_version.js +1 -1
- package/es/services/ccc/v20200210/ccc_client.js +5 -2
- package/es/services/iotexplorer/v20190423/iotexplorer_client.js +5 -2
- package/package.json +3 -1
- package/tencentcloud/common/credential.d.ts +101 -0
- package/tencentcloud/common/credential.js +267 -0
- package/tencentcloud/common/cvm_role_credential.d.ts +2 -7
- package/tencentcloud/common/index.d.ts +1 -0
- package/tencentcloud/common/index.js +1 -0
- package/tencentcloud/common/interface.d.ts +7 -0
- package/tencentcloud/common/sdk_version.d.ts +1 -1
- package/tencentcloud/common/sdk_version.js +1 -1
- package/tencentcloud/services/billing/v20180709/billing_models.d.ts +1 -1
- package/tencentcloud/services/ccc/v20200210/ccc_client.d.ts +7 -3
- package/tencentcloud/services/ccc/v20200210/ccc_client.js +9 -3
- package/tencentcloud/services/ccc/v20200210/ccc_models.d.ts +49 -0
- package/tencentcloud/services/cfw/v20190904/cfw_models.d.ts +45 -1
- package/tencentcloud/services/ckafka/v20190819/ckafka_models.d.ts +17 -0
- package/tencentcloud/services/ctem/v20231128/ctem_models.d.ts +116 -0
- package/tencentcloud/services/emr/v20190103/emr_models.d.ts +14 -0
- package/tencentcloud/services/ess/v20201111/ess_client.d.ts +3 -3
- package/tencentcloud/services/ess/v20201111/ess_client.js +3 -3
- package/tencentcloud/services/ess/v20201111/ess_models.d.ts +4 -4
- package/tencentcloud/services/essbasic/v20210526/essbasic_models.d.ts +1 -1
- package/tencentcloud/services/iai/v20180301/iai_client.d.ts +0 -1
- package/tencentcloud/services/iai/v20180301/iai_client.js +0 -1
- package/tencentcloud/services/iai/v20180301/iai_models.d.ts +9 -10
- package/tencentcloud/services/iotexplorer/v20190423/iotexplorer_client.d.ts +7 -3
- package/tencentcloud/services/iotexplorer/v20190423/iotexplorer_client.js +9 -3
- package/tencentcloud/services/iotexplorer/v20190423/iotexplorer_models.d.ts +35 -0
- package/tencentcloud/services/lighthouse/v20200324/lighthouse_models.d.ts +75 -6
- package/tencentcloud/services/lkeap/v20240522/lkeap_client.d.ts +5 -2
- package/tencentcloud/services/lkeap/v20240522/lkeap_client.js +5 -2
- package/tencentcloud/services/organization/v20210331/organization_models.d.ts +3 -3
- package/tencentcloud/services/redis/v20180412/redis_client.d.ts +2 -2
- package/tencentcloud/services/redis/v20180412/redis_client.js +2 -2
- package/tencentcloud/services/redis/v20180412/redis_models.d.ts +6 -6
@@ -0,0 +1,209 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
import { homedir } from "os";
|
4
|
+
import { parse } from 'ini';
|
5
|
+
import { CommonClient } from "./common_client";
|
6
|
+
import CvmRoleCredential from "./cvm_role_credential";
|
7
|
+
const EXPIRE_BUFFER = 30 * 1000;
|
8
|
+
export class BasicCredential {
|
9
|
+
constructor(secretId, secretKey, token) {
|
10
|
+
this.secretId = secretId;
|
11
|
+
this.secretKey = secretKey;
|
12
|
+
this.token = token;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
export class EnvironmentVariableCredential {
|
16
|
+
async getCredential() {
|
17
|
+
const secretId = process.env.TENCENTCLOUD_SECRET_ID;
|
18
|
+
const secretKey = process.env.TENCENTCLOUD_SECRET_KEY;
|
19
|
+
const token = process.env.TENCENTCLOUD_SESSION_TOKEN;
|
20
|
+
return new BasicCredential(secretId, secretKey, token);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
export class ProfileCredential {
|
24
|
+
async getCredential() {
|
25
|
+
let filePath = '';
|
26
|
+
const userHome = homedir();
|
27
|
+
const userCredentialsPath = path.join(userHome, ".tencentcloud", "credentials");
|
28
|
+
if (fs.existsSync(userCredentialsPath)) {
|
29
|
+
filePath = userCredentialsPath;
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
filePath = '/etc/tencentcloud/credentials';
|
33
|
+
}
|
34
|
+
if (filePath) {
|
35
|
+
try {
|
36
|
+
const content = fs.readFileSync(filePath, "utf8");
|
37
|
+
const { default: { secret_id, secret_key, token } } = parse(content);
|
38
|
+
if (secret_id && secret_key) {
|
39
|
+
return new BasicCredential(secret_id, secret_key, token);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
catch (error) {
|
43
|
+
}
|
44
|
+
}
|
45
|
+
return new BasicCredential('', '');
|
46
|
+
}
|
47
|
+
}
|
48
|
+
export class STSCredential {
|
49
|
+
constructor(clientConfig, assumeRoleParams) {
|
50
|
+
this.clientConfig = clientConfig;
|
51
|
+
this.assumeRoleParams = assumeRoleParams;
|
52
|
+
this.endpoint = 'sts.tencentcloudapi.com';
|
53
|
+
this.version = '2018-08-13';
|
54
|
+
this.action = 'AssumeRole';
|
55
|
+
this.region = 'ap-guangzhou';
|
56
|
+
}
|
57
|
+
async getCredentialWithStsAssumeRole() {
|
58
|
+
const { endpoint, version, action, region, clientConfig, assumeRoleParams } = this;
|
59
|
+
try {
|
60
|
+
const client = new CommonClient(endpoint, version, {
|
61
|
+
region,
|
62
|
+
...clientConfig
|
63
|
+
});
|
64
|
+
const result = await client.request(action, assumeRoleParams);
|
65
|
+
return {
|
66
|
+
TmpSecretId: result.Credentials.TmpSecretId,
|
67
|
+
TmpSecretKey: result.Credentials.TmpSecretKey,
|
68
|
+
Token: result.Credentials.Token,
|
69
|
+
ExpiredTime: result.ExpiredTime,
|
70
|
+
Expiration: result.Expiration,
|
71
|
+
};
|
72
|
+
}
|
73
|
+
catch (error) {
|
74
|
+
throw new Error(`Get STS AssumeRole failed: ${error.message}`);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
async getCredential() {
|
78
|
+
if (!this.credentialTask) {
|
79
|
+
this.credentialTask = this.getCredentialWithStsAssumeRole();
|
80
|
+
}
|
81
|
+
const credential = await this.credentialTask;
|
82
|
+
if (credential.ExpiredTime * 1000 - EXPIRE_BUFFER <= Date.now()) {
|
83
|
+
this.credentialTask = null;
|
84
|
+
return this.getCredential();
|
85
|
+
}
|
86
|
+
return {
|
87
|
+
secretId: credential.TmpSecretId,
|
88
|
+
secretKey: credential.TmpSecretKey,
|
89
|
+
token: credential.Token,
|
90
|
+
};
|
91
|
+
}
|
92
|
+
}
|
93
|
+
export { default as CvmRoleCredential } from "./cvm_role_credential";
|
94
|
+
export class OIDCRoleArnCredential {
|
95
|
+
constructor(clientConfig, assumeRoleWithWebIdentityParams) {
|
96
|
+
this.endpoint = 'sts.tencentcloudapi.com';
|
97
|
+
this.version = '2018-08-13';
|
98
|
+
this.action = 'AssumeRoleWithWebIdentity';
|
99
|
+
this.defaultSessionName = 'tencentcloud-node-sdk-';
|
100
|
+
this.isTke = false;
|
101
|
+
this.expirationReservationTime = 600;
|
102
|
+
if (clientConfig && assumeRoleWithWebIdentityParams) {
|
103
|
+
this.clientConfig = clientConfig;
|
104
|
+
this.assumeRoleWithWebIdentityParams = assumeRoleWithWebIdentityParams;
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
this.isTke = true;
|
108
|
+
this.clientConfig = {
|
109
|
+
credential: new BasicCredential('', ''),
|
110
|
+
...clientConfig,
|
111
|
+
};
|
112
|
+
}
|
113
|
+
}
|
114
|
+
initFromTke() {
|
115
|
+
const region = process.env.TKE_REGION;
|
116
|
+
if (!region) {
|
117
|
+
throw new Error('env TKE_REGION not exist');
|
118
|
+
}
|
119
|
+
const providerId = process.env.TKE_PROVIDER_ID;
|
120
|
+
if (!providerId) {
|
121
|
+
throw new Error('env TKE_PROVIDER_ID not exist');
|
122
|
+
}
|
123
|
+
const tokenFile = process.env.TKE_WEB_IDENTITY_TOKEN_FILE;
|
124
|
+
if (!tokenFile) {
|
125
|
+
throw new Error('env TKE_WEB_IDENTITY_TOKEN_FILE not exist');
|
126
|
+
}
|
127
|
+
let wbIdentityToken;
|
128
|
+
try {
|
129
|
+
wbIdentityToken = fs.readFileSync(tokenFile).toString();
|
130
|
+
}
|
131
|
+
catch (error) {
|
132
|
+
throw new Error(`failed to read token file: ${error.message}`);
|
133
|
+
}
|
134
|
+
const roleArn = process.env.TKE_ROLE_ARN;
|
135
|
+
if (!roleArn) {
|
136
|
+
throw new Error('env TKE_ROLE_ARN not exist');
|
137
|
+
}
|
138
|
+
this.clientConfig.region = region;
|
139
|
+
this.assumeRoleWithWebIdentityParams = {
|
140
|
+
RoleArn: roleArn,
|
141
|
+
RoleSessionName: `${this.defaultSessionName}${Date.now() * 1000}`,
|
142
|
+
WebIdentityToken: wbIdentityToken,
|
143
|
+
ProviderId: providerId,
|
144
|
+
};
|
145
|
+
}
|
146
|
+
async getCredentialWithStsAssumeRoleWithWebIdentity() {
|
147
|
+
try {
|
148
|
+
if (this.isTke) {
|
149
|
+
this.initFromTke();
|
150
|
+
}
|
151
|
+
const { endpoint, version, action, region, clientConfig, assumeRoleWithWebIdentityParams } = this;
|
152
|
+
const client = new CommonClient(endpoint, version, {
|
153
|
+
region: region,
|
154
|
+
...clientConfig,
|
155
|
+
});
|
156
|
+
const result = await client.request(action, assumeRoleWithWebIdentityParams);
|
157
|
+
return {
|
158
|
+
TmpSecretId: result.Credentials.TmpSecretId,
|
159
|
+
TmpSecretKey: result.Credentials.TmpSecretKey,
|
160
|
+
Token: result.Credentials.Token,
|
161
|
+
ExpiredTime: result.ExpiredTime,
|
162
|
+
Expiration: result.Expiration,
|
163
|
+
};
|
164
|
+
}
|
165
|
+
catch (error) {
|
166
|
+
throw new Error(`Get STS AssumeRoleWithWebIdentity failed: ${error.message}`);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
async getCredential() {
|
170
|
+
if (!this.credentialTask) {
|
171
|
+
this.credentialTask = this.getCredentialWithStsAssumeRoleWithWebIdentity();
|
172
|
+
}
|
173
|
+
const credential = await this.credentialTask;
|
174
|
+
if (credential.ExpiredTime * 1000 - this.expirationReservationTime <= Date.now()) {
|
175
|
+
this.credentialTask = null;
|
176
|
+
return this.getCredential();
|
177
|
+
}
|
178
|
+
return {
|
179
|
+
secretId: credential.TmpSecretId,
|
180
|
+
secretKey: credential.TmpSecretKey,
|
181
|
+
token: credential.Token,
|
182
|
+
};
|
183
|
+
}
|
184
|
+
}
|
185
|
+
export class DefaultCredentialProvider {
|
186
|
+
constructor() {
|
187
|
+
this.providers = [
|
188
|
+
new EnvironmentVariableCredential(),
|
189
|
+
new ProfileCredential(),
|
190
|
+
new CvmRoleCredential(),
|
191
|
+
new OIDCRoleArnCredential()
|
192
|
+
];
|
193
|
+
}
|
194
|
+
async getCredential() {
|
195
|
+
for (const provider of this.providers) {
|
196
|
+
try {
|
197
|
+
const credential = await provider.getCredential();
|
198
|
+
if (credential.secretId && credential.secretKey) {
|
199
|
+
return credential;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
catch (error) {
|
203
|
+
console.error(error);
|
204
|
+
continue;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
return new BasicCredential('', '');
|
208
|
+
}
|
209
|
+
}
|
package/es/common/index.js
CHANGED
package/es/common/sdk_version.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const sdkVersion = "4.1.
|
1
|
+
export const sdkVersion = "4.1.121";
|
@@ -9,8 +9,8 @@ export class Client extends AbstractClient {
|
|
9
9
|
async ModifyCompanyApply(req, cb) {
|
10
10
|
return this.request("ModifyCompanyApply", req, cb);
|
11
11
|
}
|
12
|
-
async
|
13
|
-
return this.request("
|
12
|
+
async DescribeAIAnalysisResult(req, cb) {
|
13
|
+
return this.request("DescribeAIAnalysisResult", req, cb);
|
14
14
|
}
|
15
15
|
async DescribeExtensions(req, cb) {
|
16
16
|
return this.request("DescribeExtensions", req, cb);
|
@@ -84,6 +84,9 @@ export class Client extends AbstractClient {
|
|
84
84
|
async UploadIvrAudio(req, cb) {
|
85
85
|
return this.request("UploadIvrAudio", req, cb);
|
86
86
|
}
|
87
|
+
async ModifyStaff(req, cb) {
|
88
|
+
return this.request("ModifyStaff", req, cb);
|
89
|
+
}
|
87
90
|
async DescribeExtension(req, cb) {
|
88
91
|
return this.request("DescribeExtension", req, cb);
|
89
92
|
}
|
@@ -336,8 +336,8 @@ export class Client extends AbstractClient {
|
|
336
336
|
async BindProducts(req, cb) {
|
337
337
|
return this.request("BindProducts", req, cb);
|
338
338
|
}
|
339
|
-
async
|
340
|
-
return this.request("
|
339
|
+
async DescribeSubscribedTopicPolicy(req, cb) {
|
340
|
+
return this.request("DescribeSubscribedTopicPolicy", req, cb);
|
341
341
|
}
|
342
342
|
async SearchPositionSpace(req, cb) {
|
343
343
|
return this.request("SearchPositionSpace", req, cb);
|
@@ -372,6 +372,9 @@ export class Client extends AbstractClient {
|
|
372
372
|
async DescribeDeviceFirmwares(req, cb) {
|
373
373
|
return this.request("DescribeDeviceFirmwares", req, cb);
|
374
374
|
}
|
375
|
+
async RemoveUserByRoomIdFromTRTC(req, cb) {
|
376
|
+
return this.request("RemoveUserByRoomIdFromTRTC", req, cb);
|
377
|
+
}
|
375
378
|
async BindDevices(req, cb) {
|
376
379
|
return this.request("BindDevices", req, cb);
|
377
380
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "tencentcloud-sdk-nodejs",
|
3
|
-
"version": "4.1.
|
3
|
+
"version": "4.1.121",
|
4
4
|
"description": "腾讯云 API NODEJS SDK",
|
5
5
|
"main": "./tencentcloud/index.js",
|
6
6
|
"module": "./es/index.js",
|
@@ -36,6 +36,7 @@
|
|
36
36
|
"form-data": "^3.0.4",
|
37
37
|
"get-stream": "^6.0.0",
|
38
38
|
"https-proxy-agent": "^5.0.0",
|
39
|
+
"ini": "^5.0.0",
|
39
40
|
"is-stream": "^2.0.0",
|
40
41
|
"json-bigint": "^1.0.0",
|
41
42
|
"node-fetch": "^2.2.0",
|
@@ -51,6 +52,7 @@
|
|
51
52
|
"url": "https://github.com/tencentcloud/tencentcloud-sdk-nodejs"
|
52
53
|
},
|
53
54
|
"devDependencies": {
|
55
|
+
"@types/ini": "^4.1.1",
|
54
56
|
"@types/json-bigint": "^1.0.1",
|
55
57
|
"@types/node": "^18.0.0",
|
56
58
|
"@types/node-fetch": "^2.5.7",
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import { ClientConfig, Credential, CredentialResult, DynamicCredential } from "./interface";
|
2
|
+
/**
|
3
|
+
* Basic credential with secret id and secret key
|
4
|
+
*/
|
5
|
+
export declare class BasicCredential implements Credential {
|
6
|
+
readonly secretId: string;
|
7
|
+
readonly secretKey: string;
|
8
|
+
readonly token?: string;
|
9
|
+
constructor(secretId: string, secretKey: string, token?: string);
|
10
|
+
}
|
11
|
+
/**
|
12
|
+
* Environment variable credential
|
13
|
+
* Get credential from environment variables:
|
14
|
+
* - TENCENTCLOUD_SECRET_ID
|
15
|
+
* - TENCENTCLOUD_SECRET_KEY
|
16
|
+
* - TENCENTCLOUD_SESSION_TOKEN (optional)
|
17
|
+
*/
|
18
|
+
export declare class EnvironmentVariableCredential implements DynamicCredential {
|
19
|
+
getCredential(): Promise<Credential>;
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Profile credential
|
23
|
+
* Get credential from profile file ~/.tencentcloud/credentials or /etc/tencentcloud/credentials
|
24
|
+
* example credentials file:
|
25
|
+
* [default]
|
26
|
+
* secret_id = your-secret-id
|
27
|
+
* secret_key = your-secret-key
|
28
|
+
*/
|
29
|
+
export declare class ProfileCredential implements DynamicCredential {
|
30
|
+
getCredential(): Promise<Credential>;
|
31
|
+
}
|
32
|
+
interface AssumeRoleParams {
|
33
|
+
RoleArn: string;
|
34
|
+
RoleSessionName: string;
|
35
|
+
[key: string]: any;
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* Tencent Cloud Credential via STS service
|
39
|
+
* @see {@link https://cloud.tencent.com/document/api/1312/48197} for more information.
|
40
|
+
*/
|
41
|
+
export declare class STSCredential implements DynamicCredential {
|
42
|
+
private clientConfig;
|
43
|
+
private assumeRoleParams;
|
44
|
+
private endpoint;
|
45
|
+
private version;
|
46
|
+
private action;
|
47
|
+
private region;
|
48
|
+
credentialTask: Promise<CredentialResult> | null;
|
49
|
+
/**
|
50
|
+
* Constructs a new STSCredential instance
|
51
|
+
*
|
52
|
+
* @param {ClientConfig} clientConfig Request client Configuration object
|
53
|
+
* @param {AssumeRoleParams} assumeRoleParams Request parameters of the AssumeRole interface
|
54
|
+
* @see {@link https://cloud.tencent.com/document/api/1312/48197} for more AssumeRoleParams information.
|
55
|
+
*/
|
56
|
+
constructor(clientConfig: ClientConfig, assumeRoleParams: AssumeRoleParams);
|
57
|
+
protected getCredentialWithStsAssumeRole(): Promise<CredentialResult>;
|
58
|
+
getCredential(): Promise<Credential>;
|
59
|
+
}
|
60
|
+
/**
|
61
|
+
* CVM Role credential using existing implementation
|
62
|
+
* Re-export the existing CvmRoleCredential for consistency
|
63
|
+
*/
|
64
|
+
export { default as CvmRoleCredential } from "./cvm_role_credential";
|
65
|
+
/**
|
66
|
+
* TencentCloud OIDC Credential
|
67
|
+
* OIDC is an authentication protocol built on OAuth 2.0. Tencent Cloud CAM supports OIDC role-based SSO.
|
68
|
+
* @see {@link https://cloud.tencent.com/document/product/598/96013} for more information.
|
69
|
+
*/
|
70
|
+
export declare class OIDCRoleArnCredential implements DynamicCredential {
|
71
|
+
private endpoint;
|
72
|
+
private version;
|
73
|
+
private action;
|
74
|
+
private clientConfig;
|
75
|
+
private assumeRoleWithWebIdentityParams;
|
76
|
+
private defaultSessionName;
|
77
|
+
private isTke;
|
78
|
+
protected region: string;
|
79
|
+
protected expirationReservationTime: number;
|
80
|
+
protected credentialTask: Promise<CredentialResult> | null;
|
81
|
+
/**
|
82
|
+
* Constructs a new OIDCRoleArnCredential instance
|
83
|
+
*
|
84
|
+
* @param {ClientConfig} [clientConfig] Optional request client Configuration object
|
85
|
+
* @param {AssumeRoleParams} [assumeRoleParams] Optional request parameters of the AssumeRole interface
|
86
|
+
* @see {@link https://cloud.tencent.com/document/api/1312/48197} for more AssumeRoleWithWebIdentity information.
|
87
|
+
*/
|
88
|
+
constructor();
|
89
|
+
constructor(clientConfig: ClientConfig, assumeRoleWithWebIdentityParams: AssumeRoleParams);
|
90
|
+
private initFromTke;
|
91
|
+
protected getCredentialWithStsAssumeRoleWithWebIdentity(): Promise<CredentialResult>;
|
92
|
+
getCredential(): Promise<Credential>;
|
93
|
+
}
|
94
|
+
/**
|
95
|
+
* Tencent Cloud DefaultCredentialProvider
|
96
|
+
*/
|
97
|
+
export declare class DefaultCredentialProvider implements DynamicCredential {
|
98
|
+
private readonly providers;
|
99
|
+
constructor();
|
100
|
+
getCredential(): Promise<Credential>;
|
101
|
+
}
|
@@ -0,0 +1,267 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.DefaultCredentialProvider = exports.OIDCRoleArnCredential = exports.CvmRoleCredential = exports.STSCredential = exports.ProfileCredential = exports.EnvironmentVariableCredential = exports.BasicCredential = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
7
|
+
const os_1 = require("os");
|
8
|
+
const ini_1 = require("ini");
|
9
|
+
const common_client_1 = require("./common_client");
|
10
|
+
const cvm_role_credential_1 = tslib_1.__importDefault(require("./cvm_role_credential"));
|
11
|
+
const EXPIRE_BUFFER = 30 * 1000;
|
12
|
+
/**
|
13
|
+
* Basic credential with secret id and secret key
|
14
|
+
*/
|
15
|
+
class BasicCredential {
|
16
|
+
constructor(secretId, secretKey, token) {
|
17
|
+
this.secretId = secretId;
|
18
|
+
this.secretKey = secretKey;
|
19
|
+
this.token = token;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
exports.BasicCredential = BasicCredential;
|
23
|
+
/**
|
24
|
+
* Environment variable credential
|
25
|
+
* Get credential from environment variables:
|
26
|
+
* - TENCENTCLOUD_SECRET_ID
|
27
|
+
* - TENCENTCLOUD_SECRET_KEY
|
28
|
+
* - TENCENTCLOUD_SESSION_TOKEN (optional)
|
29
|
+
*/
|
30
|
+
class EnvironmentVariableCredential {
|
31
|
+
async getCredential() {
|
32
|
+
const secretId = process.env.TENCENTCLOUD_SECRET_ID;
|
33
|
+
const secretKey = process.env.TENCENTCLOUD_SECRET_KEY;
|
34
|
+
const token = process.env.TENCENTCLOUD_SESSION_TOKEN;
|
35
|
+
return new BasicCredential(secretId, secretKey, token);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
exports.EnvironmentVariableCredential = EnvironmentVariableCredential;
|
39
|
+
/**
|
40
|
+
* Profile credential
|
41
|
+
* Get credential from profile file ~/.tencentcloud/credentials or /etc/tencentcloud/credentials
|
42
|
+
* example credentials file:
|
43
|
+
* [default]
|
44
|
+
* secret_id = your-secret-id
|
45
|
+
* secret_key = your-secret-key
|
46
|
+
*/
|
47
|
+
class ProfileCredential {
|
48
|
+
async getCredential() {
|
49
|
+
let filePath = '';
|
50
|
+
// Try user home directory first
|
51
|
+
const userHome = (0, os_1.homedir)();
|
52
|
+
const userCredentialsPath = path_1.default.join(userHome, ".tencentcloud", "credentials");
|
53
|
+
if (fs_1.default.existsSync(userCredentialsPath)) {
|
54
|
+
filePath = userCredentialsPath;
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
// Try system directory as fallback
|
58
|
+
filePath = '/etc/tencentcloud/credentials';
|
59
|
+
}
|
60
|
+
if (filePath) {
|
61
|
+
try {
|
62
|
+
const content = fs_1.default.readFileSync(filePath, "utf8");
|
63
|
+
const { default: { secret_id, secret_key, token } } = (0, ini_1.parse)(content);
|
64
|
+
if (secret_id && secret_key) {
|
65
|
+
return new BasicCredential(secret_id, secret_key, token);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
catch (error) {
|
69
|
+
// Ignore errors when reading user credentials
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return new BasicCredential('', '');
|
73
|
+
}
|
74
|
+
}
|
75
|
+
exports.ProfileCredential = ProfileCredential;
|
76
|
+
/**
|
77
|
+
* Tencent Cloud Credential via STS service
|
78
|
+
* @see {@link https://cloud.tencent.com/document/api/1312/48197} for more information.
|
79
|
+
*/
|
80
|
+
class STSCredential {
|
81
|
+
/**
|
82
|
+
* Constructs a new STSCredential instance
|
83
|
+
*
|
84
|
+
* @param {ClientConfig} clientConfig Request client Configuration object
|
85
|
+
* @param {AssumeRoleParams} assumeRoleParams Request parameters of the AssumeRole interface
|
86
|
+
* @see {@link https://cloud.tencent.com/document/api/1312/48197} for more AssumeRoleParams information.
|
87
|
+
*/
|
88
|
+
constructor(clientConfig, assumeRoleParams) {
|
89
|
+
this.clientConfig = clientConfig;
|
90
|
+
this.assumeRoleParams = assumeRoleParams;
|
91
|
+
this.endpoint = 'sts.tencentcloudapi.com';
|
92
|
+
this.version = '2018-08-13';
|
93
|
+
this.action = 'AssumeRole';
|
94
|
+
this.region = 'ap-guangzhou';
|
95
|
+
}
|
96
|
+
async getCredentialWithStsAssumeRole() {
|
97
|
+
const { endpoint, version, action, region, clientConfig, assumeRoleParams } = this;
|
98
|
+
try {
|
99
|
+
const client = new common_client_1.CommonClient(endpoint, version, {
|
100
|
+
region,
|
101
|
+
...clientConfig
|
102
|
+
});
|
103
|
+
const result = await client.request(action, assumeRoleParams);
|
104
|
+
return {
|
105
|
+
TmpSecretId: result.Credentials.TmpSecretId,
|
106
|
+
TmpSecretKey: result.Credentials.TmpSecretKey,
|
107
|
+
Token: result.Credentials.Token,
|
108
|
+
ExpiredTime: result.ExpiredTime,
|
109
|
+
Expiration: result.Expiration,
|
110
|
+
};
|
111
|
+
}
|
112
|
+
catch (error) {
|
113
|
+
throw new Error(`Get STS AssumeRole failed: ${error.message}`);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
async getCredential() {
|
117
|
+
if (!this.credentialTask) {
|
118
|
+
this.credentialTask = this.getCredentialWithStsAssumeRole();
|
119
|
+
}
|
120
|
+
const credential = await this.credentialTask;
|
121
|
+
// Check if the credential is expired
|
122
|
+
if (credential.ExpiredTime * 1000 - EXPIRE_BUFFER <= Date.now()) {
|
123
|
+
this.credentialTask = null;
|
124
|
+
return this.getCredential();
|
125
|
+
}
|
126
|
+
return {
|
127
|
+
secretId: credential.TmpSecretId,
|
128
|
+
secretKey: credential.TmpSecretKey,
|
129
|
+
token: credential.Token,
|
130
|
+
};
|
131
|
+
}
|
132
|
+
}
|
133
|
+
exports.STSCredential = STSCredential;
|
134
|
+
/**
|
135
|
+
* CVM Role credential using existing implementation
|
136
|
+
* Re-export the existing CvmRoleCredential for consistency
|
137
|
+
*/
|
138
|
+
var cvm_role_credential_2 = require("./cvm_role_credential");
|
139
|
+
Object.defineProperty(exports, "CvmRoleCredential", { enumerable: true, get: function () { return tslib_1.__importDefault(cvm_role_credential_2).default; } });
|
140
|
+
/**
|
141
|
+
* TencentCloud OIDC Credential
|
142
|
+
* OIDC is an authentication protocol built on OAuth 2.0. Tencent Cloud CAM supports OIDC role-based SSO.
|
143
|
+
* @see {@link https://cloud.tencent.com/document/product/598/96013} for more information.
|
144
|
+
*/
|
145
|
+
class OIDCRoleArnCredential {
|
146
|
+
constructor(clientConfig, assumeRoleWithWebIdentityParams) {
|
147
|
+
this.endpoint = 'sts.tencentcloudapi.com';
|
148
|
+
this.version = '2018-08-13';
|
149
|
+
this.action = 'AssumeRoleWithWebIdentity';
|
150
|
+
this.defaultSessionName = 'tencentcloud-node-sdk-';
|
151
|
+
this.isTke = false;
|
152
|
+
this.expirationReservationTime = 600;
|
153
|
+
if (clientConfig && assumeRoleWithWebIdentityParams) {
|
154
|
+
this.clientConfig = clientConfig;
|
155
|
+
this.assumeRoleWithWebIdentityParams = assumeRoleWithWebIdentityParams;
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
this.isTke = true;
|
159
|
+
this.clientConfig = {
|
160
|
+
credential: new BasicCredential('', ''),
|
161
|
+
...clientConfig,
|
162
|
+
};
|
163
|
+
}
|
164
|
+
}
|
165
|
+
initFromTke() {
|
166
|
+
const region = process.env.TKE_REGION;
|
167
|
+
if (!region) {
|
168
|
+
throw new Error('env TKE_REGION not exist');
|
169
|
+
}
|
170
|
+
const providerId = process.env.TKE_PROVIDER_ID;
|
171
|
+
if (!providerId) {
|
172
|
+
throw new Error('env TKE_PROVIDER_ID not exist');
|
173
|
+
}
|
174
|
+
const tokenFile = process.env.TKE_WEB_IDENTITY_TOKEN_FILE;
|
175
|
+
if (!tokenFile) {
|
176
|
+
throw new Error('env TKE_WEB_IDENTITY_TOKEN_FILE not exist');
|
177
|
+
}
|
178
|
+
let wbIdentityToken;
|
179
|
+
try {
|
180
|
+
wbIdentityToken = fs_1.default.readFileSync(tokenFile).toString();
|
181
|
+
}
|
182
|
+
catch (error) {
|
183
|
+
throw new Error(`failed to read token file: ${error.message}`);
|
184
|
+
}
|
185
|
+
const roleArn = process.env.TKE_ROLE_ARN;
|
186
|
+
if (!roleArn) {
|
187
|
+
throw new Error('env TKE_ROLE_ARN not exist');
|
188
|
+
}
|
189
|
+
this.clientConfig.region = region;
|
190
|
+
this.assumeRoleWithWebIdentityParams = {
|
191
|
+
RoleArn: roleArn,
|
192
|
+
RoleSessionName: `${this.defaultSessionName}${Date.now() * 1000}`,
|
193
|
+
WebIdentityToken: wbIdentityToken,
|
194
|
+
ProviderId: providerId,
|
195
|
+
};
|
196
|
+
}
|
197
|
+
async getCredentialWithStsAssumeRoleWithWebIdentity() {
|
198
|
+
try {
|
199
|
+
if (this.isTke) {
|
200
|
+
this.initFromTke();
|
201
|
+
}
|
202
|
+
const { endpoint, version, action, region, clientConfig, assumeRoleWithWebIdentityParams } = this;
|
203
|
+
const client = new common_client_1.CommonClient(endpoint, version, {
|
204
|
+
region: region,
|
205
|
+
...clientConfig,
|
206
|
+
});
|
207
|
+
const result = await client.request(action, assumeRoleWithWebIdentityParams);
|
208
|
+
return {
|
209
|
+
TmpSecretId: result.Credentials.TmpSecretId,
|
210
|
+
TmpSecretKey: result.Credentials.TmpSecretKey,
|
211
|
+
Token: result.Credentials.Token,
|
212
|
+
ExpiredTime: result.ExpiredTime,
|
213
|
+
Expiration: result.Expiration,
|
214
|
+
};
|
215
|
+
}
|
216
|
+
catch (error) {
|
217
|
+
throw new Error(`Get STS AssumeRoleWithWebIdentity failed: ${error.message}`);
|
218
|
+
}
|
219
|
+
}
|
220
|
+
async getCredential() {
|
221
|
+
if (!this.credentialTask) {
|
222
|
+
this.credentialTask = this.getCredentialWithStsAssumeRoleWithWebIdentity();
|
223
|
+
}
|
224
|
+
const credential = await this.credentialTask;
|
225
|
+
// Check if the credential is expired
|
226
|
+
if (credential.ExpiredTime * 1000 - this.expirationReservationTime <= Date.now()) {
|
227
|
+
this.credentialTask = null;
|
228
|
+
return this.getCredential();
|
229
|
+
}
|
230
|
+
return {
|
231
|
+
secretId: credential.TmpSecretId,
|
232
|
+
secretKey: credential.TmpSecretKey,
|
233
|
+
token: credential.Token,
|
234
|
+
};
|
235
|
+
}
|
236
|
+
}
|
237
|
+
exports.OIDCRoleArnCredential = OIDCRoleArnCredential;
|
238
|
+
/**
|
239
|
+
* Tencent Cloud DefaultCredentialProvider
|
240
|
+
*/
|
241
|
+
class DefaultCredentialProvider {
|
242
|
+
constructor() {
|
243
|
+
this.providers = [
|
244
|
+
new EnvironmentVariableCredential(),
|
245
|
+
new ProfileCredential(),
|
246
|
+
new cvm_role_credential_1.default(),
|
247
|
+
new OIDCRoleArnCredential()
|
248
|
+
];
|
249
|
+
}
|
250
|
+
async getCredential() {
|
251
|
+
for (const provider of this.providers) {
|
252
|
+
try {
|
253
|
+
const credential = await provider.getCredential();
|
254
|
+
if (credential.secretId && credential.secretKey) {
|
255
|
+
return credential;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
catch (error) {
|
259
|
+
// Continue to next provider if current one fails
|
260
|
+
console.error(error);
|
261
|
+
continue;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
return new BasicCredential('', '');
|
265
|
+
}
|
266
|
+
}
|
267
|
+
exports.DefaultCredentialProvider = DefaultCredentialProvider;
|
@@ -1,10 +1,5 @@
|
|
1
|
-
import { Credential, DynamicCredential } from "./interface";
|
2
|
-
interface CvmRoleCredentialResult {
|
3
|
-
TmpSecretId: string;
|
4
|
-
TmpSecretKey: string;
|
5
|
-
ExpiredTime: 1671330188;
|
6
|
-
Expiration: string;
|
7
|
-
Token: string;
|
1
|
+
import { Credential, DynamicCredential, CredentialResult } from "./interface";
|
2
|
+
interface CvmRoleCredentialResult extends CredentialResult {
|
8
3
|
Code: string;
|
9
4
|
}
|
10
5
|
/**
|
@@ -113,3 +113,10 @@ export interface Credential {
|
|
113
113
|
export interface DynamicCredential {
|
114
114
|
getCredential(): Promise<Credential>;
|
115
115
|
}
|
116
|
+
export interface CredentialResult {
|
117
|
+
TmpSecretId: string;
|
118
|
+
TmpSecretKey: string;
|
119
|
+
ExpiredTime: number;
|
120
|
+
Expiration: string;
|
121
|
+
Token: string;
|
122
|
+
}
|