@hapic/vault
TypeScript icon, indicating that this package has built-in type declarations

2.3.3 • Public • Published

@hapic/vault 🔒

npm version main Known Vulnerabilities Conventional Commits

This client provides a convenient way to interact with various endpoints in Vault, such as secrets, engines, and more. Vault is a popular open-source tool used for securely storing and accessing sensitive data, such as passwords, API keys, and certificates. The client offers a range of abstractions to simplify interactions with Vault and streamline the development process. Whether you are a seasoned developer or new to the world of secrets management, this API client is a powerful tool to help you get the most out of Vault.

Table of Contents

Documentation

To read the docs, visit https://hapic.tada5hi.net

Installation

npm install @hapic/vault --save

Usage

Config

To create a configuration for the VaultClient, a configuration must be specified, like described in the following:

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    request: {
        credentials: 'include',
    },
    conenctionOptions: {
        host: 'https://example.com/api/v1/',
        token: 'xxx',
    },
    // connectionString: 'xxx@https://example.com/v1/'
});

KeyValue V1

Create

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.keyValueV1.create(
    'engine',
    'path',
    {
        foo: 'bar'
    }
);

GetOne

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

const data = await client.keyValueV1.getOne(
    'engine',
    'path',
);
console.log(data);
// { data: { foo: 'bar' }, lease_duration: 0, ... }

Delete

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.keyValueV1.delete(
    'engine',
    'path',
);

KeyValue V2

Create

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.keyValueV2.create(
    'engine',
    'path',
    {
        data: {
            foo: 'bar'
        }
    }
);

GetOne

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

const data = await client.keyValueV2.getOne('engine', 'path');
console.log(data);
// { data: { data: { foo: 'bar' }, ... } }

Update

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.keyValueV2.create(
    'engine',
    'path',
    {
        data: {
            baz: 'boz'
        }
    }
);

Delete

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.keyValueV2.delete('engine','path');

Save

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.keyValueV2.save(
    'engine',
    'path',
    {
        data: {
            foo: 'bar'
        }
    }
);

Mount

Create

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.mount.create(
    'engine',
    {
        type: 'kv',
        generate_signing_key: true
    }
);

GetMany

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

const data = await client.mount.getMany();
console.log(data);
// {
//      data: {
//          'engine/': {
//              type: 'kv',
//              uuid: 'xxx',
//           }
//       },
//       lease_duration: 0,
//       ...
// }

GetOne

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

const data = await client.mount.getOne('engine');
console.log(data);
// { data: { type: 'kv', uuid: 'xxx' }, lease_duration: 0, ... }

Delete

import { VaultClient } from '@hapic/vault';

const client = new VaultClient({
    // ...
});

await client.mount.delete('engine');

License

Made with 💚

Published under MIT License.

Readme

Keywords

Package Sidebar

Install

npm i @hapic/vault

Weekly Downloads

334

Version

2.3.3

License

MIT

Unpacked Size

83.4 kB

Total Files

30

Last publish

Collaborators

  • tada5hi