Comparing version 4.0.0 to 4.1.0
# bedrock ChangeLog | ||
## 4.1.0 - 2020-12-09 | ||
### Added | ||
- Implement `ensureConfigOverride` configuration setting. This feature provides | ||
a mechanism for modules and top level applications to require that certain | ||
configuration values are changed during startup. This is useful when a | ||
deployment must use a different configuration than the development settings | ||
to be valid. | ||
## 4.0.0 - 2020-12-07 | ||
@@ -4,0 +13,0 @@ |
@@ -13,2 +13,3 @@ /*! | ||
const events = require('./events'); | ||
const lodashGet = require('lodash.get'); | ||
const loggers = require('./loggers'); | ||
@@ -493,3 +494,21 @@ const path = require('path'); | ||
bedrockStarted = true; | ||
// snapshot the values of the fields that must be changed | ||
// during the `bedrock.configure` event | ||
let configOverrideSnapshot; | ||
if(config.ensureConfigOverride.enable) { | ||
configOverrideSnapshot = _snapshotOverrideFields({ | ||
config, | ||
fields: config.ensureConfigOverride.fields, | ||
}); | ||
} | ||
await events.emit('bedrock.configure'); | ||
// ensure that the values captured in the snapshot have been changed | ||
if(configOverrideSnapshot) { | ||
// throws on failure which will prevent application startup | ||
_ensureConfigOverride({config, configOverrideSnapshot}); | ||
} | ||
await events.emit('bedrock.admin.init'); | ||
@@ -615,1 +634,25 @@ // set process user | ||
} | ||
function _ensureConfigOverride({config, configOverrideSnapshot}) { | ||
const logger = loggers.get('app').child('bedrock/worker'); | ||
logger.debug('Verifying configuration overrides.'); | ||
for(const [key, value] of configOverrideSnapshot) { | ||
if(lodashGet(config, key) === value) { | ||
const error = new Error( | ||
`The config field "${key}" must be changed during the ` + | ||
'"bedrock.configuration" event.'); | ||
logger.error(error); | ||
throw error; | ||
} | ||
} | ||
logger.debug('Configuration overrides have been verified.', { | ||
fields: [...configOverrideSnapshot.keys()]}); | ||
} | ||
function _snapshotOverrideFields({config, fields}) { | ||
const snapshot = new Map(); | ||
for(const field of fields) { | ||
snapshot.set(field, lodashGet(config, field)); | ||
} | ||
return snapshot; | ||
} |
@@ -59,2 +59,8 @@ /*! | ||
config.ensureConfigOverride = {}; | ||
// enable this feature when configuration overrides must occur during startup | ||
config.ensureConfigOverride.enable = false; | ||
// an array of path strings (e.g. 'mongodb.host', 'session-mongodb.ttl') | ||
config.ensureConfigOverride.fields = []; | ||
/* logging options | ||
@@ -61,0 +67,0 @@ * formatter options: |
{ | ||
"name": "bedrock", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "A core foundation for rich Web applications.", | ||
@@ -5,0 +5,0 @@ "license": "SEE LICENSE IN LICENSE.md", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
150217
2256