Giter Site home page Giter Site logo

zailic / nanvc Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 735 KB

A node client for HashiCorp's Vault written in typescript

License: MIT License

TypeScript 83.66% HCL 0.30% Shell 13.91% Dockerfile 0.41% JavaScript 1.72%
vault vault-api typescript hashicorp

nanvc's Introduction

nanvc - Not Another Node Vault Client

build status code coverage

This is a Vault client written in typescript.

Table of contents

Install

# requires nodejs >= 14
npm install nanvc --save

How to use it

The VaultClient constructor takes three optional arguments:

  • vault cluster address - if not passed in, defaults to NANVC_VAULT_CLUSER_ADDRESS environment variable otherwise it will take 'http://127.0.0.1:8200' value
  • vault auth token - if not passed in, defaults to NANVC_VAULT_AUTH_TOKEN env. variable, otherwise will be set to null
  • vault api version - if not passed in, defaults to NANVC_VAULT_API_VERSION environment variable, otherwise is set internaly to 'v1'

ES5

var VaultClient = require('nanvc');
var vault = new VaultClient('http://vault.local:8200');
vault.init({ 
        secret_shares: 1, 
        secret_threshold: 1 
    })
    .then(function (result) { // unseal vault
        console.log("Unsealing vault");
        console.log(result);
        if (!result.succeeded) {
            throw new Error(result.errorMessage);
        }
        var keys = result.apiResponse.keys;
        vault.token = result.apiResponse.root_token;
        return vault.unseal({
            secret_shares: 1,
            key: keys[0]
        });
    })
    .then(function (response) { // write a secret
        console.log("Writing a secret");
        return vault.write(
            '/secret/my-app/my-secret', { 
                'foo': 'my-password' 
            }
        )
    })
    .then(function(response) { // update a secret
        console.log(response);
        console.log("Updating secret");
        return vault.update(
            '/secret/my-app/my-secret', { 
                'foo': 'my-updated-password' 
            }
        );  
    })
    .then(function(response){ // read a secret
        console.log(response);
        console.log("Reading a secret");
        return vault.read('/secret/my-app/my-secret');
    })
    .then(function(response){ // delete a secret
        console.log(response);
        console.log("Deleting a secret");
        return vault.delete('/secret/my-app/my-secret');
    })
    .then(function(response){ // handle delete response 
        console.log(response);
    })
    .catch(console.error);

ES6

import VaultClient from "nanvc";
let vault = new VaultClient('http://vault.local:8200');

async function main() {
    try {
        let initResponse = await vault.init({
            secret_shares: 1,
            secret_threshold: 1
        });

        if (initResponse.succeeded) {
            console.log(initResponse);
            vault.token = initResponse.apiResponse.root_token;
            let unsealResponse = await vault.unseal({
                secret_shares: 1,
                key: initResponse.apiResponse.keys[0]
            });
            if (!unsealResponse.succeeded) {
                throw new Error(unsealResponse.errorMessage);
            }
        } else {
            throw new Error(initResponse.errorMessage);
        }
        // write a secret
        let writeSecretResponse = await vault.write('/secret/my-app/my-secret', { 'foo': 'my-password' });
        console.log(writeSecretResponse);
        // update a secret
        let updateSecretResponse = await vault.update('/secret/my-app/my-secret', { 'foo': 'my-updated-password' });
        console.log(updateSecretResponse);
        // read a secret
        let mySecretQueryResponse = await vault.read('/secret/my-app/my-secret');
        let mySecret = mySecretQueryResponse.succeeded && mySecretQueryResponse.apiResponse.data.foo;
        console.log(mySecretQueryResponse);
        // delete a secret
        let mySecretDeleteQueryResponse = await vault.delete('/secret/my-app/my-secret');
        let mySecretIsDeleted = mySecretDeleteQueryResponse.succeeded;
        console.log(mySecretDeleteQueryResponse);
    } catch (e) {
        throw (e);
    }

}

main().then().catch(console.error);

What is supported

