-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-password.mjs
40 lines (36 loc) · 1.14 KB
/
get-password.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { formatUrl } from "@aws-sdk/util-format-url";
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { Hash } from "@smithy/hash-node";
import { HttpRequest } from "@smithy/protocol-http";
import { SignatureV4 } from "@smithy/signature-v4";
import { loadConfig } from "@smithy/node-config-provider";
import {
NODE_REGION_CONFIG_FILE_OPTIONS,
NODE_REGION_CONFIG_OPTIONS,
} from "@smithy/config-resolver";
const signer = new SignatureV4({
service: "elasticache",
sha256: Hash.bind(null, "sha256"),
credentials: fromNodeProviderChain(),
region: loadConfig(
NODE_REGION_CONFIG_OPTIONS,
NODE_REGION_CONFIG_FILE_OPTIONS
),
});
export const getPassword = async ({ clusterName, username, serverless }) => {
const request = new HttpRequest({
protocol: "https:",
hostname: clusterName,
method: "GET",
headers: { host: clusterName },
query: {
Action: "connect",
User: username,
...(serverless && { ResourceType: "ServerlessCache" }),
},
});
const presigned = await signer.presign(request, {
expiresIn: 900,
});
return formatUrl(presigned).slice("https://".length);
};