From 2411dffa2ce997370a636ed56cc73bcc4661ec7f Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Wed, 7 Mar 2018 15:17:35 +0100 Subject: Change config to camel case with backwards compatibility This refactors the configs a bit to now use camel case everywhere. This change should help to clean up the config interface and make it better understandable. Signed-off-by: Sheogorath --- lib/config/index.js | 71 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 29 deletions(-) (limited to 'lib/config/index.js') diff --git a/lib/config/index.js b/lib/config/index.js index abcd2b3e..fae51e52 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -27,6 +27,7 @@ const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] let config = require('./default') merge(config, require('./defaultSSL')) +merge(config, require('./oldDefault')) merge(config, debugConfig) merge(config, packageConfig) merge(config, fileConfig) @@ -51,35 +52,35 @@ if (config.ldap.tlsca) { // Permission config.permission = Permission -if (!config.allowanonymous && !config.allowanonymousedits) { +if (!config.allowAnonymous && !config.allowAnonymousedits) { delete config.permission.freely } -if (!(config.defaultpermission in config.permission)) { - config.defaultpermission = config.permission.editable +if (!(config.defaultPermission in config.permission)) { + config.defaultPermission = config.permission.editable } // cache result, cannot change config in runtime!!! config.isStandardHTTPsPort = (function isStandardHTTPsPort () { - return config.usessl && config.port === 443 + return config.useSSL && config.port === 443 })() config.isStandardHTTPPort = (function isStandardHTTPPort () { - return !config.usessl && config.port === 80 + return !config.useSSL && config.port === 80 })() // cache serverURL -config.serverurl = (function getserverurl () { +config.serverURL = (function getserverurl () { var url = '' if (config.domain) { - var protocol = config.protocolusessl ? 'https://' : 'http://' + var protocol = config.protocolUseSSL ? 'https://' : 'http://' url = protocol + config.domain - if (config.urladdport) { + if (config.urlAddPort) { if (!config.isStandardHTTPPort || !config.isStandardHTTPsPort) { url += ':' + config.port } } } - if (config.urlpath) { - url += '/' + config.urlpath + if (config.urlPath) { + url += '/' + config.urlPath } return url })() @@ -97,21 +98,33 @@ config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret config.isLDAPEnable = config.ldap.url config.isSAMLEnable = config.saml.idpSsoUrl -config.isPDFExportEnable = config.allowpdfexport +config.isPDFExportEnable = config.allowPDFExport // merge legacy values -if (config.imageUploadType && !config.imageuploadtype) { - config.imageuploadtype = config.imageUploadType +let keys = Object.keys(config) +const uppercase = /[A-Z]/ +for (let i = keys.length; i--;) { + let lowercaseKey = keys[i].toLowerCase() + // if the config contains uppercase letters + // and a lowercase version of this setting exists + // and the config with uppercase is not set + // we set the new config using the old key. + if (uppercase.test(keys[i]) && + config[lowercaseKey] && + !config[keys[1]]) { + logger.warn('config.js contains deprecated lowercase setting for ' + keys[i] + '. Please change your config.js file to replace ' + lowercaseKey + ' with ' + keys[i]) + config[keys[i]] = config[lowercaseKey] + } } // Validate upload upload providers -if (['filesystem', 's3', 'minio', 'imgur'].indexOf(config.imageuploadtype) === -1) { +if (['filesystem', 's3', 'minio', 'imgur'].indexOf(config.imageUploadType) === -1) { logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio" or "imgur". Defaulting to "imgur"') - config.imageuploadtype = 'imgur' + config.imageUploadType = 'imgur' } // figure out mime types for image uploads -switch (config.imageuploadtype) { +switch (config.imageUploadType) { case 'imgur': config.allowedUploadMimeTypes = [ 'image/jpeg', @@ -131,22 +144,22 @@ switch (config.imageuploadtype) { } // generate correct path -config.sslcapath.forEach(function (capath, i, array) { +config.sslCAPath.forEach(function (capath, i, array) { array[i] = path.resolve(appRootPath, capath) }) -config.sslcertpath = path.join(appRootPath, config.sslcertpath) -config.sslkeypath = path.join(appRootPath, config.sslkeypath) -config.dhparampath = path.join(appRootPath, config.dhparampath) - -config.tmppath = path.join(appRootPath, config.tmppath) -config.defaultnotepath = path.join(appRootPath, config.defaultnotepath) -config.docspath = path.join(appRootPath, config.docspath) -config.indexpath = path.join(appRootPath, config.indexpath) -config.hackmdpath = path.join(appRootPath, config.hackmdpath) -config.errorpath = path.join(appRootPath, config.errorpath) -config.prettypath = path.join(appRootPath, config.prettypath) -config.slidepath = path.join(appRootPath, config.slidepath) +config.sslCertPath = path.join(appRootPath, config.sslCertPath) +config.sslKeyPath = path.join(appRootPath, config.sslKeyPath) +config.dhParamPath = path.join(appRootPath, config.dhParamPath) + +config.tmpPath = path.join(appRootPath, config.tmpPath) +config.defaultNotePath = path.join(appRootPath, config.defaultNotePath) +config.docsPath = path.join(appRootPath, config.docsPath) +config.indexPath = path.join(appRootPath, config.indexPath) +config.hackmdPath = path.join(appRootPath, config.hackmdPath) +config.errorPath = path.join(appRootPath, config.errorPath) +config.prettyPath = path.join(appRootPath, config.prettyPath) +config.slidePath = path.join(appRootPath, config.slidePath) // make config readonly config = deepFreeze(config) -- cgit v1.2.3