Skip to content
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

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e2cdd59
Moved project to standardjs javascript styleguide
Jan 7, 2018
d9a1c2a
Untested first refactored version
Jan 7, 2018
53e337f
Fixed small bug
Jan 7, 2018
e5f441a
Cleaned up legacy eslint stuff and upgraded all modules
Jan 7, 2018
2ea2d80
Fixed tests
Jan 7, 2018
ea915c7
Cleaned and improved testing stuff
Jan 7, 2018
517474d
Specified node v8 requirement on README
Jan 7, 2018
78d0e68
Added myself as a contributor
Jan 7, 2018
95885de
Removed redundant code on the feature definitions
Jan 7, 2018
e320dfc
Added documentation comments to features file
Jan 7, 2018
3a26e5d
Added documentation to features (uncompleted) and more
Jan 7, 2018
00118d1
Cleaned up and organized README.md
Jan 8, 2018
61cf32b
Fixed formatting typo
Jan 8, 2018
a474bd1
Added documentation of resource methods as well
Jan 8, 2018
ff46136
Small improvement to features.md
Jan 8, 2018
581a86d
Refreshed features.md
Jan 8, 2018
b9d7c2e
Small indentation fix
Jan 8, 2018
cd0d3ab
Renamed request module in index.js
Jan 8, 2018
ee3a73a
Refreshed yarn.lock to use yarpkg registry
Jan 8, 2018
6df15da
Added documentation, organized files and improved some code styles
Jan 8, 2018
77c95df
Improved docco
Jan 8, 2018
2031e34
Code cleanup and reorganization + added login and logout methods to c…
Jan 9, 2018
926cc30
Fixed unit tests typo
Jan 9, 2018
82836f9
Removed mustache
Jan 9, 2018
1bca633
Upgraded sinon
Jan 9, 2018
3175f44
Refactored examples
Jan 10, 2018
c298c29
Fixed 'main' entry in package.json
Jan 11, 2018
6627755
Fixed typo in `yarn add` example of README.md
Jan 15, 2018
306751f
Improved yarn script to refresh the local docker vault container
Jan 15, 2018
3c32577
Removed file pushed by mistake
Jan 15, 2018
1836216
Modified main to support node v6+ (removed async / await statements)
Jan 15, 2018
bdbeff1
Added node v6 and v7 support to travis
Jan 15, 2018
c6a23d7
Update README.md
Jan 15, 2018
886ffd6
Fixed README.md examples
Jan 15, 2018
685612a
Fixed docco yarn script
Jan 16, 2018
270e433
Merge branch 'master' of github.com:DaniGuardiola/node-vault into ref…
Jan 16, 2018
f0e3655
Update README.md
Jan 17, 2018
f1efbe3
Cleaned up examples
Jan 18, 2018
4c38061
Merge branch 'refactor' of github.com:DaniGuardiola/node-vault into r…
Jan 18, 2018
1d3d118
Merge branch 'master' into refactor
Jan 22, 2018
b97baca
Fixed "example" directory and added others in package.json
Jan 31, 2018
e478931
Merge branch 'master' of github.com:kr1sp1n/node-vault into refactor
Jan 31, 2018
9014306
Merge branch 'refactor' of github.com:DaniGuardiola/node-vault into r…
Jan 31, 2018
3aa13f9
Made features DRYer by generating third party logins
Jan 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

27 changes: 0 additions & 27 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ script:
- docker run --name vault -e 'SKIP_SETCAP=true' -d -p "8200:8200" vault
- docker ps
- docker logs vault
- npm run coverage
- npm run complete-test

after_success:
- codecov
4 changes: 2 additions & 2 deletions Dockerfile
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
Copy link
Collaborator

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 👍

RUN yarn
COPY . /app
108 changes: 64 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'
services:
test:
build: .
command: npm run coverage
command: yarn complete-test
environment:
- VAULT_ADDR=http://vault:8200
volumes:
Expand All @@ -13,11 +13,11 @@ services:
vault:
image: vault
volumes:
- $PWD/example:/tmp/example
- $PWD/examples:/tmp/examples
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keeping example as name for the folder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are more than one example :) it's more descriptive

Copy link
Collaborator

@kr1sp1n kr1sp1n Jan 18, 2018

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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:
Expand Down
16 changes: 0 additions & 16 deletions example/audits.js

This file was deleted.

15 changes: 0 additions & 15 deletions example/auth.js

This file was deleted.

30 changes: 0 additions & 30 deletions example/auth_approle.js

This file was deleted.

24 changes: 0 additions & 24 deletions example/auth_github.js

This file was deleted.

22 changes: 0 additions & 22 deletions example/auth_ldap.js

This file was deleted.

22 changes: 0 additions & 22 deletions example/auth_userpass.js

This file was deleted.

9 changes: 0 additions & 9 deletions example/health.js

This file was deleted.

9 changes: 0 additions & 9 deletions example/help.js

This file was deleted.

Loading