Improved config value set checks

This commit is contained in:
Jonathan Barrow 2022-10-09 13:54:42 -04:00
parent 566cd987cf
commit 1b2141ff76
No known key found for this signature in database
GPG key ID: E86E9FE9049C741F
3 changed files with 17 additions and 20 deletions

16
package-lock.json generated
View file

@ -27,7 +27,7 @@
"image-pixels": "^1.1.1",
"joi": "^17.6.1",
"kaitai-struct": "^0.9.0",
"lodash.has": "^4.5.2",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"mii-js": "github:PretendoNetwork/mii-js",
"moment": "^2.24.0",
@ -2055,12 +2055,7 @@
"node_modules/lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"node_modules/lodash.has": {
"version": "4.5.2",
"resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
"integrity": "sha512-rnYUdIo6xRCJnQmbVFEwcxF144erlD+M3YcJUVesflU9paQaE8p+fJDcIQrlMYbxoANFL+AB9hZrzSBBk5PL+g=="
"integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ=="
},
"node_modules/lodash.set": {
"version": "4.3.2",
@ -5360,12 +5355,7 @@
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.has": {
"version": "4.5.2",
"resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
"integrity": "sha512-rnYUdIo6xRCJnQmbVFEwcxF144erlD+M3YcJUVesflU9paQaE8p+fJDcIQrlMYbxoANFL+AB9hZrzSBBk5PL+g=="
"integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ=="
},
"lodash.set": {
"version": "4.3.2",

View file

@ -38,7 +38,7 @@
"image-pixels": "^1.1.1",
"joi": "^17.6.1",
"kaitai-struct": "^0.9.0",
"lodash.has": "^4.5.2",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"mii-js": "github:PretendoNetwork/mii-js",
"moment": "^2.24.0",

View file

@ -1,5 +1,5 @@
const fs = require('fs-extra');
const has = require('lodash.has');
const get = require('lodash.get');
const set = require('lodash.set');
const logger = require('../logger');
@ -131,15 +131,18 @@ function configure() {
for (const requiredField of requiredFields) {
const [keyPath, env, convertType] = requiredField;
if (!has(config, keyPath)) {
if (!process.env[env] || process.env[env].trim() === '') {
const configValue = get(config, keyPath);
const envValue = get(process.env, keyPath);
if (!configValue || configValue.trim() === '') {
if (!envValue || envValue.trim() === '') {
logger.error(`Failed to locate required field ${keyPath}. Set ${keyPath} in config.json or the ${env} environment variable`);
process.exit(0);
} else {
logger.info(`${keyPath} not found in config, using environment variable ${env}`);
const newValue = process.env[env];
const newValue = envValue;
set(config, keyPath, convertType ? convertType(newValue) : newValue);
}
@ -147,8 +150,12 @@ function configure() {
}
// * Check for optional settings
if (!has(config, 'redis.client.url')) {
if (!process.env.PN_ACT_CONFIG_REDIS_URL || process.env.PN_ACT_CONFIG_REDIS_URL.trim() === '') {
const redisConfigValue = get(config, 'redis.client.url');
const redisEnvValue = get(process.env, 'redis.client.url');
if (!redisConfigValue || redisConfigValue.trim() === '') {
if (!redisEnvValue || redisEnvValue.trim() === '') {
logger.warning('Failed to find Redis config. Disabling feature and using in-memory cache');
disabledFeatures.redis = true;