From aef2a53327c68aff8e593b10afe1ab8ade13a1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mari=C3=A1n=20Skrip?= Date: Wed, 16 Feb 2022 17:56:43 +0100 Subject: [PATCH 1/3] feat: Add option to specify default value to env var expansion --- config.sample.yml | 2 +- dev/build/config.yml | 2 +- server/helpers/config.js | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config.sample.yml b/config.sample.yml index 6f4fbdf32b..297fa33e2b 100644 --- a/config.sample.yml +++ b/config.sample.yml @@ -106,7 +106,7 @@ bindIP: 0.0.0.0 # --------------------------------------------------------------------- # Possible values: error, warn, info (default), verbose, debug, silly -logLevel: info +logLevel: $(LOG_LEVEL:info) # --------------------------------------------------------------------- # Offline Mode diff --git a/dev/build/config.yml b/dev/build/config.yml index 86d240dc95..21f1683015 100644 --- a/dev/build/config.yml +++ b/dev/build/config.yml @@ -15,5 +15,5 @@ ssl: provider: letsencrypt domain: $(LETSENCRYPT_DOMAIN) subscriberEmail: $(LETSENCRYPT_EMAIL) -logLevel: info +logLevel: $(LOG_LEVEL:info) ha: $(HA_ACTIVE) diff --git a/server/helpers/config.js b/server/helpers/config.js index 0e6ab56364..d9e60a4151 100644 --- a/server/helpers/config.js +++ b/server/helpers/config.js @@ -8,14 +8,18 @@ module.exports = { /** * Parse configuration value for environment vars * + * Replaces `$(ENV_VAR_NAME)` with value of `ENV_VAR_NAME` environment variable. + * + * Also supports defaults by if provided as `$(ENV_VAR_NAME:default)` + * * @param {any} cfg Configuration value * @returns Parse configuration value */ parseConfigValue (cfg) { return _.replace( cfg, - /\$\(([A-Z0-9_]+)\)/g, - (fm, m) => { return process.env[m] } + /\$\(([A-Z0-9_]+)(:(.+))?\)/g, + (fm, m, _, d) => { return process.env[m] || d } ) }, From 226be6c19a318fd3dabc021eb19dce2f5404f7ae Mon Sep 17 00:00:00 2001 From: Nicolas Giard Date: Fri, 18 Feb 2022 19:52:41 -0500 Subject: [PATCH 2/3] fix: remove unused capturing group for env var replacement --- server/helpers/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/helpers/config.js b/server/helpers/config.js index d9e60a4151..6f972d40df 100644 --- a/server/helpers/config.js +++ b/server/helpers/config.js @@ -18,8 +18,8 @@ module.exports = { parseConfigValue (cfg) { return _.replace( cfg, - /\$\(([A-Z0-9_]+)(:(.+))?\)/g, - (fm, m, _, d) => { return process.env[m] || d } + /\$\(([A-Z0-9_]+)(?::(.+))?\)/g, + (fm, m, d) => { return process.env[m] || d } ) }, From 1854f1de08df0a32a576fa77f74207403b0978aa Mon Sep 17 00:00:00 2001 From: Nicolas Giard Date: Fri, 18 Feb 2022 19:54:54 -0500 Subject: [PATCH 3/3] Update config.sample.yml --- config.sample.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.sample.yml b/config.sample.yml index 29c491c5e0..47edd8d28f 100644 --- a/config.sample.yml +++ b/config.sample.yml @@ -106,7 +106,7 @@ bindIP: 0.0.0.0 # --------------------------------------------------------------------- # Possible values: error, warn, info (default), verbose, debug, silly -logLevel: $(LOG_LEVEL:info) +logLevel: info # --------------------------------------------------------------------- # Log Format