Skip to content

Commit

Permalink
support Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Mar 25, 2021
1 parent 57ca44d commit 84a0811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qcloud-cos-sts",
"version": "3.0.2",
"version": "3.0.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
17 changes: 13 additions & 4 deletions nodejs/sdk/sts.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var util = {
compat[this.lowerFirstLetter(key)] = data[key];
}
}

return compat;
},
lowerFirstLetter: function (source) {
Expand All @@ -46,7 +46,7 @@ var util = {
};

// 拼接获取临时密钥的参数
var getCredential = function (options, callback) {
var _getCredential = function (options, callback) {

if (options.durationInSeconds !== undefined) {
console.warn('warning: durationInSeconds has been deprecated, Please use durationSeconds ).');
Expand Down Expand Up @@ -103,13 +103,22 @@ var getCredential = function (options, callback) {
} catch (e) {
callback(new Error(`Parse Response Error: ${JSON.stringify(data)}`))
}
}
}
} else {
callback(err || body);
}
});
};

var getCredential = (opt, callback) => {
if (callback) return _getCredential(opt, callback);
return new Promise((resolve, reject) => {
_getCredential(opt, (err, data) => {
err ? reject(err) : resolve(data);
});
});
};

var getPolicy = function (scope) {
// 定义绑定临时密钥的权限策略
var statement = scope.map(function (item) {
Expand Down Expand Up @@ -138,4 +147,4 @@ var cosStsSdk = {
getPolicy: getPolicy,
};

module.exports = cosStsSdk;
module.exports = cosStsSdk;

0 comments on commit 84a0811

Please sign in to comment.