Skip to content

Commit bc48d20

Browse files
denyshlddenis.gladikov
andauthored
Upgrade to sailor 2.6.18 (#51)
* Upgrade to sailor 2.6.18 * Annual audit of the component code to check if it exposes a sensitive data in the logs * Annual npm vulnerabilities audit Co-authored-by: denis.gladikov <[email protected]>
1 parent aef21ef commit bc48d20

13 files changed

+311
-175
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ jobs:
77
- checkout
88
- restore_cache:
99
key: dependency-cache-{{ checksum "package.json" }}
10+
- run:
11+
name: Audit Dependencies
12+
command: npm audit --audit-level=high
1013
- run:
1114
name: Installing Dependencies
1215
command: npm install

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.4.1 (November 12, 2020)
2+
3+
## General Changes
4+
* Upgrade to sailor 2.6.18
5+
* Annual audit of the component code to check if it exposes a sensitive data in the logs
6+
* Annual npm vulnerabilities audit
7+
18
# 1.4.0 (June 5, 2020)
29

310
## General Changes

lib/StatelessBasicAuthRestClient.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const request = promisify(require('requestretry'));
55
const rawRequest = require('request');
66
const removeTrailingSlash = require('remove-trailing-slash');
77
const removeLeadingSlash = require('remove-leading-slash');
8-
const debug = require('debug')('Rest-Client');
8+
9+
let staticLogger;
910

1011
const NoAuthRestClient = class NoAuthRestClient {
1112
constructor(emitter, cfg) {
13+
staticLogger = emitter.logger;
1214
this.emitter = emitter;
1315
this.cfg = cfg;
1416
}
@@ -23,7 +25,7 @@ const NoAuthRestClient = class NoAuthRestClient {
2325
const urlToCall = urlIsSegment
2426
? `${removeTrailingSlash(this.cfg.resourceServerUrl.trim())}/${removeLeadingSlash(url.trim())}`
2527
: url.trim();
26-
this.emitter.logger.info(`Making ${method} request to ${urlToCall} ...`);
28+
this.emitter.logger.info(`Making ${method} request...`);
2729

2830
const requestOptions = {
2931
url: urlToCall,
@@ -68,8 +70,9 @@ const NoAuthRestClient = class NoAuthRestClient {
6870
stream.pipe(inputStream);
6971
}
7072
})
73+
// eslint-disable-next-line no-unused-vars
7174
.on('error', (err) => {
72-
self.emitter.logger.error(err);
75+
self.emitter.logger.error('Error on making request');
7376
counter += 1;
7477
setTimeout(retryRequest.bind(this), 3000, options, retryCnt, inputStream);
7578
});
@@ -80,7 +83,7 @@ module.exports.NoAuthRestClient = NoAuthRestClient;
8083

8184
function onAnyErrorRetryStrategy(err, response) {
8285
const checkResult = err || response.statusCode >= 404;
83-
debug('Client failed making request: %s, Retrying: %s', err, checkResult);
86+
staticLogger.error('Client failed making request: %s, Retrying: %s', err, checkResult);
8487
return checkResult;
8588
}
8689

lib/actions/deleteObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exports.process = async function (msg, cfg) {
1313
this.logger.warn('Provided filename is not found: nothing to delete');
1414
return messages.newEmptyMessage();
1515
}
16-
this.logger.error('Error occurred while getting file metadata: %j', err);
16+
this.logger.error('Error occurred while getting file metadata!');
1717
throw err;
1818
}
1919

lib/actions/renameObject.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,34 @@ function checkFieldNotFolder(fieldName, fieldValue) {
2121
}
2222
// eslint-disable-next-line func-names
2323
exports.process = async function (msg, cfg) {
24+
this.logger.info('Starting rename object action...');
2425
const client = new Client(this.logger, cfg);
2526
const { bucketName, oldFileName, newFileName } = msg.body;
2627
checkFieldNotFolder('bucketName', bucketName);
2728
checkFieldNotFolder('oldFileName', oldFileName);
2829
checkFieldNotFolder('newFileName', newFileName);
2930
const folder = formatFolder(msg.body.folder);
30-
this.logger.info(`Found params oldFileName: ${oldFileName}, newFileName: ${newFileName}, bucketName: ${bucketName}, folder: ${folder}`);
3131
const fullOldFileName = `${folder || ''}${oldFileName}`;
3232
const fullNewFileName = `${folder || ''}${newFileName}`;
33-
this.logger.info(`Starting rename file ${fullOldFileName} to ${fullNewFileName} in bucket: ${bucketName}`);
3433
const oldFile = await client.getFileFromBucket(bucketName, fullOldFileName);
35-
this.logger.trace(`Old file: ${JSON.stringify(oldFile)}`);
3634
if (oldFile) {
3735
let newFile = await client.getFileFromBucket(bucketName, fullNewFileName);
3836
if (!newFile) {
3937
const copySource = `${bucketName}/${fullOldFileName}`;
40-
this.logger.trace(`Starting copyObject: ${copySource}`);
38+
this.logger.trace('Starting copyObject...');
4139
const copyResult = await client.copyObject(copySource, bucketName, fullNewFileName);
42-
this.logger.trace(`copyResult ${JSON.stringify(copyResult)}`);
40+
this.logger.trace('CopyResult received');
4341
newFile = await client.getFileFromBucket(bucketName, fullNewFileName);
44-
this.logger.trace(`New file: ${JSON.stringify(newFile)}`);
4542
if (newFile) {
46-
this.logger.trace(`Starting delete old file: ${fullOldFileName}`);
43+
this.logger.trace('Starting delete old file...');
4744
await client.deleteObject(bucketName, fullOldFileName);
4845
this.logger.info('File successfully renamed');
4946
await this.emit('data', messages.newMessageWithBody(newFile));
5047
} else {
5148
throw new Error(`Error occurred while copying a file: ${copyResult}`);
5249
}
5350
} else {
54-
this.logger.trace(`Exists file: ${JSON.stringify(newFile)}`);
55-
throw new Error(`File with name ${fullNewFileName} is already exists in bucket ${bucketName}`);
51+
throw new Error('File is already exists in provided bucket!');
5652
}
5753
} else {
5854
throw new Error(`File with name ${fullOldFileName} doesn't exists in bucket ${bucketName}`);

lib/actions/streamToCsv.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function processAction(msg, cfg) {
4444
_.map(columnConfig, (column) => {
4545
columns[column.property] = column.title;
4646
});
47-
self.logger.info('Processing following column configuration columns=%j', columns);
4847
const stringifier = csvParser.stringify({ header: true, columns });
4948
const upload = streamClient.upload({
5049
Bucket: cfg.bucketName,
@@ -81,7 +80,7 @@ function processAction(msg, cfg) {
8180
}
8281

8382
function emitError(e) {
84-
self.logger.info('Oops! Error occurred', e.stack || e);
83+
self.logger.error('Oops! Error occurred!');
8584
self.emit('error', e);
8685
}
8786

lib/actions/streamToFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { Client } = require('../client');
66
const { NoAuthRestClient } = require('../StatelessBasicAuthRestClient');
77

88
exports.process = async function (msg, cfg) {
9-
this.logger.trace('Input: %j', JSON.stringify(msg));
9+
this.logger.trace('Starting stream to file action..');
1010
const client = new Client(this.logger, cfg);
1111
const bucketName = msg.body.bucketName ? msg.body.bucketName : cfg.bucketName;
1212

@@ -25,7 +25,7 @@ exports.process = async function (msg, cfg) {
2525
};
2626
});
2727

28-
this.logger.trace('trying to get attachment from %j', attachments[0].url.url);
28+
this.logger.trace('Trying to get attachment...');
2929

3030
const passthrough = new PassThrough();
3131

lib/client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ class Client {
2828
}
2929

3030
async getFileFromBucket(bucketName, fileName) {
31-
this.logger.info(`Finding file ${fileName} in bucket: ${bucketName}`);
31+
this.logger.info('Searching for file in bucket');
3232
const params = {
3333
Bucket: bucketName,
3434
Delimiter: '/',
3535
Prefix: fileName,
3636
};
3737
const data = await this.s3.listObjects(params).promise();
38-
this.logger.trace(`Found data: ${JSON.stringify(data)}`);
3938
const foundFiles = data.Contents.filter((item) => item.Key === fileName);
40-
this.logger.trace(`Found file: ${JSON.stringify(foundFiles)}`);
39+
this.logger.trace('Filtering complete');
4140
if (foundFiles.length !== 1) {
41+
this.logger.trace('No files with provided name');
4242
return null;
4343
}
44+
this.logger.trace('File was found');
4445
return foundFiles[0];
4546
}
4647

lib/utils/attachmentProcessor.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function addAttachment(msg, name, body, contentType) {
1717
}
1818

1919
async function uploadFile(urls) {
20-
self.logger.debug('Trying to upload file: %j', body);
20+
self.logger.debug('Trying to upload file...');
2121

2222
const stream = new Readable();
2323
stream.push(body.toString());
@@ -36,10 +36,7 @@ function addAttachment(msg, name, body, contentType) {
3636
}
3737

3838
return getUrlsManualy().then((result) => {
39-
self.logger.debug('createSignedUrl result: %j', result);
40-
self.logger.debug('Uploading to url: %s', result.put_url);
41-
self.logger.debug('Content-Type: %s', contentType);
42-
self.logger.info('uploadFile is about to execute');
39+
self.logger.debug('Uploading file with content type %s ...', contentType);
4340
return uploadFile(result, contentType);
4441
});
4542
}

lib/utils/pollingUtil.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class AwsS3Polling extends PollingTrigger {
3131
for (let i = 0; i < files.length; i += 1) {
3232
const file = files[i];
3333
try {
34-
this.logger.info('Processing file with name: %s, size: %d', file.Key, file.Size);
34+
this.logger.info('Processing file with size: %d', file.Size);
3535
const resultMessage = messages.newMessageWithBody(file);
3636

3737
if (this.cfg.enableFileAttachments) {
3838
await this.s3FileToAttachment(resultMessage, path.basename(file.Key), file.Size);
3939
}
4040

41-
this.logger.trace('Emitting new message with body: %j', resultMessage.body);
41+
this.logger.trace('Emitting new message with data...');
4242
await this.context.emit('data', resultMessage);
4343
} catch (e) {
4444
await this.context.emit('error', e);
@@ -64,16 +64,16 @@ class AwsS3Polling extends PollingTrigger {
6464
resultMessage.attachments = attachments;
6565
}
6666

67-
this.logger.trace('Emitting new message with body: %j', resultMessage.body);
67+
this.logger.trace('Emitting new message with data...');
6868
await this.context.emit('data', resultMessage);
6969
this.logger.info('Finished emitting data');
7070
}
7171

7272
async s3FileToAttachment(msg, filename, size) {
73-
this.logger.info('Adding file %s to attachment...', filename);
73+
this.logger.info('Adding file to attachment...');
7474
const s3Stream = this.client.getObjectReadStream(this.cfg.bucketName, filename);
7575
const uploadResult = await this.attachmentProcessor.uploadAttachment(s3Stream);
76-
this.logger.info('File %s successfully uploaded to URL: %s', filename, uploadResult.config.url);
76+
this.logger.info('File successfully uploaded to attachment storage');
7777

7878
/* eslint-disable-next-line no-param-reassign */
7979
msg.attachments = {

0 commit comments

Comments
 (0)