-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrotate.mjs
52 lines (45 loc) · 1.47 KB
/
rotate.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
41
42
43
44
45
46
47
48
49
50
51
52
/* eslint-disable no-console */
import { PangeaConfig, VaultService, PangeaErrors } from "pangea-node-sdk";
const token = process.env.PANGEA_VAULT_TOKEN;
const config = new PangeaConfig({ domain: process.env.PANGEA_DOMAIN });
const vault = new VaultService(token, config);
(async () => {
const secretV1 = "mySecret";
const secretV2 = "myNEWSecret";
try {
console.log("Store...");
// Name should be unique
const name = "Node rotate example " + Date.now();
const storeResponse = await vault.secretStore({
secret: secretV1,
name: name,
});
console.log("Response: %s", storeResponse.result);
const id = storeResponse.result.id;
console.log("Rotating...");
const rotateResponse = await vault.secretRotate({
id: id,
secret: secretV2,
});
console.log("Response: %s", rotateResponse.result);
console.log("Getting last version...");
const getLastResponse = await vault.getItem({
id: id,
});
console.log("Response: %s", getLastResponse.result);
console.log("Version: ", getLastResponse.result.item_versions[0]);
console.log("Getting version 1...");
const getV1Response = await vault.getItem({
id,
version: "1",
});
console.log("Response: %s", getV1Response.result);
console.log("Version: ", getV1Response.result.item_versions[0]);
} catch (err) {
if (err instanceof PangeaErrors.APIError) {
console.log(err.toString());
} else {
throw err;
}
}
})();