kazana-config
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -15,3 +15,3 @@ #!/usr/bin/env node | ||
exec('git remote set-url origin ' + url.format(repo)) | ||
exec('git config user.email gregor.martynus@ehealthnigeria.org') | ||
exec('git config user.email oss@ehealthafrica.org') | ||
exec('git config user.name "eHealth Bot"') |
62
index.js
module.exports = getConfig | ||
var _ = require('lodash') | ||
var log = require('npmlog') | ||
module.exports.rc = require('rc') | ||
@@ -8,2 +9,4 @@ | ||
var getPluginDefaults = require('./lib/get-plugin-defaults') | ||
var parseManifestConfig = require('./lib/parse-manifest-config') | ||
var parseRcConfig = require('./lib/parse-rc-config') | ||
@@ -19,6 +22,59 @@ /** | ||
function getConfig (main) { | ||
var plugins = getPluginDefaults(main) | ||
_.merge(defaults, main.config, {plugin: plugins}) | ||
var rcConfig = parseRcConfig(module.exports.rc('kazana')) | ||
var mainConfig = parseManifestConfig(main) | ||
var pluginSettings = getPluginDefaults(main) | ||
var allowedNamespaces = ['kazana', main.name].concat(Object.keys(pluginSettings)) | ||
return module.exports.rc('kazana', defaults) | ||
// @deprecated | ||
// https://github.com/eHealthAfrica/kazana-config/pull/42 | ||
// istanbul ignore if | ||
if (_.difference(Object.keys(rcConfig), allowedNamespaces).length) { | ||
var rcNamespaceNames = allowedNamespaces.map(function (name) { | ||
return '[' + name + ']' | ||
}).join(', ') | ||
log.warn('deprecation', '.kazanarc: settings must be prefixed by one of: %s', rcNamespaceNames, { | ||
issue: 'https://github.com/eHealthAfrica/kazana-config/pull/42' | ||
}) | ||
rcConfig = { | ||
kazana: rcConfig | ||
} | ||
} | ||
var config = _.defaultsDeep({}, rcConfig, mainConfig, pluginSettings, defaults) | ||
// @deprecated | ||
// https://github.com/eHealthAfrica/kazana-config/pull/42 | ||
config.plugin = {} | ||
Object.keys(pluginSettings).forEach(function (key) { | ||
config.plugin[key] = pluginSettings[key] | ||
}) | ||
Object.keys(config.kazana).forEach(function (key) { | ||
// istanbul ignore if | ||
if (config.hasOwnProperty(key)) { | ||
log.warn('config', | ||
'config[%s] (was: %s) overwritten by config.kazana[%s] (value: %s)', | ||
key, | ||
config[key], | ||
key, | ||
config.kazana[key] | ||
) | ||
} | ||
config[key] = config.kazana[key] | ||
}) | ||
Object.keys(config[main.name] || {}).forEach(function (key) { | ||
// istanbul ignore if | ||
if (config.hasOwnProperty(key)) { | ||
log.warn('config', | ||
'config[%s] (was: %s) overwritten by config.kazana[%s][%s] (value: %s)', | ||
key, | ||
config[key], | ||
main.name, | ||
key, | ||
config.kazana[key] | ||
) | ||
} | ||
config[key] = config[main.name][key] | ||
}) | ||
return config | ||
} |
module.exports = { | ||
port: 5000, | ||
admin: { | ||
username: 'kazana', | ||
password: 'secret' | ||
}, | ||
log: { | ||
level: 'warn' | ||
}, | ||
backend: { | ||
port: 4999, | ||
// When undefined, defaults to pouchdb-server\'s built-in "leveldown". | ||
// Can be set to "couchdb" or any levelup storage back-ends: | ||
// https://github.com/Level/levelup/wiki/Modules#storage-back-ends | ||
name: undefined, | ||
// location option as it gets passed to levelup https://github.com/Level/levelup#leveluplocation-options-callback | ||
// If backend.name="couchdb", set the couchdb url without credententials, e.g. "https://my.couch.com" | ||
location: './.db/', | ||
// Does not apply if backend.name="couchdb" | ||
kazana: { | ||
port: 5000, | ||
admin: { | ||
username: 'kazana', | ||
password: 'secret' | ||
}, | ||
log: { | ||
file: './.db/pouch.log', | ||
level: 'info' | ||
level: 'warn' | ||
}, | ||
// Does not apply if backend.name="couchdb" | ||
config: { | ||
file: './.db/config.json' | ||
backend: { | ||
port: 4999, | ||
// When undefined, defaults to pouchdb-server\'s built-in "leveldown". | ||
// Can be set to "couchdb" or any levelup storage back-ends: | ||
// https://github.com/Level/levelup/wiki/Modules#storage-back-ends | ||
name: undefined, | ||
// location option as it gets passed to levelup https://github.com/Level/levelup#leveluplocation-options-callback | ||
// If backend.name="couchdb", set the couchdb url without credententials, e.g. "https://my.couch.com" | ||
location: './.db/', | ||
// Does not apply if backend.name="couchdb" | ||
log: { | ||
file: './.db/pouch.log', | ||
level: 'info' | ||
}, | ||
// Does not apply if backend.name="couchdb" | ||
config: { | ||
file: './.db/config.json' | ||
}, | ||
// timeout to connect to database | ||
timeout: 30000 | ||
}, | ||
// timeout to connect to database | ||
timeout: 30000 | ||
}, | ||
// database names | ||
db: { | ||
rawData: 'kazana-raw-data', | ||
integratedData: 'kazana-integrated-data', | ||
options: { | ||
timeout: 10000 | ||
// database names | ||
db: { | ||
rawData: 'kazana-raw-data', | ||
integratedData: 'kazana-integrated-data', | ||
options: { | ||
timeout: 10000 | ||
} | ||
}, | ||
// nodemailer configuration, see | ||
// https://www.npmjs.com/package/nodemailer | ||
email: { | ||
service: 'gmail', | ||
auth: { | ||
username: undefined, | ||
password: undefined | ||
} | ||
} | ||
}, | ||
// nodemailer configuration, see | ||
// https://www.npmjs.com/package/nodemailer | ||
email: { | ||
service: 'gmail', | ||
auth: { | ||
username: undefined, | ||
password: undefined | ||
} | ||
}, | ||
plugin: {} | ||
} | ||
} |
@@ -5,8 +5,10 @@ module.exports = getPluginDefaults | ||
var parseManifestConfig = require('./parse-manifest-config') | ||
function getPluginDefaults (plugin) { | ||
if (!plugin.plugins) return | ||
if (!plugin.plugins) return {} | ||
return plugin.plugins.reduce(function (map, plugin) { | ||
if (plugin.config) { | ||
map[plugin.name] = plugin.config | ||
_.merge(map, parseManifestConfig(plugin)) | ||
} | ||
@@ -13,0 +15,0 @@ _.merge(map, getPluginDefaults(plugin)) |
@@ -6,2 +6,3 @@ { | ||
"scripts": { | ||
"coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"deploydocs": "gh-pages-deploy", | ||
@@ -11,8 +12,6 @@ "docs": "doxx --source ./ --target docs --ignore coverage,bin,node_modules,tests", | ||
"predocs": "rimraf docs/build", | ||
"test": "standard && npm run test:node | tap-spec", | ||
"test:coverage": "istanbul cover tests", | ||
"test:coverage:upload": "istanbul-coveralls", | ||
"test:node": "node tests", | ||
"pretest": "standard", | ||
"test": "nyc tap --no-cov tests/**/*-test.js", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"postsemantic-release": "bundle-bump-bot -u eHealthAfrica -r kazana-server" | ||
"postsemantic-release": "npm run coverage" | ||
}, | ||
@@ -36,2 +35,6 @@ "gh-pages-deploy": { | ||
"homepage": "https://github.com/eHealthAfrica/kazana-config", | ||
"engines": { | ||
"node": ">=4.2.0", | ||
"npm": ">=2.14.0" | ||
}, | ||
"dependencies": { | ||
@@ -42,14 +45,13 @@ "lodash": "^3.10.1", | ||
"devDependencies": { | ||
"bundle-bump-bot": "^1.1.0", | ||
"coveralls": "^2.11.4", | ||
"doxx": "^2.1.1", | ||
"gh-pages-deploy": "^0.3.0", | ||
"istanbul": "^0.4.0", | ||
"istanbul-coveralls": "^1.0.3", | ||
"rimraf": "^2.4.3", | ||
"glob": "^6.0.1", | ||
"nyc": "^4.0.1", | ||
"rimraf": "^2.4.4", | ||
"semantic-release": "^6.0.3", | ||
"standard": "^5.2.2", | ||
"tap-spec": "^4.1.0", | ||
"tape": "^4.2.1" | ||
"standard": "^5.4.1", | ||
"tap": "^2.2.1" | ||
}, | ||
"version": "5.3.0" | ||
"version": "5.4.0" | ||
} |
111
README.md
@@ -12,49 +12,57 @@ # kazana-config | ||
Kazana is configured using `.kazanarc` files, using the [rc package](https://www.npmjs.com/package/rc). | ||
Kazana apps can be configured in 4 ways | ||
```js | ||
module.exports = { | ||
name: 'myapp', | ||
version: '1.0.0' | ||
} | ||
``` | ||
1. `config: {}` setting in the app / plugin manifests | ||
When loaded as plugin, it's looking for a `[plugin.<name>]` section within the `.kazanarc` files. | ||
Additionally, default configuration can be passed: | ||
``` | ||
module.exports = { | ||
name: 'myApp', | ||
version: '1.0.0', | ||
config: { | ||
kazana: { | ||
admin: { | ||
password: 'supersecret' | ||
} | ||
}, | ||
myApp: { | ||
mySetting: 'value' | ||
} | ||
} | ||
} | ||
``` | ||
```js | ||
module.exports = { | ||
name: 'myapp', | ||
version: '1.0.0', | ||
config: { | ||
admin: { | ||
user: 'myadmin', | ||
password: 'secret' | ||
} | ||
} | ||
} | ||
``` | ||
2. `.kazanarc` files, using the [rc package](https://www.npmjs.com/package/rc). | ||
Configuration can be also passed ase environment varibales | ||
```ini | ||
[kazana.admin] | ||
password = supersecret | ||
[myApp] | ||
mySetting = value | ||
``` | ||
``` | ||
kazana_admin__password = 'supersecret' npm start | ||
``` | ||
3. Environment variables | ||
or as command line arguments | ||
``` | ||
kazana_kazana__admin__password='supersecret' kazana_myApp__mySetting=value npm start | ||
``` | ||
``` | ||
npm start -- --admin.password='supersecret' | ||
``` | ||
4. command line arguments | ||
See https://www.npmjs.com/package/rc#standards for the full list | ||
and order of configuration sources. | ||
``` | ||
npm start -- --kazana.admin.password='supersecret' | ||
``` | ||
Within services, the settings are available as `server.settings.app.<setting path>`, | ||
for example `server.settings.app.admin.password` | ||
See https://www.npmjs.com/package/rc#standards for more details on how | ||
configuration is retrieved, and it what order. | ||
The settings become available as `server.settings.app.<setting path>` within | ||
the app and the plugins, for example `server.settings.app.kazana.admin.password` | ||
or `server.settings.app.config.myApp.mySetting` | ||
## Kazana Settings | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Setting Path</th> | ||
<th aling=left>Setting Path</th> | ||
<th>Default / Example</th> | ||
@@ -66,3 +74,3 @@ </tr> | ||
<td> | ||
<strong>port</strong> | ||
<strong>kazana.port</strong> | ||
</td> | ||
@@ -73,3 +81,3 @@ <td><code>5000</code></td> | ||
<td> | ||
<strong>log.level</strong> | ||
<strong>kazana.log.level</strong> | ||
</td> | ||
@@ -80,3 +88,3 @@ <td><code>warn</code></td> | ||
<td> | ||
<strong>admin.username</strong><br> | ||
<strong>kazana.admin.username</strong><br> | ||
Database admin username | ||
@@ -88,3 +96,3 @@ </td> | ||
<td> | ||
<strong>admin.password</strong><br> | ||
<strong>kazana.admin.password</strong><br> | ||
Database admin password | ||
@@ -96,3 +104,3 @@ </td> | ||
<td> | ||
<strong>backend.name</strong><br> | ||
<strong>kazana.backend.name</strong><br> | ||
When undefined, defaults to pouchdb-server's built-in "leveldown". Can be set to "couchdb" or any levelup storage back-ends: https://github.com/Level/levelup/wiki/Modules#storage-back-ends | ||
@@ -104,3 +112,3 @@ </td> | ||
<td> | ||
<strong>backend.port</strong> | ||
<strong>kazana.backend.port</strong> | ||
</td> | ||
@@ -111,3 +119,3 @@ <td><code>4999</code></td> | ||
<td> | ||
<strong>backend.location</strong><br> | ||
<strong>kazana.backend.location</strong><br> | ||
Location option as it gets passed to levelup https://github.com/Level/levelup#leveluplocation-options-callback | ||
@@ -120,3 +128,3 @@ If backend.name="couchdb", set the couchdb url without credententials, e.g. "https://my.couch.com" | ||
<td> | ||
<strong>backend.log.file</strong><br> | ||
<strong>kazana.backend.log.file</strong><br> | ||
Does not apply if backend.name="couchdb" | ||
@@ -128,3 +136,3 @@ </td> | ||
<td> | ||
<strong>backend.log.level</strong><br> | ||
<strong>kazana.backend.log.level</strong><br> | ||
Does not apply if backend.name="couchdb" | ||
@@ -136,3 +144,3 @@ </td> | ||
<td> | ||
<strong>backend.config.file</strong><br> | ||
<strong>kazana.backend.config.file</strong><br> | ||
Does not apply if backend.name="couchdb" | ||
@@ -144,3 +152,3 @@ </td> | ||
<td> | ||
<strong>backend.timeout</strong><br> | ||
<strong>kazana.backend.timeout</strong><br> | ||
Time to connect database in milliseconds | ||
@@ -152,3 +160,3 @@ </td> | ||
<td> | ||
<strong>db.rawData</strong><br> | ||
<strong>kazana.db.rawData</strong><br> | ||
Name of database containing submitted raw data | ||
@@ -160,3 +168,3 @@ </td> | ||
<td> | ||
<strong>db.integratedData</strong><br> | ||
<strong>kazana.db.integratedData</strong><br> | ||
Name of database containing integrated data | ||
@@ -168,3 +176,3 @@ </td> | ||
<td> | ||
<strong>db.options</strong><br> | ||
<strong>kazana.db.options</strong><br> | ||
Database ajax options, as passed to the PouchDB constructor. | ||
@@ -176,3 +184,3 @@ </td> | ||
<td> | ||
<strong>email.service</strong><br> | ||
<strong>kazana.email.service</strong><br> | ||
Nodemailer Email Service | ||
@@ -184,3 +192,3 @@ </td> | ||
<td> | ||
<strong>email.auth.username</strong><br> | ||
<strong>kazana.email.auth.username</strong><br> | ||
Nodemailer Email Service Username | ||
@@ -192,3 +200,3 @@ </td> | ||
<td> | ||
<strong>email.auth.password</strong><br> | ||
<strong>kazana.email.auth.password</strong><br> | ||
Nodemailer Email Service Password | ||
@@ -201,3 +209,2 @@ </td> | ||
## Local setup and Testing | ||
@@ -204,0 +211,0 @@ |
@@ -1,2 +0,3 @@ | ||
require('./specs/defaults-test') | ||
require('./specs/plugins-test') | ||
require('./unit/defaults-test') | ||
require('./unit/plugins-test') | ||
require('./integration/integration-test') |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
67823
9
32
415
216
7
4