Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@opuscapita/config
Advanced tools
Readme
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. It provides automatic key prefixing for +key* storage isolation and caching for keys and endpoints. For further details, please have a look at the wiki.
First got to your local code directory and run:
npm install @opuscapita/config
To go with the minimum setup, you'll need to have a consul instance up and running. Now go to your code file and put in the minimum setup code.
const config = require('@opuscapita/config');
// You might want to pass a configuration object to the init method. A list of parameters and their default values
// can be found at the .DefaultConfig module property.
config.init({}).then(() => config.setProperty('my-key', 'my-value'))
.then(() => config.getProperty('my-key')).then(console.log).catch(console.log);
If everything worked as expected, you will get a bluebird promise as result.
const config = require('@opuscapita/config');
config.init().then(() => config.getEndPoint('service-name')).then(endpoint =>
{
console.log('Host: ' + endpoint.host);
console.log('Port: ' + endpoint.port);
})
.catch(console.log);
In addition to single-key-requests, the config module provides **two different methods for multi-key-requests.
Prefixing allows you to recursively fetch consul keys and their corresponding values by simply passing a prefix and the recursive parameter to the getProperty() method of the config module. After all keys have been retrieved successfully, the resulting promise contains an object in which the (full) consul keys represent the actual keys and their values represent the actual values inside consul.
config.init({}).then(() => config.setProperty("path/to/key1", "value1"))
.then(() => config.setProperty("path/to/key2", "value2"))
.then(() => config.setProperty("path/to/key3", "value3"))
.then(() => config.getProperty("path/", true))
.then(console.log)
.catch(console.log);
/* Should output:
{ 'path/to/key1': 'value1',
'path/to/key2': 'value2',
'path/to/key3': 'value3' }
*/
The config module allows passing an array of keys or prefixes (but not mixed!) to the getProperty() method. After all keys have been retrieved successfully, the resulting promise contains an array of consul values each at the corresponding position of their input keys.
config.init({}).then(() => config.setProperty("key1", "value1"))
.then(() => config.setProperty("key2", "value2"))
.then(() => config.setProperty("key3", "value3"))
.then(() => config.getProperty([ "key1", "key2", "key3" ]))
.then(console.log)
.catch(console.log);
/* Should output:
[ 'value1', 'value2', 'value3' ]
*/
By using the getPassword() and setPassword() methods, the config module is capable of encrypting and decrypting data retrieved and or stored with this methods. It also exposes the encryptData() and decryptData() methods, which can be used to encrypt small amounts of local data.
The file storage of the encryption key can be configured using the serviceSecretPath property of available through the config object .DefaultConfig. This feature is mainly designed to use docker secrets but can of course be adjusted to any other key path.
Notice: If the key path was not found at the configured location, a warning is emitted to the console and the key 'default' is used.
The default configuration object provides hints about what the module's standard behavior is like. It is mostly recommended to leave most settings as they are and treat them more as general conventions to a common structure in order to maintain a common setup across different services. For further details, please have a look at the wiki.
{
host: 'consul',
port: 8500,
retryCount : 50,
retryTimeout : 1000,
serviceSecretPath : `/run/secrets/${module.exports.serviceName}-consul-key`
}
FAQs
Configuration API connector module for OpusCapita Business Network Portal.
The npm package @opuscapita/config receives a total of 129 weekly downloads. As such, @opuscapita/config popularity was classified as not popular.
We found that @opuscapita/config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.