Skip to content

Commit b432022

Browse files
authored
Merge pull request #7078 from Countly/ar2rsawseen/newarch
Allow extending countly settings through env variables
2 parents 4141c4f + 140cfc4 commit b432022

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

plugins/pluginManager.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,39 @@ var pluginManager = function pluginManager() {
383383
* @param {function} onchange - function to call when configurations change
384384
**/
385385
this.setConfigs = function(namespace, conf, exclude, onchange) {
386+
// Apply environment variable overrides before setting defaults
387+
var processedConf = {};
388+
for (let key in conf) {
389+
if (!Object.prototype.hasOwnProperty.call(conf, key)) {
390+
continue;
391+
}
392+
// Check for environment variable: COUNTLY_SETTINGS__NAMESPACE__KEY
393+
var envVarName = 'COUNTLY_SETTINGS__' + namespace.toUpperCase() + '__' + key.toUpperCase();
394+
if (process.env[envVarName] !== undefined) {
395+
var envValue = process.env[envVarName];
396+
// Try to parse as JSON first (for objects, arrays, booleans, numbers)
397+
try {
398+
processedConf[key] = JSON.parse(envValue);
399+
}
400+
catch (e) {
401+
// If parsing fails, use as string
402+
processedConf[key] = envValue;
403+
}
404+
}
405+
else {
406+
processedConf[key] = conf[key];
407+
}
408+
}
409+
386410
if (!defaultConfigs[namespace]) {
387-
defaultConfigs[namespace] = conf;
411+
defaultConfigs[namespace] = processedConf;
388412
}
389413
else {
390-
for (let i in conf) {
391-
defaultConfigs[namespace][i] = conf[i];
414+
for (let i in processedConf) {
415+
if (!Object.prototype.hasOwnProperty.call(processedConf, i)) {
416+
continue;
417+
}
418+
defaultConfigs[namespace][i] = processedConf[i];
392419
}
393420
}
394421
if (exclude) {

0 commit comments

Comments
 (0)