File Explorer

/var/runtime/node_modules/@aws-sdk/rds-signer/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.js3.0 KB · 87 lines
const { formatUrl } = require("@aws-sdk/core/util");const { Sha256 } = require("@smithy/core/checksum");const { HttpRequest } = require("@smithy/core/protocols");const { SignatureV4 } = require("@smithy/signature-v4");const { fromNodeProviderChain } = require("@aws-sdk/credential-providers");const { loadConfig, NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS } = require("@smithy/core/config"); const getRuntimeConfig = (config) => {    return {        runtime: "node",        ...config,        credentials: config?.credentials ??            fromNodeProviderChain({                profile: config.profile,            }),        region: config?.region ??            loadConfig(NODE_REGION_CONFIG_OPTIONS, {                ...NODE_REGION_CONFIG_FILE_OPTIONS,                profile: config.profile,            }),    };}; const MINUTE_MS = 60_000;class Signer {    credentials;    hostname;    port;    protocol = "https:";    region;    service = "rds-db";    sha256;    username;    constructor(configuration) {        const runtimeConfiguration = getRuntimeConfig(configuration);        const creds = runtimeConfiguration.credentials;        this.credentials = typeof creds === "function" ? this.createCredentialsWrapper(creds) : creds;        this.hostname = runtimeConfiguration.hostname;        this.port = runtimeConfiguration.port;        this.region = runtimeConfiguration.region;        this.sha256 = runtimeConfiguration.sha256 ?? Sha256;        this.username = runtimeConfiguration.username;    }    async getAuthToken() {        const signer = new SignatureV4({            service: this.service,            region: this.region,            credentials: this.credentials,            sha256: this.sha256,        });        const request = new HttpRequest({            method: "GET",            protocol: this.protocol,            hostname: this.hostname,            port: this.port,            query: {                Action: "connect",                DBUser: this.username,            },            headers: {                host: `${this.hostname}:${this.port}`,            },        });        const presigned = await signer.presign(request, {            expiresIn: 900,        });        return formatUrl(presigned).replace(`${this.protocol}//`, "");    }    createCredentialsWrapper(provider) {        return async (identityProperties) => {            const credentials = await provider(identityProperties);            if (credentials.expiration && credentials.expiration.getTime() - Date.now() < 15 * MINUTE_MS) {                try {                    const refreshed = await provider({ ...identityProperties, forceRefresh: true });                    if (!refreshed.expiration || refreshed.expiration.getTime() - Date.now() >= 15 * MINUTE_MS) {                        return refreshed;                    }                }                catch { }            }            return credentials;        };    }} exports.Signer = Signer;