Socket
Socket
Sign inDemoInstall

@opuscapita/config

Package Overview
Dependencies
16
Maintainers
12
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.4 to 3.1.5-next.0

212

lib/ConfigClient.js

@@ -30,2 +30,3 @@ const ConfigClientBase = require('./ConfigClientBase');

*
* @param {object} config
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html}.

@@ -46,3 +47,3 @@ */

return Promise.resolve(this._init(initConf)).catch(e => { this.logger.error(e.message); throw e; });
return Promise.resolve(this._init(initConf)).catch(e => { this.logger.error(e.message, e); throw e; });
}

@@ -57,3 +58,3 @@

{
return Promise.resolve(this._dispose()).catch(e => { this.logger.error(e.message); throw e; });
return Promise.resolve(this._dispose()).catch(e => { this.logger.error(e.message, e); throw e; });
}

@@ -83,3 +84,3 @@

{
return key && /^([0-9a-zA-Z-]+\/?)+[0-9a-zA-Z-]+$/.test(this.getFullKey(key));
return key ? /^([0-9a-zA-Z-]+\/?)+[0-9a-zA-Z-]+$/.test(this.getFullKey(key)) : false;
}

@@ -99,3 +100,3 @@

{
return prefix && /^([0-9a-zA-Z-]+\/)+$/.test(prefix);
return prefix ? /^([0-9a-zA-Z-]+\/)+$/.test(prefix) : false;
}

@@ -110,4 +111,4 @@

{
const cipher = crypto.createCipheriv('aes-256-cbc', this.secret, '9f3663cc2e8a47dd');
return cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64');
const cipher = crypto.createCipheriv('aes-256-cbc', this.secret, '9f3663cc2e8a47dd');
return cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64');
}

@@ -122,4 +123,4 @@

{
const cipher = crypto.createDecipheriv('aes-256-cbc', this.secret, '9f3663cc2e8a47dd');
return JSON.parse(cipher.update(encrypted, 'base64', 'utf8') + cipher.final('utf8'));
const cipher = crypto.createDecipheriv('aes-256-cbc', this.secret, '9f3663cc2e8a47dd');
return JSON.parse(cipher.update(encrypted, 'base64', 'utf8') + cipher.final('utf8'));
}

@@ -140,30 +141,30 @@

* remote service capacity problems. For further details have a look at the [DefaultConfig]{@link DefaultConfig}.
* @param {string|array} keyOrPrefix - Key(s) to request. Can be either a single key string, a key-prefix, an array of keys or and array of key-prefixes. For using key-prefixes, the *recusrive* parameter has to be set to true. All keys an prefixes will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} recursive - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @param {string|string[]} keyOrPrefix - Key(s) to request. Can be either a single key string, a key-prefix, an array of keys or and array of key-prefixes. For using key-prefixes, the *recusrive* parameter has to be set to true. All keys an prefixes will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} [recursive] - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} [silent] - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html}.
*/
getProperty(keyOrPrefix, recursive, silent)
getProperty(keyOrPrefix, recursive = false, silent = false)
{
if(Array.isArray(keyOrPrefix))
return Promise.all(keyOrPrefix.map(k => this.getProperty(k, recursive, silent)));
if(Array.isArray(keyOrPrefix))
return Promise.all(keyOrPrefix.map(k => this.getProperty(k, recursive, silent)));
const keyName = this.getFullKey(keyOrPrefix);
const keyName = this.getFullKey(keyOrPrefix);
const isValidKey = !recursive && this.checkKey(keyOrPrefix);
const isValidPrefix = recursive && this.checkKeyPrefix(keyOrPrefix);
const isValidKey = !recursive && this.checkKey(keyOrPrefix);
const isValidPrefix = recursive && this.checkKeyPrefix(keyOrPrefix);
if(isValidKey || isValidPrefix)
{
const task = () => retry(() => this._getConsulValues(keyName, recursive), { max_tries : 5, interval : 500 });
if(isValidKey || isValidPrefix)
{
const task = () => retry(() => this._getConsulValues(keyName, recursive), { max_tries : 5, interval : 500 });
if(silent)
return task().catch(e => this.logger.warn(e));
else
return task();
}
else
{
return Promise.reject(new Error('The passed key or prefix is invalid: ' + keyOrPrefix));
}
if(silent)
return task().catch(e => this.logger.warn('Cannot get property', e));
else
return task();
}
else
{
return Promise.reject(new Error('The passed key or prefix is invalid: ' + keyOrPrefix));
}
}

