Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add ENV variables support for few configuration option - Closes #2225 #2285

Merged
merged 4 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,32 @@ node app.js [options]

Each of that option can be appended on command line. There are also few `ENV` variables that can be utilized for this purpose.

| Option | ENV Variable | Config Option | Description |
| ------------------ | ---------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --network<br> -n | LISK_NETWORK | | Which configurations set to use, associated to lisk networks. Any of this option can be used `devnet`, `alphanet`, `betanet`, `testnet` and `mainnet`. Default value is `devnet`. |
| --config<br> -c | LISK_CONFIG_FILE | | Path the custom configuration file, which will override values of `config/default/config.json` |
| --port<br> -p | LISK_WS_PORT | wsPort | TCP port for P2P layer |
| --http-port<br> -h | LISK_HTTP_PORT | httpPort | TCP port for HTTP API |
| --address<br> -a | | address | Listening host name or ip |
| --database<br> -d | | db.database | PostgreSQL database name to connect |
| --peers<br> -p | LISK_PEERS | peers.list | Comma separated list of peers to connect in the format `192.168.99.100:5000,172.169.99.77:5000` |
| --log<br> -l | LISK_CONSOLE_LOG_LEVEL | consoleLogLevel | Log level for lisk for console output |
| --snapshot<br> -s | | | Number of round for which take the snapshot. If none specified it will use the highest round available. |
| Option | ENV Variable | Config Option | Description |
| ------------------ | ---------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --network<br> -n | LISK_NETWORK | | Which configurations set to use, associated to lisk networks. Any of this option can be used `devnet`, `alphanet`, `betanet`, `testnet` and `mainnet`. Default value is `devnet`. |
| --config<br> -c | LISK_CONFIG_FILE | | Path the custom configuration file, which will override values of `config/default/config.json` |
| --port<br> -p | LISK_WS_PORT | wsPort | TCP port for P2P layer |
| --http-port<br> -h | LISK_HTTP_PORT | httpPort | TCP port for HTTP API |
| --address<br> -a | LISK_ADDRESS | address | Listening host name or ip |
| --log<br> -l | LISK_FILE_LOG_LEVEL | fileLogLevel | Log level for file output |
| | LISK_CONSOLE_LOG_LEVEL | consoleLogLevel | Log level for console output |
| | LISK_CACHE_ENABLED | cacheEnabled | Enable or disable cache. Must be set to true/false |
| --database<br> -d | LISK_DB_NAME | db.database | PostgreSQL database name to connect |
| | LISK_DB_HOST | db.host | PostgreSQL database host name |
| | LISK_DB_PORT | db.port | PostgreSQL database port |
| | LISK_DB_USER | db.user | PostgreSQL database username to connect |
| | LISK_DB_PASSWORD | db.password | PostgreSQL database password to connect |
| --peers<br> -p | LISK_PEERS | peers.list | Comma separated list of peers to connect in the format `192.168.99.100:5000,172.169.99.77:5000` |
| | LISK_API_PUBLIC | api.access.public | Enable or disable public access of http API. Must be set to true/false |
| | LISK_API_WHITELIST | api.access.whiteList | Comma separated list of IPs to enable API access. Format `192.168.99.100,172.169.99.77` |
| | LISK_FORGING_DELEGATES | forging.delegates | Comma separated list of delegates to load in the format `publicKey|encryptedPassphrase,publicKey2|encryptedPassphrase2` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to escape that, it does show properly in the rendered README file.

| | LISK_FORGING_WHITELIST | forging.access.whiteList | Comma separated list of IPs to enable access to forging endpoints. Format `192.168.99.100,172.169.99.77` |
| --snapshot<br> -s | | | Number of round for which take the snapshot. If none specified it will use the highest round available. |

#### Note

* All `ENV` variables restricted with operating system constraint of `ENV` variable maximum length.
* Comma separated lists will replace the original config values. e.g. If you specify `LISK_PEERS`, original `peers.list` specific to network will be replaced completely.

For more detail understanding of configuration read this [online documentation](https://lisk.io/documentation/lisk-core/user-guide/configuration)

Expand Down
3 changes: 0 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ if (typeof gc !== 'undefined') {
*/
var appConfig = AppConfig(require('./package.json'));

// Define lisk network env variable to be used by child processes load config files
process.env.LISK_NETWORK = appConfig.network;

// Global objects to be utilized under modules/helpers where scope is not accessible
global.constants = appConfig.constants;
global.exceptions = appConfig.exceptions;
Expand Down
58 changes: 53 additions & 5 deletions helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ function Config(packageJson, parseCommandLineOptions = true) {
}

const network = program.network || process.env.LISK_NETWORK || 'devnet';
// Define lisk network env variable to be used by child processes load config files
process.env.LISK_NETWORK = network;

const genesisBlock = loadJSONFile(`./config/${network}/genesis_block.json`);

Expand Down Expand Up @@ -90,29 +92,55 @@ function Config(packageJson, parseCommandLineOptions = true) {
let commandLineConfig = {
wsPort: +program.port || process.env.LISK_WS_PORT || null,
httpPort: +program.httpPort || process.env.LISK_HTTP_PORT || null,
address: program.address,
consoleLogLevel: program.log || process.env.LISK_CONSOLE_LOG_LEVEL,
db: { database: program.database },
address: program.address || process.env.LISK_ADDRESS || null,
fileLogLevel: program.log || process.env.LISK_FILE_LOG_LEVEL || null,
consoleLogLevel: process.env.LISK_CONSOLE_LOG_LEVEL || null,
cacheEnabled: process.env.LISK_CACHE_ENABLED === 'true',
db: {
database: program.database || process.env.LISK_DB_NAME || null,
host: process.env.LISK_DB_HOST || null,
port: process.env.LISK_DB_PORT || null,
user: process.env.LISK_DB_USER || null,
password: process.env.LISK_DB_PASSWORD || null,
},
api: {
access: {
public: process.env.LISK_API_PUBLIC === 'true',
whiteList: extractWhiteListIPs(process.env.LISK_API_WHITELIST),
},
},
forging: {
delegates: extractDelegatesList(process.env.LISK_FORGING_DELEGATES),
access: {
whiteList: extractWhiteListIPs(process.env.LISK_FORGING_WHITELIST),
},
},
loading: { snapshotRound: program.snapshot },
peers: {
list: extractPeersList(
program.peers || process.env.LISK_PEERS,
+program.port ||
process.env.LISK_WS_PORT ||
customConfig.wsPort ||
networkConfig.wsPort ||
defaultConfig.wsPort
),
},
coverage: process.env.NODE_ENV === 'test',
};
commandLineConfig = cleanDeep(commandLineConfig);

const appConfig = _.merge(
const appConfig = _.mergeWith(
defaultConfig,
networkConfig,
customConfig,
commandLineConfig,
runtimeConfig
runtimeConfig,
(objValue, srcValue) => {
if (_.isArray(objValue)) {
return srcValue;
}
}
);

var validator = new z_schema();
Expand Down Expand Up @@ -158,6 +186,26 @@ function extractPeersList(peers, defaultPort) {
return [];
}

function extractWhiteListIPs(ips) {
if (typeof ips === 'string') {
return ips.split(',');
}
return [];
}

function extractDelegatesList(delegates) {
if (typeof delegates === 'string') {
return delegates.split(',').map(delegate => {
delegate = delegate.split('|');
return {
publicKey: delegate[0],
encryptedPassphrase: delegate[1],
};
});
}
return [];
}

function cleanDeep(
object,
{
Expand Down