vaultaire
v0.10.2
Published
JavaScript/Typescript client for HashiCorp's Vault
Downloads
2,710
Maintainers
Readme
Vaultaire
A client for the HTTP API of HashiCorp's Vault written for Node.js. Maintained fork of the node-vault project.
Install
make sure to use node.js version >= 12
npm install vaultaire
pnpm install vaultaire
yarn install vaultaire
Usage
Init and unseal
var options = {
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
var vault = require("vaultaire")(options);
// init vault server
vault.init({ secret_shares: 1, secret_threshold: 1 })
.then( (result) => {
var 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);
Test
Run tests inside docker to do also nice integration testing:
docker-compose up -d vault
pnpm test
This will create containers for vault and running the tests.
Docs
Just generate docco docs via pnpm run docs
.
Examples
Please have a look at the examples and the generated feature list to see what is already implemented.
Instead of installing all the dependencies like vault itself and other stuff you can use docker and docker-compose to link and run multiple docker containers with all of its dependencies.
git clone [email protected]:vaultaire/vaultaire.git
cd vaultaire
docker-compose up vault
Now you can run the examples from another terminal window.
First of all you should initialize and unseal the vault:
node example/init.js
You should see root_token:
followed by a long key in the response.
Please copy that long key and export it as environment variable:
export VAULT_TOKEN=<insert long key here>
Now you are able to run all of the other examples:
node example/policies.js