pino-elasticsearch
Advanced tools
+107
| 'use strict' | ||
| const test = require('tap').test | ||
| const proxyquire = require('proxyquire') | ||
| test('CLI: arg node should passed to client constructor', async (t) => { | ||
| const cli = proxyquire('../cli.js', { | ||
| pump: () => { }, | ||
| './lib.js': (opts) => { | ||
| t.same(opts, { node: 'https://custom-node-url:9999' }) | ||
| return { | ||
| on: () => { } | ||
| } | ||
| } | ||
| }) | ||
| cli({ node: 'https://custom-node-url:9999' }) | ||
| }) | ||
| test('CLI: arg rejectUnauthorized, if set to \'true\', should passed as true (bool) to client constructor', async (t) => { | ||
| const cli = proxyquire('../cli.js', { | ||
| pump: () => { }, | ||
| './lib.js': (opts) => { | ||
| t.same(opts, { | ||
| node: 'https://custom-node-url:9999', | ||
| rejectUnauthorized: true | ||
| }) | ||
| return { | ||
| on: () => { } | ||
| } | ||
| } | ||
| }) | ||
| cli({ | ||
| node: 'https://custom-node-url:9999', | ||
| rejectUnauthorized: 'true' | ||
| }) | ||
| }) | ||
| test('CLI: arg rejectUnauthorized, if set to \'false\', should passed as false (bool) to client constructor', async (t) => { | ||
| const cli = proxyquire('../cli.js', { | ||
| pump: () => { }, | ||
| './lib.js': (opts) => { | ||
| t.same(opts, { | ||
| node: 'https://custom-node-url:9999', | ||
| rejectUnauthorized: false | ||
| }) | ||
| return { | ||
| on: () => { } | ||
| } | ||
| } | ||
| }) | ||
| cli({ | ||
| node: 'https://custom-node-url:9999', | ||
| rejectUnauthorized: 'false' | ||
| }) | ||
| }) | ||
| test('CLI: arg rejectUnauthorized, if set to anything instead of true or false, should passed as true (bool) to client constructor', async (t) => { | ||
| const cli = proxyquire('../cli.js', { | ||
| pump: () => { }, | ||
| './lib.js': (opts) => { | ||
| t.same(opts, { | ||
| node: 'https://custom-node-url:9999', | ||
| rejectUnauthorized: true | ||
| }) | ||
| return { | ||
| on: () => { } | ||
| } | ||
| } | ||
| }) | ||
| cli({ | ||
| node: 'https://custom-node-url:9999', | ||
| rejectUnauthorized: 'anything' | ||
| }) | ||
| }) | ||
| test('CLI: if arg.read-config is set, should read the config file and passed the value (only allowed values)', async (t) => { | ||
| const cli = proxyquire('../cli.js', { | ||
| pump: () => { }, | ||
| './lib.js': (opts) => { | ||
| t.same(opts, { | ||
| index: 'custom-index', | ||
| node: 'https://localhost:9200', | ||
| rejectUnauthorized: false, | ||
| auth: { | ||
| username: 'elastic', | ||
| password: 'pass' | ||
| }, | ||
| // some keys are redundant, it is intended as it is. | ||
| // (see function start() in cli.js) | ||
| 'read-config': 'test/exampleConfig.js', | ||
| username: 'elastic', | ||
| password: 'pass' | ||
| }) | ||
| return { | ||
| on: () => { } | ||
| } | ||
| } | ||
| }) | ||
| cli({ | ||
| node: 'https://custom-node-url:9999', | ||
| 'read-config': 'test/exampleConfig.js' | ||
| }) | ||
| }) |
| module.exports = { | ||
| index: 'custom-index', | ||
| node: 'https://localhost:9200', | ||
| rejectUnauthorized: false, | ||
| username: 'elastic', | ||
| password: 'pass' | ||
| } |
+60
-37
@@ -36,2 +36,6 @@ #! /usr/bin/env node | ||
| if (opts.rejectUnauthorized) { | ||
| opts.rejectUnauthorized = opts.rejectUnauthorized !== 'false' | ||
| } | ||
| const stream = pinoElasticSearch(opts) | ||
@@ -49,45 +53,64 @@ | ||
| if (opts.rejectUnauthorized) { | ||
| opts.rejectUnauthorized = opts.rejectUnauthorized !== 'false' | ||
| } | ||
| pump(process.stdin, stream) | ||
| } | ||
| const flags = minimist(process.argv.slice(2), { | ||
| alias: { | ||
| version: 'v', | ||
| help: 'h', | ||
| node: 'n', | ||
| index: 'i', | ||
| 'flush-bytes': 'f', | ||
| 'flush-interval': 't', | ||
| 'trace-level': 'l', | ||
| username: 'u', | ||
| password: 'p', | ||
| 'api-key': 'k', | ||
| cloud: 'c', | ||
| 'read-config': 'r' | ||
| }, | ||
| default: { | ||
| node: 'http://localhost:9200' | ||
| function startCli (flags) { | ||
| const allowedProps = [ | ||
| 'node', | ||
| 'index', | ||
| 'flush-bytes', | ||
| 'flush-interval', | ||
| 'trace-level', | ||
| 'username', | ||
| 'password', | ||
| 'api-key', | ||
| 'cloud', | ||
| 'es-version', | ||
| 'rejectUnauthorized' | ||
| ] | ||
| if (flags['read-config']) { | ||
| if (flags['read-config'].match(/.*\.json$/) !== null) { | ||
| const config = JSON.parse(fs.readFileSync(path.join(process.cwd(), flags['read-config']), 'utf-8')) | ||
| allowedProps.forEach(key => { | ||
| if (config[key] !== undefined) { | ||
| flags[key] = config[key] | ||
| } | ||
| }) | ||
| } | ||
| if (flags['read-config'].match(/.*\.js$/) !== null) { | ||
| const config = require(path.join(process.cwd(), flags['read-config'])) | ||
| allowedProps.forEach(key => { | ||
| if (config[key] !== undefined) { | ||
| flags[key] = config[key] | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| }) | ||
| const allowedProps = ['node', 'index', 'flush-bytes', 'flush-interval', 'trace-level', 'username', 'password', 'api-key', 'cloud', 'es-version', 'rejectUnauthorized'] | ||
| start(flags) | ||
| } | ||
| if (flags['read-config']) { | ||
| if (flags['read-config'].match(/.*\.json$/) !== null) { | ||
| const config = JSON.parse(fs.readFileSync(path.join(process.cwd(), flags['read-config']), 'utf-8')) | ||
| allowedProps.forEach(key => { | ||
| if (config[key]) { flags[key] = config[key] } | ||
| }) | ||
| } | ||
| if (require.main === module) { | ||
| startCli(minimist(process.argv.slice(2), { | ||
| alias: { | ||
| version: 'v', | ||
| help: 'h', | ||
| node: 'n', | ||
| index: 'i', | ||
| 'flush-bytes': 'f', | ||
| 'flush-interval': 't', | ||
| 'trace-level': 'l', | ||
| username: 'u', | ||
| password: 'p', | ||
| 'api-key': 'k', | ||
| cloud: 'c', | ||
| 'read-config': 'r' | ||
| }, | ||
| default: { | ||
| node: 'http://localhost:9200' | ||
| } | ||
| })) | ||
| } | ||
| if (flags['read-config'].match(/.*\.js$/) !== null) { | ||
| const config = require(path.join(process.cwd(), flags['read-config'])) | ||
| allowedProps.forEach(key => { | ||
| if (config[key]) { flags[key] = config[key] } | ||
| }) | ||
| } | ||
| } | ||
| start(flags) | ||
| module.exports = startCli |
+2
-2
| { | ||
| "name": "pino-elasticsearch", | ||
| "version": "6.6.0", | ||
| "version": "6.7.0", | ||
| "description": "Load pino logs into ElasticSearch", | ||
@@ -33,3 +33,3 @@ "main": "./lib.js", | ||
| "tap": "^16.0.0", | ||
| "tsd": "^0.28.1" | ||
| "tsd": "^0.29.0" | ||
| }, | ||
@@ -36,0 +36,0 @@ "dependencies": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
63240
5.12%24
9.09%1149
12.21%