@@ -179,6 +180,6 @@

{
if(this.checkKey(key))
return Promise.resolve(this._setConsulValue(this.getFullKey(key), value));
else
return Promise.reject(new Error('The passed key is invalid: ' + key));
if(this.checkKey(key))
return Promise.resolve(this._setConsulValue(this.getFullKey(key), value));
else
return Promise.reject(new Error('The passed key is invalid: ' + key));
}

@@ -188,30 +189,30 @@

* Removes a single value or a list of values from consul's key-value store.
* @param {string|array} keyOrPrefix - Key to remove. Will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} recursive - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @param {string|string[]} keyOrPrefix - Key to remove. Will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} [recursive] - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} [silent] - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html}.
*/
deleteProperty(keyOrPrefix, recursive, silent)
deleteProperty(keyOrPrefix, recursive = false, silent = false)
{
if(Array.isArray(keyOrPrefix))
return Promise.all(keyOrPrefix.map(k => this.deleteProperty(k, recursive)));
if(Array.isArray(keyOrPrefix))
return Promise.all(keyOrPrefix.map(k => this.deleteProperty(k, recursive)));
const keyName = this.getFullKey(keyOrPrefix);
const keyName = this.getFullKey(keyOrPrefix);
const isValidKey = !recursive && this.checkKey(keyOrPrefix);
const isValidPrefix = recursive && this.checkKeyPrefix(keyOrPrefix);
const isValidKey = !recursive && this.checkKey(keyOrPrefix);
const isValidPrefix = recursive && this.checkKeyPrefix(keyOrPrefix);
if(isValidKey || isValidPrefix)
{
const task = () => retry(() => this._deleteConsulValue(keyName, recursive), { max_tries : 5, interval : 500 });
if(isValidKey || isValidPrefix)
{
const task = () => retry(() => this._deleteConsulValue(keyName, recursive), { max_tries : 5, interval : 500 });
if(silent)
return task().catch(e => this.logger.warn(e));
else
return task();
}
else
{
return Promise.reject(new Error('The passed key or prefix is invalid: ' + keyOrPrefix));
}
if(silent)
return task().catch(e => this.logger.warn('Cannot delete property', e));
else
return task();
}
else
{
return Promise.reject(new Error('The passed key or prefix is invalid: ' + keyOrPrefix));
}
}

@@ -226,19 +227,19 @@

* remote service capacity problems. For further details have a look at the [DefaultConfig]{@link DefaultConfig}.
* @param {string} serviceName - Name of service to request.
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @param {string|string[]} serviceName - Name of service to request.
* @param {boolean} [silent] - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html} containing and [Endpoint]{@link module:@opuscapita/config~Endpoint} object.
*/
getEndPoint(serviceName, silent)
getEndPoint(serviceName, silent = false)
{
if(Array.isArray(serviceName))
return Promise.all(serviceName.map(k => this.getEndPoint(k, silent)));
if(Array.isArray(serviceName))
return Promise.all(serviceName.map(k => this.getEndPoint(k, silent)));
const task = () => this._getConsulEndpoint(serviceName);
const task = () => this._getConsulEndpoint(serviceName);
if(silent)
return task().catch(e => this.logger.warn(e));
else
return retry(task, { max_tries: this.config.retryCount, interval: this.config.retryTimeout })
.catch(e => { this.logger.warn(e); throw e; });
if(silent)
return task().catch(e => this.logger.warn('Cannot get endpoint', e));
else
return retry(task, { max_tries: this.config.retryCount, interval: this.config.retryTimeout })
.catch(e => { this.logger.warn('Cannot get endpoint', e); throw e; });
}

