You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
4 weeks ago
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.checkCredentials = exports.setSTSToken = void 0;
|
||
|
const formatObjKey_1 = require("./formatObjKey");
|
||
|
async function setSTSToken() {
|
||
|
if (!this.options)
|
||
|
this.options = {};
|
||
|
const now = new Date();
|
||
|
if (this.stsTokenFreshTime) {
|
||
|
if (+now - this.stsTokenFreshTime >= this.options.refreshSTSTokenInterval) {
|
||
|
this.stsTokenFreshTime = now;
|
||
|
let credentials = await this.options.refreshSTSToken();
|
||
|
credentials = formatObjKey_1.formatObjKey(credentials, 'firstLowerCase');
|
||
|
if (credentials.securityToken) {
|
||
|
credentials.stsToken = credentials.securityToken;
|
||
|
}
|
||
|
checkCredentials(credentials);
|
||
|
Object.assign(this.options, credentials);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
this.stsTokenFreshTime = now;
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
exports.setSTSToken = setSTSToken;
|
||
|
function checkCredentials(obj) {
|
||
|
const stsTokenKey = ['accessKeySecret', 'accessKeyId', 'stsToken'];
|
||
|
const objKeys = Object.keys(obj);
|
||
|
stsTokenKey.forEach(_ => {
|
||
|
if (!objKeys.find(key => key === _)) {
|
||
|
throw Error(`refreshSTSToken must return contains ${_}`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
exports.checkCredentials = checkCredentials;
|