Vault
Install
| npm install @testcontainers/vault --save-dev
|
Examples
These examples use the following libraries:
Choose an image from the container registry and substitute IMAGE.
Write/read a value
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 | await using container = await new VaultContainer(IMAGE).withVaultToken(VAULT_TOKEN).start();
const client = new Client({
endpoint: container.getAddress(),
token: container.getRootToken(),
});
const writeResult = await client.kv2.write({
mountPath: "secret",
path: "hello",
data: {
message: "world",
other: "vault",
},
});
expect(writeResult.error).toBeUndefined();
const readResult = await client.kv2.read({
mountPath: "secret",
path: "hello",
});
if (readResult.error) {
throw readResult.error;
}
const data = readResult.data.data.data;
expect(data.message).toBe("world");
expect(data.other).toBe("vault");
|
Run CLI init commands at startup
| await using container = await new VaultContainer(IMAGE)
.withVaultToken(VAULT_TOKEN)
.withInitCommands("secrets enable transit", "write -f transit/keys/my-key")
.start();
const result = await container.exec(["vault", "read", "-format=json", "transit/keys/my-key"]);
expect(result.exitCode).toBe(0);
expect(result.output).toContain("my-key");
|