Vault Rest API Call Http Method Client Library Method Tested
/:path GET VaultClient.read(secretPath: string) Yes
/:path POST VaultClient.write(secretPath: string, secretData: object) Yes
/:path PUT VaultClient.update(secretPath: string, secretData: object) Yes
/:path DELETE VaultClient.delete(secretPath: string) Yes
/:path LIST VaultClient.list(path: string) Yes
/sys/audit GET VaultClient.audits() Yes
/sys/audit/:name PUT VaultClient.enableAudit(auditName: string) Yes
/sys/audit/:name DELETE VaultClient.disableAudit(auditName: string) Yes
/sys/audit-hash/:path POST VaultClient.auditHash(path: string, payload: object) Yes
/sys/auth GET VaultClient.auths() Yes
/sys/auth POST VaultClient.enableAuth(path: string, payload: object) Yes
/sys/auth DELETE VaultClient.disableAuth(path: string) Yes
/sys/capabilities POST N/A N/A
/sys/capabilities-accessor POST N/A N/A
/sys/capabilities-self POST N/A N/A
/sys/config/auditing GET N/A N/A
/sys/config/control-group GET N/A N/A
/sys/config/cors GET N/A N/A
/sys/control-group POST N/A N/A
/sys/generate-root GET N/A N/A
/sys/health HEAD N/A N/A
/sys/health GET N/A N/A
/sys/init GET VaultClient.isInitialized() Yes
/sys/init PUT VaultClient.init(initData: object) Yes
/sys/key-status GET N/A N/A
/sys/leader GET N/A N/A
/sys/leases PUT N/A N/A
/sys/leases LIST N/A N/A
/sys/license GET N/A N/A
/sys/mfa N/A N/A N/A
/sys/mounts GET VaultClient.mounts() Yes
/sys/mounts/:mount_point POST VaultClient.mount(path: string, mountOptions: object) Yes
/sys/mounts/:mount_point DELETE VaultClient.unmount(path: string) Yes
/sys/mounts/:mount_point/tune POST N/A N/A
/sys/plugins/reload/backend PUT N/A N/A
/sys/plugins/catalog LIST N/A N/A
/sys/plugins/catalog/:catalog_name PUT N/A N/A
/sys/plugins/catalog/:catalog_name GET N/A N/A
/sys/plugins/catalog/:catalog_name DELETE N/A N/A
/sys/policy GET VaultClient.policies() No
/sys/policy PUT VaultClient.addPolicy(policyName: string, policyData: obkect ) No
/sys/policy DELETE VaultClient.removePolicy(policyName: string) No
/sys/policies N/A N/A N/a
/sys/raw N/A N/A N/A
/sys/rekey N/A N/A N/A
/sys/rekey-recovery-key N/A N/A N/A
/sys/remount POST VaultClient.remount(remountData: object) Yes
/sys/replication N/A N/A N/A
/sys/rotate N/A N/A N/A
/sys/seal PUT VaultClient.seal() Yes
/sys/seal-status GET VaultClient.status() Yes
/sys/step-down N/A N/A N/A
/sys/tools N/A N/A N/A
/sys/unseal PUT VaultClient.unseal(unsealData: object) Yes
/sys/wrapping/lookup N/A N/A N/A
/sys/wrapping/rewrap N/A N/A N/A
/sys/wrapping/unwrap N/A N/A N/A
/sys/wrapping/wrap N/A N/A N/A

TODO list

  • Better documentation(API, more samples, what is supported and what is NOT)
  • Full support for "System Backend Commands"
  • Typescript declarations - it will bring IDE intellisense for tools like Vscode, IntelliJ IDEA, Atom, etc

nanvc's People

Contributors

renovate-bot avatar zailic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

godokoro hensur

nanvc's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency eslint to v8.57.0
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update actions/stale action to v9
  • chore(deps): update codecov/codecov-action action to v4
  • chore(deps): update dependency @types/sinon to v17
  • chore(deps): update dependency chai to v5
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency nyc to v17
  • chore(deps): update dependency rimraf to v6
  • chore(deps): update dependency sinon to v18
  • chore(deps): update dependency typescript to v5
  • chore(deps): update github/codeql-action action to v3
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

docker-compose
docker-compose.yml
github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v2
  • github/codeql-action v1
  • github/codeql-action v1
  • github/codeql-action v1
.github/workflows/main.yaml
  • actions/checkout v2
  • actions/setup-node v2
  • codecov/codecov-action v1
.github/workflows/publish.yaml
  • actions/checkout v2
  • actions/setup-node v1
.github/workflows/stale.yaml
  • actions/stale v3
npm
package.json
  • got 11.8.2
  • tv4 1.3.0
  • @testdeck/mocha 0.2.0
  • @types/chai 4.3.0
  • @types/got 9.6.12
  • @types/mocha 9.1.0
  • @types/sinon 10.0.11
  • @types/tv4 1.2.31
  • @typescript-eslint/eslint-plugin 5.16.0
  • @typescript-eslint/parser 5.16.0
  • chai 4.3.6
  • eslint 8.11.0
  • eslint-config-prettier 8.5.0
  • eslint-plugin-import 2.25.4
  • mocha 9.2.2
  • nyc 15.1.0
  • rimraf 3.0.2
  • sinon 13.0.1
  • ts-node 10.7.0
  • typescript 4.6.2
  • node >=14

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.