@@ -253,19 +254,19 @@

* remote service capacity problems. For further details have a look at the [DefaultConfig]{@link DefaultConfig}.
* @param {string} serviceName - Name of service to request.
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @param {string|string[]} serviceName - Name of service to request.
* @param {boolean} [silent] - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html} containing an array of [Endpoint]{@link module:@opuscapita/config~Endpoint} objects.
*/
getEndPoints(serviceName, silent)
getEndPoints(serviceName, silent = false)
{
if(Array.isArray(serviceName))
return Promise.all(serviceName.map(k => this.getEndPoints(k, silent)));
if(Array.isArray(serviceName))
return Promise.all(serviceName.map(k => this.getEndPoints(k, silent)));
const task = () => this._getConsulEndpoints(serviceName);
const task = () => this._getConsulEndpoints(serviceName);
if(silent)
return task().catch(e => { this.logger.warn(e); return [ ]; });
else
return retry(task, { max_tries: this.config.retryCount, interval: this.config.retryTimeout })
.catch(e => { this.logger.warn(e); throw e; });
if(silent)
return task().catch(e => { this.logger.warn('Cannot get endpoints', e); return [ ]; });
else
return retry(task, { max_tries: this.config.retryCount, interval: this.config.retryTimeout })
.catch(e => { this.logger.warn('Cannot get endpoint', e); throw e; });
}

@@ -286,8 +287,9 @@

* remote service capacity problems. For further details have a look at the [DefaultConfig]{@link DefaultConfig}.
* @param {mixed} keyOrPrefix - Key(s) to request. Can be either a single key string, a key-prefix, an array of keys or and array of key-prefixes. For using key-prefixes, the *recusrive* parameter has to be set to true. All keys an prefixes will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} recursive - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @deprecated since v3.1.5 - use getProperty instead
* @param {string|string[]} keyOrPrefix - Key(s) to request. Can be either a single key string, a key-prefix, an array of keys or and array of key-prefixes. For using key-prefixes, the *recusrive* parameter has to be set to true. All keys an prefixes will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} [recursive] - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} [silent] - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html}.
*/
get(keyOrPrefix, recursive, silent)
get(keyOrPrefix, recursive = false, silent = false)
{

@@ -299,2 +301,3 @@ return this.getProperty(keyOrPrefix, recursive, silent);

* Sets a value to consul's key-value store. Alias for [setProperty()]{@link setProperty}.
* @deprecated since v3.1.5 - use setProperty instead
* @param {string} key - Key to set. Will automatically get prefixed with [serviceName]{@link serviceName}.

@@ -311,10 +314,11 @@ * @param {object} value - Value to set.

* Removes a value from consul's key-value store. Alias for [deleteProperty()]{@link deleteProperty}.
* @deprecated since v3.1.5 - use deleteProperty instead
* @param {string} key - Key to remove. Will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} recursive - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @param {boolean} [recursive] - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} [silent] - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html}.
*/
delete(keyOrPrefix, recursive, silent)
delete(key, recursive = false, silent = false)
{
return this.deleteProperty(keyOrPrefix, recursive);
return this.deleteProperty(key, recursive, silent);
}

@@ -326,16 +330,16 @@

