1.120.0 • Published 7 months ago

@biorate/config-loader-vault v1.120.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Vault config loader

Vault config loader

Features

  • Merge json data into config
  • Download files from vault

Examples

./vault.ts
import { init } from '@biorate/inversion';
import { VaultConnector as VaultConnectorBase } from '@biorate/vault';

export class VaultConnector extends VaultConnectorBase {
  @init() protected async initialize() {
    await super.initialize();
    await this.current!.write('secret/data/config.json', {
      data: { hello: 'world! (merge)' },
    });
    await this.current!.write('secret/data/files.json', {
      data: { 'hello.txt': 'world! (download)' },
    });
  }
}
./index.ts
import { promises as fs } from 'fs';
import { path } from '@biorate/tools';
import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { IVaultConnector } from '@biorate/vault';
import { VaultConnector } from './vault';
import { ConfigLoader } from '@biorate/config-loader';
import { ConfigLoaderVault } from '@biorate/config-loader-vault';

class Root extends Core() {
  @inject(Types.Config) public config: IConfig;
  @inject(Types.Vault) public vault: IVaultConnector;
  @inject(Types.ConfigLoaderVault) public configLoaderVault: ConfigLoader;
}

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container
  .bind<IVaultConnector>(Types.Vault)
  .to(VaultConnector)
  .inSingletonScope();
container.bind<ConfigLoader>(Types.ConfigLoaderVault).to(ConfigLoaderVault).inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

container.get<IConfig>(Types.Config).merge({
  Vault: [
    {
      name: 'connection',
      options: {
        apiVersion: 'v1',
        endpoint: 'http://localhost:8200',
        token: 'admin',
      },
    },
  ],
  ConfigLoaderVault: [
    {
      action: 'merge',
      path: 'secret/data/config.json',
      connection: 'connection',
      cache: true,
    },
    {
      action: 'download',
      path: 'secret/data/files.json',
      connection: 'connection',
      cache: true,
    },
  ],
});

(async () => {
  const root = container.get<Root>(Root);
  await root.$run();

  console.log(root.config.get('hello')); // world! (merge)

  const file = await fs.readFile(
    path.create(process.cwd(), 'keys', 'hello.txt'),
    'utf-8',
  )
  console.log(file); // world! (download)
})();

See

@biorate/config-loader docs for details

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)

1.98.1

9 months ago

1.98.0

9 months ago

1.96.0

11 months ago

1.90.0

12 months ago

1.120.0

7 months ago

1.95.1

11 months ago

1.91.5

12 months ago

1.95.0

11 months ago

1.91.4

12 months ago

1.93.1

11 months ago

1.91.3

12 months ago

1.93.0

11 months ago

1.91.2

12 months ago

1.91.1

12 months ago

1.91.0

12 months ago

1.100.0

9 months ago

1.104.0

9 months ago

1.102.0

9 months ago

1.102.1

9 months ago

1.76.3

1 year ago

1.65.4

2 years ago

1.54.0

2 years ago

1.38.2

2 years ago

1.38.3

2 years ago

1.38.1

2 years ago

1.38.4

2 years ago

1.42.2

2 years ago

1.43.0

2 years ago

1.42.1

2 years ago

1.30.12

2 years ago

1.29.0

3 years ago

1.28.1

3 years ago

1.28.0

3 years ago

1.30.0

2 years ago

1.30.1

2 years ago

1.26.0

3 years ago

1.27.2

3 years ago

1.27.0

3 years ago

1.27.1

3 years ago

1.24.0

3 years ago

1.22.1

3 years ago

1.21.2

3 years ago

1.22.7

3 years ago

1.20.1

3 years ago

1.11.2

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago