Skip to content

Commit

Permalink
Upgrade to sailor 2.6.18 (#42)
Browse files Browse the repository at this point in the history
Upgrade to sailor 2.6.18
Delete sensitive data from logs
  • Loading branch information
denyshld authored Oct 29, 2020
1 parent 8bfc7c7 commit bfe916a
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 122 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.3.3 (October 30, 2020)

* Upgrade to sailor 2.6.18
* Annual audit of the component code to check if it exposes a sensitive data in the logs

## 1.3.2 (June 6, 2020)

* Remove update docs on deploy script
Expand Down
13 changes: 6 additions & 7 deletions lib/actions/attachmentToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ function checkFileName(self, fileName, pattern) {
}

if (!pattern.test(fileName)) {
self.logger.debug('%s does not match pattern: \'%s\'', fileName, pattern);
self.logger.debug('Filename does not match pattern');
return false;
}

if (fileName.split('.').pop() !== 'xml') {
self.logger.debug('%s is not .xml file: ', fileName);
self.logger.debug('Provided fileName is not .xml file');
return false;
}

Expand All @@ -40,14 +40,14 @@ module.exports.process = async function processAction(msg, cfg) {
const fileName = key;
// get file size based attachment object may not be define or be accurate
let fileSize = attachment.size;
self.logger.info('Processing attachment=%s', fileName);
self.logger.info('Processing attachment');

if (checkFileName(self, fileName, pattern)) {
if (fileSize === undefined || fileSize < MAX_FILE_SIZE) {
// eslint-disable-next-line no-await-in-loop
const response = await new AttachmentProcessor().getAttachment(attachment.url, 'arraybuffer');

this.logger.debug(`For filename ${fileName} Response status: ${response.status} Response headers: ${JSON.stringify(response.headers)}`);
this.logger.debug(`For provided filename response status: ${response.status}`);

if (response.status >= 400) {
throw new Error(`Error in making request to ${attachment.url}
Expand All @@ -61,12 +61,11 @@ module.exports.process = async function processAction(msg, cfg) {
throw new Error(`Empty attachment received for file ${fileName}`);
}

this.logger.debug(`For filename ${fileName} Response Body string: ${responseBodyString}`);
fileSize = sizeof(responseBodyString);

if (fileSize < MAX_FILE_SIZE) {
const returnMsg = await xml2Json.process(this, responseBodyString);
this.logger.debug(`For filename ${fileName} Result of XML Conversion: ${JSON.stringify(returnMsg)}`);
this.logger.debug('Attachment to XML finished');
foundXML = true;
await self.emit('data', messages.newMessageWithBody(returnMsg.body));
} else {
Expand All @@ -80,6 +79,6 @@ module.exports.process = async function processAction(msg, cfg) {
}
}
if (!foundXML) {
self.logger.info(`No XML files that match the pattern found with in attachments. Pattern: ${pattern}`);
self.logger.info('No XML files that match the pattern found within attachments');
}
};
2 changes: 1 addition & 1 deletion lib/actions/jsonToXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports.process = async function process(msg, cfg) {
const attachmentProcessor = new AttachmentProcessor();
const uploadResult = await attachmentProcessor.uploadAttachment(xmlString);
const attachmentUrl = uploadResult.config.url;
this.logger.info(`Successfully created attachment at ${attachmentUrl}`);
this.logger.info('Attachment created successfully');

const outboundMessage = messages.newEmptyMessage();
outboundMessage.attachments = {
Expand Down
6 changes: 3 additions & 3 deletions lib/actions/jsonToXmlOld.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint no-invalid-this: 0 no-console: 0 */
const eioUtils = require('elasticio-node').messages;
const xml2js = require('xml2js');
const _ = require('lodash');
Expand Down Expand Up @@ -41,8 +40,9 @@ function validateJsonPropNames(value, key) {
* @param msg incoming message object that contains ``body`` with payload
* @param cfg configuration that is account information and configuration field values
*/
// eslint-disable-next-line no-unused-vars
function processAction(msg, cfg) {
this.logger.debug('Action started, message=%j cfg=%j', msg, cfg);
this.logger.debug('Action started...');
const options = {
trim: false,
normalize: false,
Expand All @@ -60,7 +60,7 @@ function processAction(msg, cfg) {
validateJsonPropNames(jsonToTransform);

const result = builder.buildObject(jsonToTransform);
this.logger.debug('Successfully converted body to XML result=%s', result);
this.logger.debug('Successfully converted body to XML');
return eioUtils.newMessageWithBody({
xmlString: result,
});
Expand Down
17 changes: 8 additions & 9 deletions lib/actions/parse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint no-invalid-this: 0 no-console: 0 */
const elasticio = require('elasticio-node');

const { messages } = elasticio;
Expand All @@ -18,7 +17,7 @@ let unmarshaller;
*/
module.exports.process = function processAction(msg, cfg) {
co(function* gen() {
this.logger.debug('Action started cfg=%j', cfg);
this.logger.debug('Action started...');
// We need to make sure we execute initialization only once
yield lock.acquireAsync();
try {
Expand All @@ -31,9 +30,10 @@ module.exports.process = function processAction(msg, cfg) {
-compact \
-logLevel DEBUG \
"${cfg.schemaUri}"`;
this.logger.debug('Starting JAVA process cmd=%s', cmd);
this.logger.debug('Starting JAVA process...');
// eslint-disable-next-line no-unused-vars
const out = yield exec(cmd);
this.logger.debug('%s\nGeneration completed', out);
this.logger.debug('Generation completed');
this.logger.debug('Loading mappings from ./mappings/index.js');
// eslint-disable-next-line global-require, import/no-unresolved
const mappings = require('../../mappings');
Expand All @@ -50,18 +50,17 @@ module.exports.process = function processAction(msg, cfg) {
if (msg.body.xml && typeof msg.body.xml === 'string') {
this.logger.info('Found input data in incoming message length of XML is length=%s', msg.body.xml.length);
const result = unmarshaller.unmarshalString(msg.body.xml);
this.logger.debug('Parsed XML to JSON json=%j', result);
this.logger.debug('XML parsed to JSON');
this.emit('data', messages.newMessageWithBody(result));
} else if (msg.attachments && Object.keys(msg.attachments).length > 0) {
this.logger.info('Found attachments in the message keys=%s', Object.keys(msg.attachments));
this.logger.info(`Found attachments in the message keys=${Object.keys(msg.attachments).length}`);
this.emit('data', msg);
} else {
this.logger.debug('No data XML payload found in the incoming message or it\'s attachments, '
+ 'no processing will be done msg=%j', msg);
this.logger.debug('No data XML payload found in the incoming message or it\'s attachments');
}
this.emit('end');
}.bind(this)).catch((err) => {
this.logger.info('Error occurred', err.stack || err);
this.logger.info('Error in parsing occurred');
this.emit('error', err);
this.emit('end');
});
Expand Down
3 changes: 1 addition & 2 deletions lib/actions/xmlToJson.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint no-invalid-this: 0 no-console: 0 */
const xml2Json = require('../xml2Json.js');

/**
Expand All @@ -7,8 +6,8 @@ const xml2Json = require('../xml2Json.js');
* @param msg incoming message object that contains ``body`` with payload
* @param cfg configuration that is account information and configuration field values
*/
// eslint-disable-next-line no-unused-vars
module.exports.process = function processAction(msg, cfg) {
this.logger.trace('Action started, message=%j cfg=%j', msg, cfg);
if (!msg.body || !msg.body.xmlString) {
this.emit('error', 'Missing XML String as input');
this.emit('end');
Expand Down
2 changes: 1 addition & 1 deletion lib/xml2Json.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports.process = async function xml2Json(self, xmlString) {
return new Promise(((resolve, reject) => {
parser.parseString(xmlString, (err, data) => {
if (err) {
self.logger.info('Error occurred', err.stack || err);
self.logger.info('Error in xml2Json occurred');
reject(new Error(invalidXmlMessage));
} else {
self.logger.info('Successfully converted XML to JSON');
Expand Down
Loading

0 comments on commit bfe916a

Please sign in to comment.