mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
env: off/on are truthy sometimes
Provide readENVTruthy, and mapTruthy, to explicitly handle
the cases where on/off or similar should result in a
Boolean value. Here, they should be mapped correctly,
eliminating a problem @miloskozak experienced when setting
AUTH_DEFAULT_ROLES=bad, there is an exception becaue the
value is a literal `true` instead of the string `"bad"`.
Intended to be a no-op, preserving the intended effects
from previous commit
dbe29bd4be from
@jasoncalabrese.
This commit is contained in:
@@ -136,8 +136,8 @@ function updateSettings() {
|
||||
//should always find extended settings last
|
||||
env.extendedSettings = findExtendedSettings(process.env);
|
||||
|
||||
if (!readENV('TREATMENTS_AUTH', true)) {
|
||||
env.settings.authDefaultRoles = env.settings.authDefaultRoles || [ ];
|
||||
if (!readENVTruthy('TREATMENTS_AUTH', true)) {
|
||||
env.settings.authDefaultRoles = env.settings.authDefaultRoles || "";
|
||||
env.settings.authDefaultRoles += ' careportal';
|
||||
}
|
||||
|
||||
@@ -151,12 +151,17 @@ function readENV(varName, defaultValue) {
|
||||
|| process.env[varName]
|
||||
|| process.env[varName.toLowerCase()];
|
||||
|
||||
if (typeof value === 'string' && (value.toLowerCase() === 'on' || value.toLowerCase() === 'true')) { value = true; }
|
||||
if (typeof value === 'string' && (value.toLowerCase() === 'off' || value.toLowerCase() === 'false')) { value = false; }
|
||||
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
function readENVTruthy(varName, defaultValue) {
|
||||
var value = readENV(varName, defaultValue);
|
||||
if (typeof value === 'string' && (value.toLowerCase() === 'on' || value.toLowerCase() === 'true')) { value = true; }
|
||||
if (typeof value === 'string' && (value.toLowerCase() === 'off' || value.toLowerCase() === 'false')) { value = false; }
|
||||
return value;
|
||||
}
|
||||
|
||||
function findExtendedSettings (envs) {
|
||||
var extended = {};
|
||||
|
||||
|
||||
+14
-1
@@ -44,11 +44,18 @@ function init ( ) {
|
||||
};
|
||||
|
||||
var valueMappers = {
|
||||
alarmUrgentHighMins: mapNumberArray
|
||||
nightMode: mapTruthy
|
||||
, alarmUrgentHigh: mapTruthy
|
||||
, alarmUrgentHighMins: mapNumberArray
|
||||
, alarmHigh: mapTruthy
|
||||
, alarmHighMins: mapNumberArray
|
||||
, alarmLow: mapTruthy
|
||||
, alarmLowMins: mapNumberArray
|
||||
, alarmUrgentLow: mapTruthy
|
||||
, alarmUrgentLowMins: mapNumberArray
|
||||
, alarmUrgentMins: mapNumberArray
|
||||
, alarmTimeagoWarn: mapTruthy
|
||||
, alarmTimeagoUrgent: mapTruthy
|
||||
, alarmWarnMins: mapNumberArray
|
||||
, timeFormat: mapNumber
|
||||
};
|
||||
@@ -80,6 +87,12 @@ function init ( ) {
|
||||
}
|
||||
}
|
||||
|
||||
function mapTruthy (value) {
|
||||
if (typeof value === 'string' && (value.toLowerCase() === 'on' || value.toLowerCase() === 'true')) { value = true; }
|
||||
if (typeof value === 'string' && (value.toLowerCase() === 'off' || value.toLowerCase() === 'false')) { value = false; }
|
||||
return value;
|
||||
}
|
||||
|
||||
//TODO: getting sent in status.json, shouldn't be
|
||||
settings.DEFAULT_FEATURES = ['delta', 'direction', 'timeago', 'devicestatus', 'upbat', 'errorcodes', 'profile'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user