pino-eventhub
Advanced tools
Comparing version 0.0.2 to 0.1.0
{ | ||
"name": "pino-eventhub", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Pipe pino logs to Azure Event Hub", | ||
"main": "pino-eventhub", | ||
"bin": { | ||
"pino-eventhub": "./pino-eventhub.js" | ||
"pino-eventhub": "./start.js" | ||
}, | ||
"scripts": { | ||
"start": "node pino-eventhub.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"lint": "standard --fix", | ||
"start": "node start.js", | ||
"test": "standard && lab -c -m 5000 --leaks", | ||
"coveralls": "lab -c -m 5000 --leaks -t 90 -r lcov | coveralls" | ||
}, | ||
@@ -23,5 +25,8 @@ "keywords": [ | ||
"author": "Dr. Jan-Jan van der Vyver <jan.jan.code@gmail.com>", | ||
"contributors": [ | ||
"Ron Litzenberger (https://github.com/litzenberger)" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"crypto": "^0.0.3", | ||
"base64-stream": "^0.1.3", | ||
"debug": "^2.6.8", | ||
@@ -37,2 +42,8 @@ "fast-json-parse": "^1.0.2", | ||
}, | ||
"devDependencies": { | ||
"code": "^4.1.0", | ||
"coveralls": "^2.13.1", | ||
"lab": "^11.2.2", | ||
"standard": "^10.0.3" | ||
}, | ||
"repository": { | ||
@@ -39,0 +50,0 @@ "type": "git", |
#! /usr/bin/env node | ||
'use strict' | ||
const minimist = require('minimist') | ||
const Writable = require('readable-stream').Writable | ||
const split = require('split2') | ||
const pump = require('pump') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const utf8 = require('utf8') | ||
@@ -15,5 +12,6 @@ const crypto = require('crypto') | ||
const Parse = require('fast-json-parse') | ||
const socketCount = 10 | ||
function giveSecurityWarning () { | ||
console.warn("It is poor security practice to share your Shared Access Policy Key. It is better to calculate the Shared Access Signature, and share that.") | ||
console.warn('It is poor security practice to share your Shared Access Policy Key. It is better to calculate the Shared Access Signature, and share that.') | ||
console.log("'pino-eventhub.createSignature' can be used to calculate the Shared Access Signature.") | ||
@@ -39,4 +37,3 @@ } | ||
}) | ||
const url = decodeURIComponent(opts.sr) + '/messages' | ||
const agent = new https.Agent({keepAlive: true, maxSockets: opts.max || socketCount}) | ||
const options = { | ||
@@ -46,6 +43,7 @@ method: 'POST', | ||
port: opts.port, | ||
agent: agent, | ||
path: '/' + opts.eh + '/messages?timeout=60&api-version=2014-01', | ||
headers: { | ||
Authorization: 'SharedAccessSignature sr=' + opts.sr + '&sig=' + opts.sig + '&se=' + opts.se + '&skn=' + opts.skn, | ||
'Content-Type': 'application/atom+xml;type=entry;charset=utf-8', | ||
'Content-Type': 'application/atom+xml;type=entry;charset=utf-8' | ||
} | ||
@@ -59,10 +57,8 @@ } | ||
function callback(done) { | ||
return function inner(response) { | ||
function callback (done) { | ||
return function inner (response) { | ||
debug('response.statusCode =', response.statusCode) | ||
debug('response.statusMessage =', response.statusMessage) | ||
if (response.statusCode != 201) { | ||
// splitter.emit(`response error =`, response.statusMessage) | ||
console.log(`response error =`, response.statusMessage) | ||
if (response.statusCode !== 201) { | ||
splitter.emit('error', new Error(response.statusCode)) | ||
} | ||
@@ -81,5 +77,2 @@ | ||
const index = opts.index || 'pino' | ||
const type = opts.type || 'log' | ||
const writable = new Writable({ | ||
@@ -118,3 +111,2 @@ objectMode: true, | ||
console.error(`request error =`, e) | ||
done() | ||
}) | ||
@@ -126,3 +118,3 @@ req.write(line) | ||
} | ||
}, | ||
} | ||
}) | ||
@@ -134,77 +126,4 @@ | ||
} | ||
module.exports = { | ||
createSignature: createSignature, | ||
pinoEventHub: pinoEventHub, | ||
} | ||
function start (opts) { | ||
if (opts.help) { | ||
console.log(fs.readFileSync(path.join(__dirname, './usage.txt'), 'utf8')) | ||
return | ||
} | ||
if (opts.version) { | ||
console.log('pino-eventhub', require('./package.json').version) | ||
return | ||
} | ||
const ehn = opts['event-hub-namespace'] || process.env.PINO_EVENT_HUB_NAMESPACE | ||
const eh = opts['event-hub'] || process.env.PINO_EVENT_HUB | ||
const sapn = opts['shared-access-policy-name'] || process.env.PINO_SHARED_ACCESS_POLICY_NAME | ||
const sapk = opts['shared-access-policy-key'] || process.env.PINO_SHARED_ACCESS_POLICY_KEY | ||
const sas = opts['sas'] || process.env.PINO_SHARED_ACCESS_SIGNATURE | ||
if (!ehn || !eh || !sapn || (!sas && !sapk) ) { | ||
console.log(fs.readFileSync(path.join(__dirname, './usage.txt'), 'utf8')) | ||
console.log(" 1 or more missing required parameters 'event-hub-namespace', 'event-hub', 'shared-access-policy-name' and 'sas'.") | ||
if (!sas) { | ||
giveSecurityWarning() | ||
} | ||
return | ||
} | ||
if (opts.expiry && !Number.isNumber(opts.expiry)) { | ||
console.log(`"expiry" should be in unix date format`) | ||
return | ||
} | ||
const now = new Date() | ||
const week = 60*60*24*7 | ||
const host = 'https://' + ehn + '.servicebus.windows.net' | ||
// path = eh | ||
const uri = encodeURIComponent(host + '/' + eh) | ||
const se = opts.expiry || process.env.PINO_SAS_EXPIRY | ||
|| Math.round(now.getTime() / 1000) + week | ||
const options = Object.assign(opts, { | ||
host, | ||
eh, | ||
sr: uri, | ||
sig: sas || createSignature(uri, se, sapk, true), | ||
se, | ||
skn: sapn, | ||
}) | ||
pump(process.stdin, pinoEventHub(options)) | ||
} | ||
if (require.main === module) { | ||
start(minimist(process.argv.slice(2), { | ||
alias: { | ||
version: 'v', | ||
help: 'h', | ||
'event-hub-namespace': 's', | ||
'event-hub': 'e', | ||
'shared-access-policy-name': 'n', | ||
'shared-access-policy-key': 'k', | ||
'expiry': 'x', | ||
'sas': 'a', | ||
'bulk-size': 'b', | ||
'port': 'p', | ||
}, | ||
default: { | ||
port: 443, | ||
'bulk-size': 500, | ||
} | ||
})) | ||
} | ||
module.exports = pinoEventHub | ||
module.exports.createSignature = createSignature | ||
module.exports.giveSecurityWarning = giveSecurityWarning |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
15020
11
258
1
4
13
3
+ Addedbase64-stream@^0.1.3
+ Addedbase64-stream@0.1.5(transitive)
- Removedcrypto@^0.0.3
- Removedcrypto@0.0.3(transitive)