@cloudbase/node-sdk
Advanced tools
Comparing version 3.6.0 to 3.7.0
@@ -50,19 +50,15 @@ "use strict"; | ||
exports.getEnvIdFromContext = getEnvIdFromContext; | ||
async function getCredentialsOnDemand(credentials) { | ||
function getCredentialsOnDemand(credentials) { | ||
const { secretId, secretKey } = credentials; | ||
let newCredentials = credentials; | ||
// 原本这里只在SCF云函数环境下,运行支持任意环境通过环境变量传递密钥 | ||
if (!secretId || !secretKey) { | ||
if ((0, cloudplatform_1.checkIsInScf)()) { | ||
// 放在此处是为了兼容本地环境下读环境变量 | ||
const { TENCENTCLOUD_SECRETID, TENCENTCLOUD_SECRETKEY, TENCENTCLOUD_SESSIONTOKEN } = cloudbase_1.CloudBase.getCloudbaseContext(); | ||
if (!TENCENTCLOUD_SECRETID || !TENCENTCLOUD_SECRETKEY) { | ||
throw E(Object.assign(Object.assign({}, code_1.ERROR.INVALID_PARAM), { message: 'missing secretId or secretKey of tencent cloud' })); | ||
} | ||
else { | ||
newCredentials = { | ||
secretId: TENCENTCLOUD_SECRETID, | ||
secretKey: TENCENTCLOUD_SECRETKEY, | ||
sessionToken: TENCENTCLOUD_SESSIONTOKEN | ||
}; | ||
} | ||
// 尝试从环境变量中读取 | ||
const { TENCENTCLOUD_SECRETID, TENCENTCLOUD_SECRETKEY, TENCENTCLOUD_SESSIONTOKEN } = cloudbase_1.CloudBase.getCloudbaseContext(); | ||
if (TENCENTCLOUD_SECRETID && TENCENTCLOUD_SECRETKEY) { | ||
newCredentials = { | ||
secretId: TENCENTCLOUD_SECRETID, | ||
secretKey: TENCENTCLOUD_SECRETKEY, | ||
sessionToken: TENCENTCLOUD_SESSIONTOKEN | ||
}; | ||
} | ||
@@ -112,3 +108,3 @@ // 注意:CBR 环境下,已经禁止该方式获取临时密钥,这里实际是不会成功的 | ||
const { secretId, secretKey, sessionToken } = this.config; | ||
const credentials = await getCredentialsOnDemand({ secretId, secretKey, sessionToken }); | ||
const credentials = getCredentialsOnDemand({ secretId, secretKey, sessionToken }); | ||
this.config = Object.assign(Object.assign({}, this.config), { secretId: credentials.secretId, secretKey: credentials.secretKey, sessionToken: credentials.sessionToken }); | ||
@@ -115,0 +111,0 @@ if (!this.config.secretId || !this.config.secretKey) { |
{ | ||
"name": "@cloudbase/node-sdk", | ||
"version": "3.6.0", | ||
"version": "3.7.0", | ||
"description": "tencent cloud base server sdk for node.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -39,25 +39,20 @@ import http from 'http' | ||
export async function getCredentialsOnDemand(credentials: ITencentCloudCredentials): Promise<ITencentCloudCredentials> { | ||
export function getCredentialsOnDemand(credentials: ITencentCloudCredentials): ITencentCloudCredentials { | ||
const { secretId, secretKey } = credentials | ||
let newCredentials: ITencentCloudCredentials = credentials | ||
let newCredentials: ITencentCloudCredentials = credentials | ||
// 原本这里只在SCF云函数环境下,运行支持任意环境通过环境变量传递密钥 | ||
if (!secretId || !secretKey) { | ||
if (checkIsInScf()) { | ||
// 放在此处是为了兼容本地环境下读环境变量 | ||
const { | ||
TENCENTCLOUD_SECRETID, | ||
TENCENTCLOUD_SECRETKEY, | ||
TENCENTCLOUD_SESSIONTOKEN | ||
} = CloudBase.getCloudbaseContext() | ||
if (!TENCENTCLOUD_SECRETID || !TENCENTCLOUD_SECRETKEY) { | ||
throw E({ | ||
...ERROR.INVALID_PARAM, | ||
message: 'missing secretId or secretKey of tencent cloud' | ||
}) | ||
} else { | ||
newCredentials = { | ||
secretId: TENCENTCLOUD_SECRETID, | ||
secretKey: TENCENTCLOUD_SECRETKEY, | ||
sessionToken: TENCENTCLOUD_SESSIONTOKEN | ||
} | ||
// 尝试从环境变量中读取 | ||
const { | ||
TENCENTCLOUD_SECRETID, | ||
TENCENTCLOUD_SECRETKEY, | ||
TENCENTCLOUD_SESSIONTOKEN | ||
} = CloudBase.getCloudbaseContext() | ||
if (TENCENTCLOUD_SECRETID && TENCENTCLOUD_SECRETKEY) { | ||
newCredentials = { | ||
secretId: TENCENTCLOUD_SECRETID, | ||
secretKey: TENCENTCLOUD_SECRETKEY, | ||
sessionToken: TENCENTCLOUD_SESSIONTOKEN | ||
} | ||
@@ -118,3 +113,3 @@ } | ||
const { secretId, secretKey, sessionToken } = this.config | ||
const credentials = await getCredentialsOnDemand({ secretId, secretKey, sessionToken }) | ||
const credentials = getCredentialsOnDemand({ secretId, secretKey, sessionToken }) | ||
this.config = { | ||
@@ -121,0 +116,0 @@ ...this.config, |
255973
7128