* remote service capacity problems. For further details have a look at the [DefaultConfig]{@link DefaultConfig}.
* @param {mixed} keyOrPrefix - Key(s) to request. Can be either a single key string, a key-prefix, an array of keys or and array of key-prefixes. For using key-prefixes, the *recusrive* parameter has to be set to true. All keys an prefixes will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} recursive - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @param {string|string[]} keyOrPrefix - Key(s) to request. Can be either a single key string, a key-prefix, an array of keys or and array of key-prefixes. For using key-prefixes, the *recusrive* parameter has to be set to true. All keys an prefixes will automatically get prefixed with [serviceName]{@link serviceName}.
* @param {boolean} [recursive] - If set to true, the *keyOrPrefix* parameter is used as key-prefix to recursively list all keys below this prefix.
* @param {boolean} [silent] - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html}.
*/
getPassword(keyOrPrefix, recursive, silent)
getPassword(keyOrPrefix, recursive = false, silent = false)
{
return this.get(keyOrPrefix, recursive, silent).then(values =>
{
if(Array.isArray(keyOrPrefix) || recursive)
return Object.keys(values).reduce((all, key) => { all[key] = this.decryptData(values[key]); return all }, { });
return this.get(keyOrPrefix, recursive, silent).then(values =>
{
if(Array.isArray(keyOrPrefix) || recursive)
return Object.keys(values).reduce((all, key) => { all[key] = this.decryptData(values[key]); return all }, { });
return this.decryptData(values);
});
return this.decryptData(values);
});
}

@@ -351,4 +355,4 @@

{
const encrypted = this.encryptData(value);
return this.set(key, encrypted);
const encrypted = this.encryptData(value);
return this.set(key, encrypted);
};

@@ -360,4 +364,4 @@

*
* @param {string|array} serviceNames - A single service name or an array of service names to wait for.
* @param {number?} timeout - The maximum time in milliseconds to wait for the requested services to be available.
* @param {string|string[]} serviceNames - A single service name or an array of service names to wait for.
* @param {number} [timeout] - The maximum time in milliseconds to wait for the requested services to be available.
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html} that gets rejected with an error if the passed timeout is reached.

@@ -367,3 +371,3 @@ */

{
return retry(() => this.getEndPoint(serviceNames).then(() => true), { interval : 500, backOff : 1.2, max_interval : timeout, max_tries : Number.MAX_SAFE_INTEGER, timeout : timeout });
return retry(() => this.getEndPoint(serviceNames, false).then(() => true), { interval : 500, backOff : 1.2, max_interval : timeout, max_tries : Number.MAX_SAFE_INTEGER, timeout : timeout });
}

@@ -383,10 +387,10 @@ }

ConfigClient.DefaultConfig = {
host : 'consul',
port : 8500,
retryCount : 50,
retryTimeout : 1000,
host : 'consul',
port : 8500,
retryCount : 50,
retryTimeout : 1000,
logger : null,
serviceSecretPath : `/run/secrets/${ConfigClientBase.serviceName}-consul-key`
serviceSecretPath : `/run/secrets/${ConfigClientBase.serviceName}-consul-key`
}
module.exports = ConfigClient;

@@ -53,5 +53,5 @@ const EventEmitter = require('events');

this.cache = cache;
this.epWatches = { };
this.keyWatches = { };
this.knownKeys = { };
this.epWatches = {};
this.keyWatches = {};
this.knownKeys = {};

