租房小程序前端代码
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.

36 lines
1.3 KiB

3 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.checkCredentials = exports.setSTSToken = void 0;
  4. const formatObjKey_1 = require("./formatObjKey");
  5. async function setSTSToken() {
  6. if (!this.options)
  7. this.options = {};
  8. const now = new Date();
  9. if (this.stsTokenFreshTime) {
  10. if (+now - this.stsTokenFreshTime >= this.options.refreshSTSTokenInterval) {
  11. this.stsTokenFreshTime = now;
  12. let credentials = await this.options.refreshSTSToken();
  13. credentials = formatObjKey_1.formatObjKey(credentials, 'firstLowerCase');
  14. if (credentials.securityToken) {
  15. credentials.stsToken = credentials.securityToken;
  16. }
  17. checkCredentials(credentials);
  18. Object.assign(this.options, credentials);
  19. }
  20. }
  21. else {
  22. this.stsTokenFreshTime = now;
  23. }
  24. return null;
  25. }
  26. exports.setSTSToken = setSTSToken;
  27. function checkCredentials(obj) {
  28. const stsTokenKey = ['accessKeySecret', 'accessKeyId', 'stsToken'];
  29. const objKeys = Object.keys(obj);
  30. stsTokenKey.forEach(_ => {
  31. if (!objKeys.find(key => key === _)) {
  32. throw Error(`refreshSTSToken must return contains ${_}`);
  33. }
  34. });
  35. }
  36. exports.checkCredentials = checkCredentials;