summaryrefslogtreecommitdiff
path: root/lib/config
diff options
context:
space:
mode:
authorChristoph (Sheogorath) Kern2017-12-12 10:23:42 +0100
committerGitHub2017-12-12 10:23:42 +0100
commit74758723f9deed8218a6dec588724d722656f6fd (patch)
tree1ba55d7cd15c339b8034b361c418e15c46f14641 /lib/config
parente9e7a8e23df7e82730b843c748e17072fb2f1221 (diff)
parent5e5a021ce0606bc260b4a091620ad5a2862a7ee8 (diff)
Merge pull request #651 from alecdwm/ldap-auth-searchattributes-fix
Parse env var `HMD_LDAP_SEARCHATTRIBUTES` as a comma-separated array
Diffstat (limited to '')
-rw-r--r--lib/config/environment.js10
-rw-r--r--lib/config/utils.js7
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/config/environment.js b/lib/config/environment.js
index b7b0e3f8..45a2b0e0 100644
--- a/lib/config/environment.js
+++ b/lib/config/environment.js
@@ -1,6 +1,6 @@
'use strict'
-const {toBooleanConfig} = require('./utils')
+const {toBooleanConfig, toArrayConfig} = require('./utils')
module.exports = {
domain: process.env.HMD_DOMAIN,
@@ -15,7 +15,7 @@ module.exports = {
preload: toBooleanConfig(process.env.HMD_HSTS_PRELOAD)
},
protocolusessl: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL),
- alloworigin: process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : undefined,
+ alloworigin: toArrayConfig(process.env.HMD_ALLOW_ORIGIN),
usecdn: toBooleanConfig(process.env.HMD_USECDN),
allowanonymous: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS),
allowfreeurl: toBooleanConfig(process.env.HMD_ALLOW_FREEURL),
@@ -70,7 +70,7 @@ module.exports = {
tokenSecret: process.env.HMD_LDAP_TOKENSECRET,
searchBase: process.env.HMD_LDAP_SEARCHBASE,
searchFilter: process.env.HMD_LDAP_SEARCHFILTER,
- searchAttributes: process.env.HMD_LDAP_SEARCHATTRIBUTES,
+ searchAttributes: toArrayConfig(process.env.HMD_LDAP_SEARCHATTRIBUTES),
tlsca: process.env.HMD_LDAP_TLS_CA
},
saml: {
@@ -79,8 +79,8 @@ module.exports = {
issuer: process.env.HMD_SAML_ISSUER,
identifierFormat: process.env.HMD_SAML_IDENTIFIERFORMAT,
groupAttribute: process.env.HMD_SAML_GROUPATTRIBUTE,
- externalGroups: process.env.HMD_SAML_EXTERNALGROUPS ? process.env.HMD_SAML_EXTERNALGROUPS.split('|') : [],
- requiredGroups: process.env.HMD_SAML_REQUIREDGROUPS ? process.env.HMD_SAML_REQUIREDGROUPS.split('|') : [],
+ externalGroups: toArrayConfig(process.env.HMD_SAML_EXTERNALGROUPS, '|', []),
+ requiredGroups: toArrayConfig(process.env.HMD_SAML_REQUIREDGROUPS, '|', []),
attribute: {
id: process.env.HMD_SAML_ATTRIBUTE_ID,
username: process.env.HMD_SAML_ATTRIBUTE_USERNAME,
diff --git a/lib/config/utils.js b/lib/config/utils.js
index 11bbd8cb..9ff2f96d 100644
--- a/lib/config/utils.js
+++ b/lib/config/utils.js
@@ -6,3 +6,10 @@ exports.toBooleanConfig = function toBooleanConfig (configValue) {
}
return configValue
}
+
+exports.toArrayConfig = function toArrayConfig (configValue, separator = ',', fallback) {
+ if (configValue && typeof configValue === 'string') {
+ return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
+ }
+ return fallback
+}