@@ -93,5 +93,5 @@ const [ secret, consul ] = await Promise.all([

this.epWatches = { };
this.keyWatches = { };
this.knownKeys = { };
this.epWatches = {};
this.keyWatches = {};
this.knownKeys = {};

@@ -105,9 +105,9 @@ this.secret = null;

{
this.logger.info('Connecting to consul service: %s:%s', host, port);
this.logger.info('Connecting to consul', {host, port});
const connection = consul({
host : host,
port : port,
promisify : true
});
host : host,
port : port,
promisify : true
});

@@ -121,3 +121,3 @@ try

{
this.logger.error('Could not connect to consul: %s', e.message);
this.logger.error('Could not connect to consul', {e});
throw e;

@@ -131,3 +131,3 @@ }

{
this.logger.info('Reading encryption key: %s', serviceSecretPath);
this.logger.info('Reading encryption key', {serviceSecretPath});

@@ -137,9 +137,9 @@ let secret = 'b2eb88a9cd0e45cf890a1505df17a718';

try
{
secret = fs.readFileSync(serviceSecretPath, 'utf8').trim();
}
catch(e)
{
this.logger.warn('Cannot read encryption key from %s. Falling back to default key.', serviceSecretPath);
}
{
secret = fs.readFileSync(serviceSecretPath, 'utf8').trim();
}
catch(e)
{
this.logger.warn('Cannot read encryption key - falling back to default key.', {serviceSecretPath});
}

@@ -317,3 +317,4 @@ return secret;

{
return [{host: serviceName, port: 80}];
const port = process.env[`${serviceName.toUpperCase()}_PORT`] || 80;
return [{host: serviceName, port}];
}

@@ -385,3 +386,3 @@

{
this.logger.warn('Config key %s could not be set: %s', keyName, e.message);
this.logger.warn('Config key could not be set', {keyName, ...e});
}

@@ -408,3 +409,3 @@ }

{
this.logger.warn('Config key %s could not be deleted: %s', keyName, e.message);
this.logger.warn('Config key could not be deleted', {keyName, ...e});

@@ -411,0 +412,0 @@ return false;

{
"name": "@opuscapita/config",
"version": "3.1.4",
"version": "3.1.5-next.0",
"description": "Configuration API connector module for OpusCapita Business Network Portal.",

@@ -8,10 +8,6 @@ "main": "index.js",

"start": "npm run test",
"test": "npm run setupConsul ; npx nyc mocha --exit --timeout 30000 -R mocha-junit-reporter --reporter-options mochaFile=junit/integration-test-results.xml,outputs=true",
"test-raw": "npm run setupConsul ; npx nyc mocha --exit --timeout 30000",
"setupConsul": "sh ./setup-consul.sh",
"test-coverage": "npm run setupConsul ; npx nyc --reporter=lcov mocha --exit --timeout 20000",
"upload-coverage": "cat ./coverage/lcov.info | npx coveralls",
"test": "npm run setup-consul ; npx nyc --all -r lcov mocha --exit --timeout 30000 -R mocha-junit-reporter --reporter-options mochaFile=junit/integration-test-results.xml,outputs=true",
"setup-consul": "sh ./setup-consul.sh",
"api-doc": "npx jsdoc2md --files ./lib/* > wiki/Home.md",
"doc": "npm run api-doc",
"prepublishOnly": "npm version patch -m 'Version set to %s. [skip ci]'"
"doc": "npm run api-doc"
},

@@ -33,15 +29,18 @@ "repository": {

"dependencies": {
"@opuscapita/cache": "^1.1.0",
"@opuscapita/logger": "^1.3.0",
"bluebird": "~3.5.1",
"@opuscapita/cache": "^1.2.0",
"@opuscapita/logger": "^2.0.0",
"bluebird": "^3.7.2",
"bluebird-retry": "~0.11.0",
"consul": "^0.34.0",
"consul": "^0.40.0",
"extend": "~3.0.1"
},
"devDependencies": {
"jsdoc-to-markdown": "^4.0.1",
"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.23.3",
"nyc": "^13.0.0"
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.6",
"eslint": "^8.20.0",
"jsdoc-to-markdown": "^7.1.1",
"mocha": "^10.0.0",
"mocha-junit-reporter": "^2.0.2",
"nyc": "^15.1.0"
}
}
# @opuscapita/config
This library is automatically build and published to npmjs after commit to the `master` branch
This library was automatically build and published to npmjs after commit to the `master` branch but was re-configured for manual build instead.

@@ -4,0 +4,0 @@ This module provides easy access to instances of the **consul** service registry. It helps with accessing **key-value** stored configuration data, local data **encryption** and service **endpoint discovery** with health checking and change notifications.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc