Code Monkey home page Code Monkey logo

node-vault's Introduction

node-vault

A Javascript client for the HTTP API of HashiCorp's vault with a focus on ease of use.

npm install @litehex/node-vault

Usage

Init and unseal vault
import { Client } from '@litehex/node-vault';

// Get a new instance of the client
const vc = new Client({
  apiVersion: 'v1', // default
  endpoint: 'http://127.0.0.1:8200', // default
  token: 'hv.xxxxxxxxxxxxxxxxxxxxx' // Optional incase of you want to initialize the vault
});

// Init vault
vc.init({ secret_shares: 1, secret_threshold: 1 }).then((res) => {
  const { keys, root_token } = res;
  vc.token = root_token;
  // Unseal vault
  vc.unseal({ secret_shares: 1, key: keys[0] });
});
Write, read and delete secrets
vc.write({ path: 'secret/hello', data: { foo: 'bar' } }).then(async () => {
  const data = await vc.read({ path: 'secret/hello' });
  console.log(data); // { data: { foo: 'bar' }, ... }
  await vc.delete({ path: 'secret/hello' });
});

Docs

Examples

Custom command implementation
import { generateCommand } from '@litehex/node-vault';
import { z } from 'zod';

const status = generateCommand({
  path: '/sys/seal-status',
  method: 'GET',
  client: vc,
  // refine: change the request before sending
  refine: (req) => {
    req.headers['X-Custom-Header'] = 'value';
    return req;
  },
  schema: {
    // path: use this to fill the path template
    // searchParams
    // body: schema for request body
    response: z.any()
  }
});

status().then((res) => {
  console.log(res);
});
Using a proxy or having the ability to modify the outgoing request.
import { Client } from '@litehex/node-vault';
import { ProxyAgent } from 'undici';

const agent = new ProxyAgent('http://localhost:8080');

const vc = new Client({
  // ... other params
  request: {
    dispatcher: agent,
    headers: {
      'X-Custom-Header': 'value'
    }
  }
});

Credits

This project is inspired by kr1sp1n/node-vault, and thanks to the contributors for their efforts.

License

This project is licensed under the GPLv3 License - see the LICENSE file for details

node-vault's People

Contributors

shahradelahi avatar renovate[bot] avatar

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.