-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# [1.7.0](v1.6.0...v1.7.0) (2024-06-15) ### Features * **deps:** bump @vercel/ncc from 0.38.0 to 0.38.1 ([482bf52](482bf52)) * **deps:** bump braces from 3.0.2 to 3.0.3 ([575fa01](575fa01)) * **deps:** bump dotenv from 16.3.1 to 16.3.2 ([1e934d1](1e934d1)) * **deps:** bump dotenv from 16.3.2 to 16.4.1 ([59d7a52](59d7a52)) * **deps:** bump dotenv from 16.4.1 to 16.4.4 ([d72d999](d72d999)) * **deps:** bump dotenv from 16.4.4 to 16.4.5 ([6dce75a](6dce75a)) * **deps:** bump express from 4.18.2 to 4.18.3 ([d573c53](d573c53)) * **deps:** bump express from 4.18.3 to 4.19.1 ([6b9b862](6b9b862)) * **deps:** bump express from 4.19.1 to 4.19.2 ([2d542da](2d542da))
- Loading branch information
1 parent
575fa01
commit 3a0b75f
Showing
3 changed files
with
106 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1875,11 +1875,13 @@ function _parseVault (options) { | |
// Parse .env.vault | ||
const result = DotenvModule.configDotenv({ path: vaultPath }) | ||
if (!result.parsed) { | ||
throw new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`) | ||
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`) | ||
err.code = 'MISSING_DATA' | ||
throw err | ||
} | ||
|
||
// handle scenario for comma separated keys - for use with key rotation | ||
// example: DOTENV_KEY="dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenv.org/vault/.env.vault?environment=prod" | ||
// example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod" | ||
const keys = _dotenvKey(options).split(',') | ||
const length = keys.length | ||
|
||
|
@@ -1943,7 +1945,9 @@ function _instructions (result, dotenvKey) { | |
uri = new URL(dotenvKey) | ||
} catch (error) { | ||
if (error.code === 'ERR_INVALID_URL') { | ||
throw new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:[email protected]/vault/.env.vault?environment=development') | ||
const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:[email protected]/vault/.env.vault?environment=development') | ||
err.code = 'INVALID_DOTENV_KEY' | ||
throw err | ||
} | ||
|
||
throw error | ||
|
@@ -1952,34 +1956,53 @@ function _instructions (result, dotenvKey) { | |
// Get decrypt key | ||
const key = uri.password | ||
if (!key) { | ||
throw new Error('INVALID_DOTENV_KEY: Missing key part') | ||
const err = new Error('INVALID_DOTENV_KEY: Missing key part') | ||
err.code = 'INVALID_DOTENV_KEY' | ||
throw err | ||
} | ||
|
||
// Get environment | ||
const environment = uri.searchParams.get('environment') | ||
if (!environment) { | ||
throw new Error('INVALID_DOTENV_KEY: Missing environment part') | ||
const err = new Error('INVALID_DOTENV_KEY: Missing environment part') | ||
err.code = 'INVALID_DOTENV_KEY' | ||
throw err | ||
} | ||
|
||
// Get ciphertext payload | ||
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}` | ||
const ciphertext = result.parsed[environmentKey] // DOTENV_VAULT_PRODUCTION | ||
if (!ciphertext) { | ||
throw new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`) | ||
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`) | ||
err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT' | ||
throw err | ||
} | ||
|
||
return { ciphertext, key } | ||
} | ||
|
||
function _vaultPath (options) { | ||
let dotenvPath = path.resolve(process.cwd(), '.env') | ||
let possibleVaultPath = null | ||
|
||
if (options && options.path && options.path.length > 0) { | ||
dotenvPath = options.path | ||
if (Array.isArray(options.path)) { | ||
for (const filepath of options.path) { | ||
if (fs.existsSync(filepath)) { | ||
possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault` | ||
} | ||
} | ||
} else { | ||
possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault` | ||
} | ||
} else { | ||
possibleVaultPath = path.resolve(process.cwd(), '.env.vault') | ||
} | ||
|
||
// Locate .env.vault | ||
return dotenvPath.endsWith('.vault') ? dotenvPath : `${dotenvPath}.vault` | ||
if (fs.existsSync(possibleVaultPath)) { | ||
return possibleVaultPath | ||
} | ||
|
||
return null | ||
} | ||
|
||
function _resolveHome (envPath) { | ||
|
@@ -2002,51 +2025,73 @@ function _configVault (options) { | |
} | ||
|
||
function configDotenv (options) { | ||
let dotenvPath = path.resolve(process.cwd(), '.env') | ||
const dotenvPath = path.resolve(process.cwd(), '.env') | ||
let encoding = 'utf8' | ||
const debug = Boolean(options && options.debug) | ||
|
||
if (options) { | ||
if (options.path != null) { | ||
dotenvPath = _resolveHome(options.path) | ||
if (options && options.encoding) { | ||
encoding = options.encoding | ||
} else { | ||
if (debug) { | ||
_debug('No encoding is specified. UTF-8 is used by default') | ||
} | ||
if (options.encoding != null) { | ||
encoding = options.encoding | ||
} | ||
|
||
let optionPaths = [dotenvPath] // default, look for .env | ||
if (options && options.path) { | ||
if (!Array.isArray(options.path)) { | ||
optionPaths = [_resolveHome(options.path)] | ||
} else { | ||
optionPaths = [] // reset default | ||
for (const filepath of options.path) { | ||
optionPaths.push(_resolveHome(filepath)) | ||
} | ||
} | ||
} | ||
|
||
try { | ||
// Specifying an encoding returns a string instead of a buffer | ||
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding })) | ||
// Build the parsed data in a temporary object (because we need to return it). Once we have the final | ||
// parsed data, we will combine it with process.env (or options.processEnv if provided). | ||
let lastError | ||
const parsedAll = {} | ||
for (const path of optionPaths) { | ||
try { | ||
// Specifying an encoding returns a string instead of a buffer | ||
const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding })) | ||
|
||
let processEnv = process.env | ||
if (options && options.processEnv != null) { | ||
processEnv = options.processEnv | ||
DotenvModule.populate(parsedAll, parsed, options) | ||
} catch (e) { | ||
if (debug) { | ||
_debug(`Failed to load ${path} ${e.message}`) | ||
} | ||
lastError = e | ||
} | ||
} | ||
|
||
DotenvModule.populate(processEnv, parsed, options) | ||
let processEnv = process.env | ||
if (options && options.processEnv != null) { | ||
processEnv = options.processEnv | ||
} | ||
|
||
return { parsed } | ||
} catch (e) { | ||
if (debug) { | ||
_debug(`Failed to load ${dotenvPath} ${e.message}`) | ||
} | ||
DotenvModule.populate(processEnv, parsedAll, options) | ||
|
||
return { error: e } | ||
if (lastError) { | ||
return { parsed: parsedAll, error: lastError } | ||
} else { | ||
return { parsed: parsedAll } | ||
} | ||
} | ||
|
||
// Populates process.env from .env file | ||
function config (options) { | ||
const vaultPath = _vaultPath(options) | ||
|
||
// fallback to original dotenv if DOTENV_KEY is not set | ||
if (_dotenvKey(options).length === 0) { | ||
return DotenvModule.configDotenv(options) | ||
} | ||
|
||
const vaultPath = _vaultPath(options) | ||
|
||
// dotenvKey exists but .env.vault file does not exist | ||
if (!fs.existsSync(vaultPath)) { | ||
if (!vaultPath) { | ||
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`) | ||
|
||
return DotenvModule.configDotenv(options) | ||
|
@@ -2059,9 +2104,9 @@ function decrypt (encrypted, keyStr) { | |
const key = Buffer.from(keyStr.slice(-64), 'hex') | ||
let ciphertext = Buffer.from(encrypted, 'base64') | ||
|
||
const nonce = ciphertext.slice(0, 12) | ||
const authTag = ciphertext.slice(-16) | ||
ciphertext = ciphertext.slice(12, -16) | ||
const nonce = ciphertext.subarray(0, 12) | ||
const authTag = ciphertext.subarray(-16) | ||
ciphertext = ciphertext.subarray(12, -16) | ||
|
||
try { | ||
const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce) | ||
|
@@ -2073,14 +2118,14 @@ function decrypt (encrypted, keyStr) { | |
const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data' | ||
|
||
if (isRange || invalidKeyLength) { | ||
const msg = 'INVALID_DOTENV_KEY: It must be 64 characters long (or more)' | ||
throw new Error(msg) | ||
const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)') | ||
err.code = 'INVALID_DOTENV_KEY' | ||
throw err | ||
} else if (decryptionFailed) { | ||
const msg = 'DECRYPTION_FAILED: Please check your DOTENV_KEY' | ||
throw new Error(msg) | ||
const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY') | ||
err.code = 'DECRYPTION_FAILED' | ||
throw err | ||
} else { | ||
console.error('Error: ', error.code) | ||
console.error('Error: ', error.message) | ||
throw error | ||
} | ||
} | ||
|
@@ -2092,7 +2137,9 @@ function populate (processEnv, parsed, options = {}) { | |
const override = Boolean(options && options.override) | ||
|
||
if (typeof parsed !== 'object') { | ||
throw new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate') | ||
const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate') | ||
err.code = 'OBJECT_REQUIRED' | ||
throw err | ||
} | ||
|
||
// Set process.env | ||
|
@@ -7959,7 +8006,7 @@ return new B(c,{type:"multipart/form-data; boundary="+b})} | |
/***/ 9968: | ||
/***/ ((module) => { | ||
|
||
module.exports = JSON.parse('{"name":"dotenv","version":"16.3.1","description":"Loads environment variables from .env file","main":"lib/main.js","types":"lib/main.d.ts","exports":{".":{"types":"./lib/main.d.ts","require":"./lib/main.js","default":"./lib/main.js"},"./config":"./config.js","./config.js":"./config.js","./lib/env-options":"./lib/env-options.js","./lib/env-options.js":"./lib/env-options.js","./lib/cli-options":"./lib/cli-options.js","./lib/cli-options.js":"./lib/cli-options.js","./package.json":"./package.json"},"scripts":{"dts-check":"tsc --project tests/types/tsconfig.json","lint":"standard","lint-readme":"standard-markdown","pretest":"npm run lint && npm run dts-check","test":"tap tests/*.js --100 -Rspec","prerelease":"npm test","release":"standard-version"},"repository":{"type":"git","url":"git://github.com/motdotla/dotenv.git"},"funding":"https://github.com/motdotla/dotenv?sponsor=1","keywords":["dotenv","env",".env","environment","variables","config","settings"],"readmeFilename":"README.md","license":"BSD-2-Clause","devDependencies":{"@definitelytyped/dtslint":"^0.0.133","@types/node":"^18.11.3","decache":"^4.6.1","sinon":"^14.0.1","standard":"^17.0.0","standard-markdown":"^7.1.0","standard-version":"^9.5.0","tap":"^16.3.0","tar":"^6.1.11","typescript":"^4.8.4"},"engines":{"node":">=12"},"browser":{"fs":false}}'); | ||
module.exports = JSON.parse('{"name":"dotenv","version":"16.4.5","description":"Loads environment variables from .env file","main":"lib/main.js","types":"lib/main.d.ts","exports":{".":{"types":"./lib/main.d.ts","require":"./lib/main.js","default":"./lib/main.js"},"./config":"./config.js","./config.js":"./config.js","./lib/env-options":"./lib/env-options.js","./lib/env-options.js":"./lib/env-options.js","./lib/cli-options":"./lib/cli-options.js","./lib/cli-options.js":"./lib/cli-options.js","./package.json":"./package.json"},"scripts":{"dts-check":"tsc --project tests/types/tsconfig.json","lint":"standard","lint-readme":"standard-markdown","pretest":"npm run lint && npm run dts-check","test":"tap tests/*.js --100 -Rspec","test:coverage":"tap --coverage-report=lcov","prerelease":"npm test","release":"standard-version"},"repository":{"type":"git","url":"git://github.com/motdotla/dotenv.git"},"funding":"https://dotenvx.com","keywords":["dotenv","env",".env","environment","variables","config","settings"],"readmeFilename":"README.md","license":"BSD-2-Clause","devDependencies":{"@definitelytyped/dtslint":"^0.0.133","@types/node":"^18.11.3","decache":"^4.6.1","sinon":"^14.0.1","standard":"^17.0.0","standard-markdown":"^7.1.0","standard-version":"^9.5.0","tap":"^16.3.0","tar":"^6.1.11","typescript":"^4.8.4"},"engines":{"node":">=12"},"browser":{"fs":false}}'); | ||
|
||
/***/ }) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters