-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I refactored the project #78
Changes from all commits
e2cdd59
d9a1c2a
53e337f
e5f441a
2ea2d80
ea915c7
517474d
78d0e68
95885de
e320dfc
3a26e5d
00118d1
61cf32b
a474bd1
ff46136
581a86d
b9d7c2e
cd0d3ab
ee3a73a
6df15da
77c95df
2031e34
926cc30
82836f9
1bca633
3175f44
c298c29
6627755
306751f
3c32577
1836216
bdbeff1
c6a23d7
886ffd6
685612a
270e433
f0e3655
f1efbe3
4c38061
1d3d118
b97baca
e478931
9014306
3aa13f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
FROM node:8.6-alpine | ||
FROM node:8.9.4 | ||
WORKDIR /app | ||
COPY package.json /app | ||
RUN npm install | ||
RUN yarn | ||
COPY . /app |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,74 +5,78 @@ | |
[![Download Status](https://img.shields.io/npm/dm/node-vault.svg?style=flat-square)](https://www.npmjs.com/package/node-vault) | ||
[![Dependency Status](https://img.shields.io/david/kr1sp1n/node-vault.svg?style=flat-square)](https://david-dm.org/kr1sp1n/node-vault) | ||
|
||
A client for the HTTP API of HashiCorp's [Vault] written for Node.js. | ||
NodeJS API client for HashiCorp's [Vault] | ||
|
||
|
||
## install | ||
make sure to use node.js version >= 6 | ||
## Install | ||
`node-vault` supports Node.js v6 and above. | ||
|
||
# yarn | ||
yarn add node-vault | ||
|
||
# npm | ||
npm install node-vault | ||
|
||
|
||
## test | ||
## Usage | ||
|
||
Run tests inside docker to do also nice integration testing: | ||
**[All features]** | ||
|
||
docker-compose up --force-recreate test | ||
|
||
This will create containers for vault, postgres and running the tests inside | ||
docker. | ||
|
||
|
||
## usage | ||
|
||
### init and unseal | ||
### Init and unseal | ||
|
||
```javascript | ||
var options = { | ||
const 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 | ||
}; | ||
// VAULT_ADDR environment variable is also available | ||
token: '<vault token>' // client authentication token, optional | ||
// VAULT_TOKEN environment variable is also available | ||
} | ||
|
||
// get new instance of the client | ||
var vault = require("node-vault")(options); | ||
const vault = require('node-vault')(options) | ||
|
||
// init vault server | ||
vault.init({ secret_shares: 1, secret_threshold: 1 }) | ||
.then( (result) => { | ||
var keys = result.keys; | ||
const run = async () => { | ||
// init vault server | ||
const initData = await vault.init({ secret_shares: 1, secret_threshold: 1 }) | ||
// set token for all following requests | ||
vault.token = result.root_token; | ||
vault.login(initData.root_token) | ||
// unseal vault server | ||
return vault.unseal({ secret_shares: 1, key: keys[0] }) | ||
}) | ||
.catch(console.error); | ||
const [key] = initData.keys | ||
await vault.unseal({ secret_shares: 1, key }) | ||
} | ||
|
||
run().catch(console.error) | ||
``` | ||
|
||
### write, read and delete secrets | ||
### Write, read and delete secrets | ||
|
||
```javascript | ||
vault.write('secret/hello', { value: 'world', lease: '1s' }) | ||
.then( () => vault.read('secret/hello')) | ||
.then( () => vault.delete('secret/hello')) | ||
.catch(console.error); | ||
const run = async () => { | ||
await vault.write('secret/hello', { value: 'world', lease: '1s' }) | ||
await vault.read('secret/hello') | ||
await vault.delete('secret/hello') | ||
} | ||
|
||
run().catch(console.error) | ||
``` | ||
|
||
## docs | ||
Just generate [docco] docs via `npm run docs`. | ||
## Code documentation | ||
Generate [docco] docs via `yarn docs`. | ||
|
||
|
||
## examples | ||
Please have a look at the [examples] and the generated [feature list] to see what is already implemented. | ||
## Examples and feature list | ||
Have a look at the [examples] and the generated [feature list] to see what is implemented. | ||
|
||
Instead of installing all the dependencies like vault itself, postgres and other stuff you can | ||
When running the examples, instead of installing all the dependencies like vault, postgres and other stuff you can | ||
use [docker] and [docker-compose] to link and run multiple docker containers with all of its dependencies. | ||
|
||
> Note that node v8+ is required to run the examples, due to the usage of `async/await`. | ||
|
||
```bash | ||
git clone [email protected]:kr1sp1n/node-vault.git | ||
cd node-vault | ||
docker-compose up vault | ||
docker-compose up --force-recreate vault # or use "yarn refresh-docker-vault" | ||
``` | ||
|
||
Now you can run the examples from another terminal window. | ||
|
@@ -92,13 +96,29 @@ Now you are able to run all of the other [examples]: | |
node example/policies.js | ||
``` | ||
|
||
You can also init vault and run all of the examples in one go by running `yarn examples` (which just executes [examples/all.js]) | ||
|
||
## Testing | ||
|
||
You can run the automated tests with `yarn test`. | ||
To run tests inside docker (making it very easy to run the integration tests) simply run: | ||
|
||
docker-compose up --force-recreate test | ||
|
||
There's also this yarn alias available: `yarn docker-test`. | ||
|
||
> Note that you will need to install and setup [docker] and [docker-compose] | ||
|
||
This will create containers for vault, postgres and the tests themselves. | ||
|
||
|
||
|
||
[examples]: https://github.com/kr1sp1n/node-vault/tree/master/example | ||
[docker-compose.yml]: https://github.com/kr1sp1n/node-vault/tree/master/docker-compose.yml | ||
[examples]: /examples | ||
[examples/all.js]: examples/all.js | ||
[docker-compose.yml]: /docker-compose.yml | ||
[Vault]: https://vaultproject.io/ | ||
[docker-compose]: https://www.docker.com/docker-compose | ||
[docker]: http://docs.docker.com/ | ||
[docker toolbox]: https://www.docker.com/toolbox | ||
[docco]: http://jashkenas.github.io/docco | ||
[feature list]: https://github.com/kr1sp1n/node-vault/tree/master/features.md | ||
[docker]: https://docs.docker.com/ | ||
[docker-compose]: https://docs.docker.com/compose/ | ||
[docco]: http://ashkenas.com/docco/ | ||
[All features]: features.md | ||
[feature list]: features.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ version: '2' | |
services: | ||
test: | ||
build: . | ||
command: npm run coverage | ||
command: yarn complete-test | ||
environment: | ||
- VAULT_ADDR=http://vault:8200 | ||
volumes: | ||
|
@@ -13,11 +13,11 @@ services: | |
vault: | ||
image: vault | ||
volumes: | ||
- $PWD/example:/tmp/example | ||
- $PWD/examples:/tmp/examples | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there are more than one example :) it's more descriptive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, fine with this change but there are still some inconsistencies e.g. https://github.com/kr1sp1n/node-vault/pull/78/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R23 and the comment in the first line of the example files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. I forgot the package.json stuff. Yup I will fix that, and maybe also add test, lib and doc directories. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kr1sp1n Done |
||
- $PWD/logs/:/tmp/logs | ||
cap_add: | ||
- IPC_LOCK | ||
command: server -config /tmp/example/config.hcl | ||
command: server -config /tmp/examples/config.hcl | ||
ports: | ||
- "8200:8200" | ||
depends_on: | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with yarn 👍