cloudfunctions/ClearingRedundantFolders/node_modules/@cloudbase/manager-node/lib/utils/auth.js

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAuth = void 0;
const crypto_1 = __importDefault(require("crypto"));
function camSafeUrlEncode(str) {
    return encodeURIComponent(str)
        .replace(/!/g, '%21')
        .replace(/'/g, '%27')
        .replace(/\(/g, '%28')
        .replace(/\)/g, '%29')
        .replace(/\*/g, '%2A');
}
function getAuth(options) {
    const SecretId = options.secretId;
    const SecretKey = options.secretKey;
    const method = options.method.toLowerCase() || 'get';
    const queryParams = options.params || {};
    const headers = options.headers || {};
    let pathname = options.pathname || '/';
    pathname.indexOf('/') !== 0 && (pathname = '/' + pathname);
    if (!SecretId) {
        throw Error('missing param SecretId');
    }
    if (!SecretKey) {
        throw Error('missing param SecretKey');
    }
    const getObjectKeys = function (obj) {
        return Object.keys(obj)
            .filter(key => typeof obj[key] !== 'undefined')
            .sort();
    };
    const objectToString = function (obj) {
        const list = [];
        const keyList = getObjectKeys(obj);
        keyList.forEach(key => {
            let value = obj[key] === null || typeof obj[key] === 'undefined' ? '' : obj[key];
            if (typeof value !== 'string') {
                value = JSON.stringify(value);
            }
            list.push(`${camSafeUrlEncode(key.toLowerCase())}=${camSafeUrlEncode(value)}`);
        });
        return list.join('&');
    };
    // 签名有效起止时间
    const now = Math.floor(Date.now() / 1000) - 1;
    // 签名过期时间为当前 + 900s
    const exp = now + 900;
    // 要用到的 Authorization 参数列表
    const qSignAlgorithm = 'sha1';
    const qAk = SecretId;
    const qKeyTime = now + ';' + exp;
    const qHeaderList = getObjectKeys(headers)
        .join(';')
        .toLowerCase();
    const qUrlParamList = getObjectKeys(queryParams)
        .join(';')
        .toLowerCase();
后面还有 37 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。