diff --git a/package-lock.json b/package-lock.json index e1ed44cb..3f0fb96f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dotenv-azure", - "version": "2.0.0", + "version": "2.0.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 394ad0c8..bf97fcaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dotenv-azure", - "version": "2.0.0", + "version": "2.0.5", "description": "Load environment variables from Azure's services App Configuration, Key Vault or a .env file", "keywords": [ "azure", diff --git a/src/dotenv-azure.ts b/src/dotenv-azure.ts index 0fa713c0..7e5aae66 100644 --- a/src/dotenv-azure.ts +++ b/src/dotenv-azure.ts @@ -1,7 +1,7 @@ import * as fs from 'fs' import { URL } from 'url' import Bottleneck from 'bottleneck' -import dotenv, { DotenvParseOptions, DotenvParseOutput } from 'dotenv' +import dotenv, { DotenvParseOptions } from 'dotenv' import { ManagedIdentityCredential, ClientSecretCredential } from '@azure/identity' import { SecretClient } from '@azure/keyvault-secrets' import { AppConfigurationClient, ConfigurationSetting } from '@azure/app-configuration' @@ -60,8 +60,8 @@ export default class DotenvAzure { async config(options: DotenvAzureConfigOptions = {}): Promise { const { safe = false } = options const dotenvResult = dotenv.config(options) - - const azureVars = await this.loadFromAzure(dotenvResult.parsed) + const vars:Record = {...(dotenvResult.parsed || {}), ...process.env} + const azureVars = await this.loadFromAzure(vars) const joinedVars = { ...azureVars, ...dotenvResult.parsed } populateProcessEnv(azureVars) @@ -96,7 +96,8 @@ export default class DotenvAzure { * @param dotenvVars - dotenv parse() output containing azure credentials variables * @returns an object with keys and values */ - async loadFromAzure(dotenvVars?: DotenvParseOutput): Promise { + async loadFromAzure(dotenvVars?: Record): Promise { + // const vars = {...dotenvVars, ...process.env} const credentials = this.getAzureCredentials(dotenvVars) const appConfigClient = new AppConfigurationClient(credentials.connectionString) const labels = dotenvVars?.AZURE_APP_CONFIG_LABELS || '' @@ -201,10 +202,10 @@ export default class DotenvAzure { ) } - private getAzureCredentials(dotenvVars: DotenvParseOutput = {}): AzureCredentials { + private getAzureCredentials(dotenvVars: Record = {}): AzureCredentials { const vars = { ...dotenvVars, ...process.env } const connectionString = this.connectionString || vars.AZURE_APP_CONFIG_CONNECTION_STRING - + if (!connectionString) { throw new MissingAppConfigCredentialsError() }