@avanio/variable-util-azurekv
v0.10.0
Published
azure key vault variables
Downloads
24
Readme
variable-util-node
Azure keyvault loader for @avanio/variable-util-azurekv
install
npm i @avanio/variable-util @avanio/variable-util-azurekv --save
Examples
setLogger(console); // or log4js or winston
// Azure KV loader
const credentials = new ClientSecretCredential(tenantId, clientId, clientSecret); // or any other Azure credentials (managed identity, etc.)
const kvEnv = new AzureSecretsConfigLoader(async () => ({credentials, url: `${process.env.KV_URI}`})).getLoader;
const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader;
// parser instaces
const urlParser = new UrlParser({urlSanitize: true}); // urlSanitize hides credentials from logs
// lookup from: env process.env.DATABASE_URI => JSON file "settings.json" DATABASE_URI key => keyvault process.env.KV_URI name "zz-yy-database"
const databaseUrl: URL = await getConfigVariable('DATABASE_URI', [env(), fileEnv(), kvEnv('zz-yy-database')], urlParser, new URL('db://localhost'), {
showValue: true,
});
new AzureSecretsConfigLoader(options).getLoader: IConfigLoader
A IConfigLoader instance that loads configuration values from Azure Keyvault secrets.
Note: getLoader is function generator which can override key we are looking for example, kvEnv() with default key or kvEnv('OVERRIDE_KEY')
- options.credentials (required):
TokenCredential
. - options.url (required):
string
of Azure Keyvault URL. - options.disabled (optional):
boolean
to disable this loader. - options.isSilent (optional):
boolean
to hide error messages. (default: true)