mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Follows template in TS docs now: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-function-d-ts.html Also makes it possible to reference interfaces from the NodeVault namespace outside of this module.
29 lines
912 B
TypeScript
29 lines
912 B
TypeScript
import nv = require("node-vault");
|
|
|
|
// Test code came from the sample code in README of the module.
|
|
const options: nv.VaultOptions = {
|
|
apiVersion: 'v1', // default
|
|
endpoint: 'http://127.0.0.1:8200', // default
|
|
token: '1234', // optional client token; can be fetched after valid initialization of the server
|
|
};
|
|
|
|
// get new instance of the client
|
|
const vault = nv(options);
|
|
|
|
// init vault server
|
|
vault.init({ secret_shares: 1, secret_threshold: 1 })
|
|
.then((result) => {
|
|
const keys = result.keys;
|
|
// set token for all following requests
|
|
vault.token = result.root_token;
|
|
// unseal vault server
|
|
return vault.unseal({ secret_shares: 1, key: keys[0] });
|
|
})
|
|
.catch(console.error);
|
|
|
|
// write, read and delete secrets
|
|
vault.write('secret/hello', { value: 'world', lease: '1s' })
|
|
.then(() => vault.read('secret/hello'))
|
|
.then(() => vault.delete('secret/hello'))
|
|
.catch(console.error);
|