File Explorer

/proc/self/task/7/root/var/runtime/node_modules/@aws-sdk/middleware-token/dist-cjs

This explorer reads the filesystem of the server it runs on, so /workspace/user isn't present here. Browsing and the terminal still work against this server's own disk from /.

index.js2.1 KB · 61 lines
const { HttpRequest } = require("@smithy/core/protocols");const { HttpAuthLocation } = require("@smithy/types");const { normalizeProvider } = require("@smithy/core/client");const { memoize } = require("@smithy/core/config");const { nodeProvider } = require("@aws-sdk/token-providers"); const tokenMiddlewareOptions = {    name: "tokenMiddleware",    tags: ["TOKEN", "AUTH"],    relation: "after",    toMiddleware: "retryMiddleware",    override: true,};const tokenMiddleware = (options) => (next, context) => async (args) => {    if (!HttpRequest.isInstance(args.request) || context.currentAuthConfig)        return next(args);    const token = options.token && (await options.token());    if (token?.token) {        const authConfig = {            in: HttpAuthLocation.HEADER,            name: "authorization",            scheme: "Bearer",        };        context.currentAuthConfig = authConfig;        args.request.headers[authConfig.name] = `${authConfig.scheme} ${token.token}`;    }    else {        context.currentAuthConfig = undefined;    }    return next(args);}; const getTokenPlugin = (options) => ({    applyToStack: (clientStack) => {        clientStack.addRelativeTo(tokenMiddleware(options), tokenMiddlewareOptions);    },}); const isTokenWithExpiry = (token) => token.expiration !== undefined;const isTokenExpiringWithinFiveMins = (token) => isTokenWithExpiry(token) && token.expiration.getTime() - Date.now() < 300000;const normalizeTokenProvider = (token) => {    if (typeof token === "function") {        return memoize(token, isTokenExpiringWithinFiveMins, isTokenWithExpiry);    }    return normalizeProvider(token);}; const tokenDefaultProvider = nodeProvider; const resolveTokenConfig = (input) => {    const { token } = input;    return Object.assign(input, {        token: token ? normalizeTokenProvider(token) : tokenDefaultProvider(input),    });}; exports.getTokenPlugin = getTokenPlugin;exports.resolveTokenConfig = resolveTokenConfig;exports.tokenMiddleware = tokenMiddleware;exports.tokenMiddlewareOptions = tokenMiddlewareOptions;