Comparing version 1.31.10 to 1.31.11
@@ -13,4 +13,39 @@ /* | ||
var flatten = require('flat') | ||
var unflatten = require('flat').unflatten | ||
var util = require('util') | ||
var RC = require('rc-yaml-2') | ||
var fs = require('fs') | ||
// load SPM receivers from file containing | ||
// env vars e.g. SPM_RECEIVER_URL, EVENTS_RECEIVER_URL, LOGSENE_RECEIVER_URL | ||
// the file overwrites the actual environment | ||
// and is used by Sematext Enterprise or multi-region setups to | ||
// setup receiver URLs | ||
function loadEnvFromFile (fileName) { | ||
try { | ||
var receivers = fs.readFileSync(fileName).toString() | ||
if (receivers) { | ||
var lines = receivers.split('\n') | ||
} | ||
// console.log(new Date(), 'loading Sematext receiver URLs from ' + fileName) | ||
lines.forEach(function (line) { | ||
var kv = line.split('=') | ||
if (kv.length === 2 && kv[1].length > 0) { | ||
process.env[kv[0].trim()] = kv[1].trim() | ||
// console.log(kv[0].trim() + ' = ' + kv[1].trim()) | ||
} | ||
}) | ||
} catch (error) { | ||
// ignore missing file or wrong format | ||
// console.error(error.message) | ||
} | ||
} | ||
var envFileName = '/etc/sematext/receivers.config' | ||
/** | ||
if (/win/.test(os.platform()) { | ||
envFileName = process.env.ProgramData + '\\Sematext\\receivers.config' | ||
} | ||
**/ | ||
loadEnvFromFile(envFileName) | ||
var spmDefaultConfig = { | ||
@@ -48,6 +83,18 @@ tokens: { | ||
SpmConfig.prototype.get = function (key) { | ||
return this.rcFlat[key] | ||
SpmConfig.prototype.get = function (flatKey) { | ||
return this.rcFlat[flatKey] | ||
} | ||
SpmConfig.prototype.set = function (flatKey, value) { | ||
var kv = {} | ||
kv[flatKey] = value | ||
kv.object = true | ||
var result = unflatten(kv) | ||
delete result.object | ||
delete this.rcFlat | ||
util._extend(this, result) | ||
this.rcFlat = flatten(this) | ||
return this | ||
} | ||
module.exports = new SpmConfig(process.env.SPM_AGENT_APP_TYPE || 'spmagent') |
{ | ||
"name": "spm-agent", | ||
"version": "1.31.10", | ||
"version": "1.31.11", | ||
"description": "Node.js agent framework for SPM by Sematext", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -76,2 +76,14 @@ /* | ||
}) | ||
it('SPM Config "set" accepts flat key', function (done) { | ||
try { | ||
config.set('a.b.0.name', 'test') | ||
if (config.a.b[0].name === 'test') { | ||
done() | ||
} else { | ||
done(new Error('set flat key: a.b.0.name != test')) | ||
} | ||
} catch (err) { | ||
done(err) | ||
} | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58665
1084
40