Skip to content

Commit 0ca5e6c

Browse files
author
Kyle Hayes
committed
feat: support for labels
- Adding support for labels - Mixing in process.env for Azure loadFromAzure
1 parent b47d650 commit 0ca5e6c

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dotenv-azure",
3-
"version": "2.0.5",
3+
"version": "2.0.0",
44
"description": "Load environment variables from Azure's services App Configuration, Key Vault or a .env file",
55
"keywords": [
66
"azure",

src/dotenv-azure.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ export default class DotenvAzure {
6060
async config(options: DotenvAzureConfigOptions = {}): Promise<DotenvAzureConfigOutput> {
6161
const { safe = false } = options
6262
const dotenvResult = dotenv.config(options)
63-
const vars:Record<string, string | undefined> = {...(dotenvResult.parsed || {}), ...process.env}
63+
const vars: Record<string, string | undefined> = {
64+
...(dotenvResult.parsed || {}),
65+
...process.env,
66+
}
6467
const azureVars = await this.loadFromAzure(vars)
6568
const joinedVars = { ...azureVars, ...dotenvResult.parsed }
6669

@@ -97,7 +100,6 @@ export default class DotenvAzure {
97100
* @returns an object with keys and values
98101
*/
99102
async loadFromAzure(dotenvVars?: Record<string, string | undefined>): Promise<VariablesObject> {
100-
// const vars = {...dotenvVars, ...process.env}
101103
const credentials = this.getAzureCredentials(dotenvVars)
102104
const appConfigClient = new AppConfigurationClient(credentials.connectionString)
103105
const labels = dotenvVars?.AZURE_APP_CONFIG_LABELS || ''
@@ -202,8 +204,7 @@ export default class DotenvAzure {
202204
)
203205
}
204206

205-
private getAzureCredentials(dotenvVars: Record<string, string | undefined> = {}): AzureCredentials {
206-
const vars = { ...dotenvVars, ...process.env }
207+
private getAzureCredentials(vars: Record<string, string | undefined> = {}): AzureCredentials {
207208
const connectionString = this.connectionString || vars.AZURE_APP_CONFIG_CONNECTION_STRING
208209

209210
if (!connectionString) {

test/azure.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const appConfigListMock = jest.fn(() =>
1818
isReadOnly: false,
1919
key: 'APP_CONFIG_VAR',
2020
value: 'ok',
21+
label: 'the-label',
2122
},
2223
{
2324
isReadOnly: true,

test/dotenv-azure.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const mockReadFileSync = readFileSync as jest.Mock
1919
describe('DotenvAzure', () => {
2020
const OLD_ENV = process.env
2121
const AZURE_APP_CONFIG_CONNECTION_STRING = 'app-config-conneciton-string'
22+
const AZURE_APP_CONFIG_LABELS = 'app-config-labels'
2223
const AZURE_TENANT_ID = 'tenant-id'
2324
const AZURE_CLIENT_ID = 'client-id'
2425
const AZURE_CLIENT_SECRET = 'client-secret'
@@ -44,6 +45,12 @@ describe('DotenvAzure', () => {
4445
expect(await dotenvAzure.config()).toBeDefined()
4546
})
4647

48+
it('does not throw when AZURE_APP_CONFIG_LABELS is defined', async () => {
49+
process.env = { ...OLD_ENV, AZURE_APP_CONFIG_CONNECTION_STRING, AZURE_APP_CONFIG_LABELS }
50+
const dotenvAzure = new DotenvAzure()
51+
expect(await dotenvAzure.config()).toBeDefined()
52+
})
53+
4754
it('throws when AZURE_APP_CONFIG_URL and AZURE_APP_CONFIG_CONNECTION_STRING are not defined', () => {
4855
const dotenvAzure = new DotenvAzure()
4956
expect(dotenvAzure.config()).rejects.toThrowError(MissingAppConfigCredentialsError)

0 commit comments

Comments
 (0)