serverless-es-proxy-logs
Advanced tools
Comparing version 3.0.7 to 3.0.8
{ | ||
"name": "serverless-es-proxy-logs", | ||
"version": "3.0.7", | ||
"version": "3.0.8", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A Serverless plugin to transport logs to ElasticSearch", |
// v1.1.2 | ||
var https = require('https'); | ||
var zlib = require('zlib'); | ||
var crypto = require('crypto'); | ||
import * as net from 'net'; | ||
var endpoint = process.env.ES_ENDPOINT; | ||
var indexPrefix = process.env.ES_INDEX_PREFIX; | ||
// TODO: Verify DLQ is empty | ||
// Disable TLS validation (want to remove this for production) | ||
// TODO: Pin proper CA. | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
var tags = undefined; | ||
@@ -40,26 +36,20 @@ try { | ||
// post documents to the Amazon Elasticsearch Service | ||
put(elasticsearchBulkPayload, function(error, success, statusCode, failedItems) { | ||
console.log('Response: ' + JSON.stringify({ | ||
"statusCode": statusCode | ||
})); | ||
//socket data | ||
console.log('connecting to socket ...'); | ||
const [url, port] = endpoint.split(':'); | ||
var client = new net.Socket(); | ||
client.connect(parseInt(port), url, function() { | ||
console.log('Successfully connected to es endpoint'); | ||
console.log('Emitting data', elasticsearchBulkPayload); | ||
client.write(elasticsearchBulkPayload); | ||
console.log('sent data'); | ||
}); | ||
if (error) { | ||
console.log('Error: ' + JSON.stringify(error, null, 2)); | ||
client.on('error', err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
if (failedItems && failedItems.length > 0) { | ||
console.log("Failed Items: " + | ||
JSON.stringify(failedItems, null, 2)); | ||
var failedLogs = findFailedLogs(failedItems, elasticsearchBulkArray); | ||
failedLogs.forEach( failedLog => { | ||
console.log("Failed log content: " + JSON.stringify(failedLog, null, 2)); | ||
}); | ||
} | ||
context.fail(JSON.stringify(error)); | ||
} else { | ||
console.log('Success: ' + JSON.stringify(success)); | ||
context.succeed('Success'); | ||
} | ||
client.on('close', function() { | ||
console.log('Connection closed'); | ||
}); | ||
@@ -69,18 +59,3 @@ }); | ||
function findFailedLogs(failedItems, esBulkArray) { | ||
var failedLogs = []; | ||
failedItems.forEach(item => { | ||
var _id = item && item.index && item.index._id; | ||
if (_id) { | ||
var failedLog = esBulkArray.find(esLog => esLog && esLog.id === _id); | ||
if (failedLog) { | ||
failedLogs.push(failedLog); | ||
} | ||
} | ||
}); | ||
return failedLogs; | ||
} | ||
function esDocumentArrayToPayload(esDocumentArray) { | ||
@@ -187,53 +162,1 @@ return esDocumentArray.map( | ||
} | ||
function put(body, callback) { | ||
var requestParams = buildRequest(endpoint, body); | ||
var request = https.request(requestParams, function(response) { | ||
var responseBody = ''; | ||
response.on('data', function(chunk) { | ||
responseBody += chunk; | ||
}); | ||
response.on('end', function() { | ||
var info = JSON.parse(responseBody); | ||
var failedItems; | ||
var success; | ||
if (response.statusCode >= 200 && response.statusCode < 299) { | ||
failedItems = info.items.filter(function(x) { | ||
return x.index.status >= 300; | ||
}); | ||
success = { | ||
"attemptedItems": info.items.length, | ||
"successfulItems": info.items.length - failedItems.length, | ||
"failedItems": failedItems.length | ||
}; | ||
} | ||
var error = response.statusCode !== 200 || info.errors === true ? { | ||
"statusCode": response.statusCode, | ||
"responseBody": responseBody | ||
} : null; | ||
callback(error, success, response.statusCode, failedItems); | ||
}); | ||
}).on('error', function(e) { | ||
callback(e); | ||
}); | ||
request.end(requestParams.body); | ||
} | ||
function buildRequest(endpoint, body) { | ||
const [ep, port] = endpoint.split(':'); | ||
return request = { | ||
host: ep, | ||
port: port, | ||
method: 'PUT', | ||
path: '/', | ||
body: JSON.stringify(body), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
} |
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
Network access
Supply chain riskThis module accesses the network.
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
Network access
Supply chain riskThis module accesses the network.
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
4
53615
669