From b9420f098d32f766f7cf7913f1cfc72bd205e239 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 17 Jun 2023 10:12:44 -0700 Subject: [PATCH] Add ability to specific DOTENV_API_URL in .env.vault as a configuration --- src/vars.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/vars.ts b/src/vars.ts index d6d4d17..d4d0f1d 100644 --- a/src/vars.ts +++ b/src/vars.ts @@ -3,7 +3,8 @@ import {existsSync, readFileSync} from 'fs' export class Vars { get apiUrl(): string { - return process.env.DOTENV_API_URL || 'https://vault.dotenv.org' + // read from process.env first, then .env.vault configuration file first, then default + return process.env.DOTENV_API_URL || this.vaultParsed.DOTENV_API_URL || 'https://vault.dotenv.org' } get vaultFilename(): string { @@ -23,8 +24,12 @@ export class Vars { return 'DOTENV_VAULT' } + get vaultParsed(): Record { + return dotenv.configDotenv({path: vars.vaultFilename}).parsed || {} + } + get vaultValue(): string { - return (dotenv.configDotenv({path: vars.vaultFilename}).parsed || {})[vars.vaultKey] + return this.vaultParsed[vars.vaultKey] } get existingEnvVault(): boolean {