@platformatic/config
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -9,3 +9,3 @@ 'use strict' | ||
async function loadConfig (minimistConfig, _args, app, overrides = {}) { | ||
async function loadConfig (minimistConfig, _args, app, overrides = {}, replaceEnv = true) { | ||
const args = parseArgs(_args, deepmerge({ all: true })({ | ||
@@ -43,3 +43,3 @@ string: ['allow-env'], | ||
const parsingResult = await configManager.parse() | ||
const parsingResult = await configManager.parse(replaceEnv) | ||
if (!parsingResult) { | ||
@@ -46,0 +46,0 @@ const err = new errors.ConfigurationDoesNotValidateAgainstSchemaError() |
@@ -19,3 +19,8 @@ 'use strict' | ||
this.pupa = null | ||
this.envWhitelist = opts.envWhitelist || [] | ||
if (typeof this.envWhitelist === 'string') { | ||
this.envWhitelist = opts.envWhitelist.split(',') | ||
} | ||
if (!opts.source) { | ||
@@ -64,3 +69,3 @@ throw new errors.SourceMissingError() | ||
for (const key in env) { | ||
if (key.match(/^PLT_/) || this.envWhitelist.includes(key)) { | ||
if (this.#isEnvVariable(key)) { | ||
purged[key] = env[key] | ||
@@ -127,9 +132,26 @@ } | ||
/** | ||
* Checks if a key starts with `PLT_` or is in the whitelist. | ||
* With respect for wildcard ala `MY_NS_*` | ||
* @param {string} key | ||
*/ | ||
#isEnvVariable (key) { | ||
const isInWhitelist = this.envWhitelist.some((whitelisted) => | ||
(whitelisted.endsWith('*') && key.startsWith(whitelisted.slice(0, -1))) || whitelisted === key | ||
) | ||
return key.startsWith('PLT_') || isInWhitelist | ||
} | ||
_transformConfig () {} | ||
async parse () { | ||
async parse (replaceEnv = true) { | ||
try { | ||
if (this.fullPath) { | ||
const configString = await this.load() | ||
this.current = this._parser(await this.replaceEnv(configString)) | ||
if (replaceEnv) { | ||
this.current = this._parser(await this.replaceEnv(configString)) | ||
} else { | ||
this.current = this._parser(await this.load()) | ||
} | ||
// try updating the config format to latest | ||
@@ -167,4 +189,5 @@ try { | ||
} catch (err) { | ||
console.error(err) | ||
if (err.name === 'MissingValueError') { | ||
if (!err.key.match(/^PLT_/) && !this.envWhitelist.includes(err.key)) { | ||
if (!this.#isEnvVariable(err.key)) { | ||
throw new errors.InvalidPlaceholderError(err.key, err.key) | ||
@@ -171,0 +194,0 @@ } else { |
{ | ||
"name": "@platformatic/config", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "Platformatic DB Config Manager", | ||
@@ -35,4 +35,4 @@ "main": "index.js", | ||
"undici": "^5.25.4", | ||
"@platformatic/metaconfig": "1.11.0", | ||
"@platformatic/utils": "1.11.0" | ||
"@platformatic/metaconfig": "1.12.0", | ||
"@platformatic/utils": "1.12.0" | ||
}, | ||
@@ -39,0 +39,0 @@ "scripts": { |
35896
662
+ Added@platformatic/metaconfig@1.12.0(transitive)
+ Added@platformatic/utils@1.12.0(transitive)
- Removed@platformatic/metaconfig@1.11.0(transitive)
- Removed@platformatic/utils@1.11.0(transitive)
Updated@platformatic/utils@1.12.0