Skip to content

Commit bdb2778

Browse files
authored
* Upgrade to sailor 2.6.18 (#5)
Upgrade to sailor 2.6.18
1 parent cec1047 commit bdb2778

File tree

11 files changed

+335
-134
lines changed

11 files changed

+335
-134
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker:
5+
- image: circleci/node:14-stretch
6+
steps:
7+
- checkout
8+
- restore_cache:
9+
key: dependency-cache-{{ checksum "package.json" }}
10+
- run:
11+
name: Audit Dependencies
12+
command: npm audit --audit-level=high
13+
- run:
14+
name: Installing Dependencies
15+
command: npm install
16+
- save_cache:
17+
key: dependency-cache-{{ checksum "package.json" }}
18+
paths:
19+
- node_modules
20+
- run:
21+
name: Running Integration Tests
22+
command: npm run integration-test
23+
24+
workflows:
25+
version: 2
26+
build_and_test:
27+
jobs:
28+
- test

.travis.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3.2 (November 5, 2020)
2+
3+
* Upgrade to sailor 2.6.18
4+
* Annual audit of the component code to check if it exposes a sensitive data in the logs
5+
* Annual npm vulnerabilities audit
6+
17
## 1.3.1 (May 22, 2020)
28

39
* Update sailor version to 2.6.7

lib/actions/publish.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const co = require('co');
21
const amqp = require('amqplib');
32
const logger = require('@elastic.io/component-logger')();
3+
44
const encryptor = require('../encryptor.js');
55

66
let channel;
@@ -10,18 +10,16 @@ let channel;
1010
*
1111
* @param cfg
1212
*/
13-
function init(cfg) {
13+
async function init(cfg) {
1414
logger.info('Starting initialization');
1515
const { amqpURI } = cfg;
1616
const amqpExchange = cfg.topic;
17-
return co(function* gen() {
18-
logger.debug('Connecting to amqpURI=%s', amqpURI);
19-
const conn = yield amqp.connect(amqpURI);
20-
logger.debug('Creating a confirm channel');
21-
channel = yield conn.createConfirmChannel();
22-
logger.debug('Asserting topic exchange exchange=%s', amqpExchange);
23-
yield channel.assertExchange(amqpExchange, 'topic');
24-
});
17+
logger.debug('Connecting to amqp...');
18+
const conn = await amqp.connect(amqpURI);
19+
logger.debug('Creating a confirm channel');
20+
channel = await conn.createConfirmChannel();
21+
logger.debug('Asserting topic exchange exchange...');
22+
await channel.assertExchange(amqpExchange, 'topic');
2523
}
2624

2725
/**
@@ -30,24 +28,23 @@ function init(cfg) {
3028
* @param msg incoming message object that contains ``body`` with payload
3129
* @param cfg configuration that is account information and configuration field values
3230
*/
33-
function processAction(msg, cfg) {
31+
async function processAction(msg, cfg) {
3432
const self = this;
3533
const amqpExchange = cfg.topic;
36-
return co(function* sendMessage() {
37-
self.logger.info('Publishing message id=%s', msg.id);
38-
const encryptedData = encryptor.encryptMessageContent(self, {
39-
body: msg.body.payload || msg.body,
40-
attachments: msg.attachments,
41-
});
42-
channel.publish(amqpExchange, msg.body.routingKey || '', encryptedData, {
43-
contentType: 'application/octet-stream',
44-
messageId: msg.id,
45-
});
46-
self.logger.info('Message published id=%s', msg.id);
47-
yield channel.waitForConfirms();
48-
self.logger.info('Message publishing confirmed id=%s', msg.id);
49-
return msg;
34+
35+
self.logger.info('Publishing message...');
36+
const encryptedData = encryptor.encryptMessageContent(self, {
37+
body: msg.body.payload || msg.body,
38+
attachments: msg.attachments,
39+
});
40+
channel.publish(amqpExchange, msg.body.routingKey || '', encryptedData, {
41+
contentType: 'application/octet-stream',
42+
messageId: msg.id,
5043
});
44+
self.logger.info('Message published');
45+
await channel.waitForConfirms();
46+
self.logger.info('Message publishing confirmed');
47+
return msg;
5148
}
5249

5350
module.exports.process = processAction;

lib/cipher.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable new-cap */
2-
32
const _ = require('lodash');
43
const crypto = require('crypto');
54

@@ -8,7 +7,7 @@ const PASSWORD = process.env.ELASTICIO_MESSAGE_CRYPTO_PASSWORD;
87
const VECTOR = process.env.ELASTICIO_MESSAGE_CRYPTO_IV;
98

109
function encryptIV(self, rawData) {
11-
self.logger.debug('About to encrypt:', rawData);
10+
self.logger.debug('About to encrypt raw data');
1211

1312
if (!_.isString(rawData)) {
1413
throw new Error('RabbitMQ message cipher.encryptIV() accepts only string as parameter.');
@@ -29,7 +28,7 @@ function encryptIV(self, rawData) {
2928
}
3029

3130
function decryptIV(self, encData) {
32-
self.logger.debug('About to decrypt:', encData);
31+
self.logger.debug('About to decrypt encrypted data');
3332

3433
if (!PASSWORD) {
3534
self.logger.info('Decryption will be skipped as ELASTICIO_MESSAGE_CRYPTO_PASSWORD env is empty');

lib/encryptor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function decryptMessageContent(self, messagePayload) {
1111
try {
1212
return JSON.parse(cipher.decrypt(self, messagePayload));
1313
} catch (err) {
14-
self.logger.error(err.stack);
14+
self.logger.error('Error occurred while message decrypt!');
1515
throw Error(`Failed to decrypt message: ${err.message}`);
1616
}
1717
}

lib/triggers/consume.js

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { messages } = require('elasticio-node');
2-
const co = require('co');
32
const amqp = require('amqplib');
43
const logger = require('@elastic.io/component-logger')();
4+
55
const encryptor = require('../encryptor.js');
66

77
let channel;
@@ -13,35 +13,34 @@ let listening;
1313
*
1414
* @param cfg
1515
*/
16-
function init(cfg) {
17-
logger.info('Starting initialization, queueName=%s', queueName);
16+
async function init(cfg) {
17+
logger.info('Starting initialization...');
1818
const { amqpURI } = cfg;
1919
const amqpExchange = cfg.topic;
2020
const keys = (cfg.bindingKeys || '#').split(',').map((s) => s.trim());
21-
return co(function* initialize() {
22-
logger.debug('Connecting to amqpURI=%s', amqpURI);
23-
const conn = yield amqp.connect(amqpURI);
24-
25-
logger.debug('Creating a receiver channel');
26-
channel = yield conn.createChannel();
21+
logger.debug('Connecting to amqpURI...');
22+
const conn = await amqp.connect(amqpURI);
2723

28-
logger.debug('Asserting topic exchange exchange=%s', amqpExchange);
29-
yield channel.assertExchange(amqpExchange, 'topic');
24+
logger.debug('Creating a receiver channel');
25+
channel = await conn.createChannel();
3026

31-
logger.debug('Asserting queue');
32-
yield channel.assertQueue(queueName, {
33-
exclusive: false,
34-
durable: false,
35-
autoDelete: true,
36-
});
27+
logger.debug('Asserting topic exchange exchange...');
28+
await channel.assertExchange(amqpExchange, 'topic');
3729

38-
// eslint-disable-next-line no-restricted-syntax
39-
for (const key of keys) {
40-
logger.debug(`Binding queue to exchange queue=${queueName} exchange=${amqpExchange} bindingKey=${key}`);
41-
yield channel.bindQueue(queueName, amqpExchange, key);
42-
}
43-
logger.info('Initialization completed');
30+
logger.debug('Asserting queue');
31+
await channel.assertQueue(queueName, {
32+
exclusive: false,
33+
durable: false,
34+
autoDelete: true,
4435
});
36+
37+
// eslint-disable-next-line no-restricted-syntax
38+
for (const key of keys) {
39+
logger.debug('Binding queue to exchange...');
40+
// eslint-disable-next-line no-await-in-loop
41+
await channel.bindQueue(queueName, amqpExchange, key);
42+
}
43+
logger.info('Initialization completed');
4544
}
4645

4746
/**
@@ -50,8 +49,8 @@ function init(cfg) {
5049
* @param msg incoming message object that contains ``body`` with payload
5150
* @param cfg configuration that is account information and configuration field values
5251
*/
53-
// eslint-disable-next-line no-unused-vars
54-
function processAction(msg, cfg) {
52+
// eslint-disable-next-line no-unused-vars,consistent-return
53+
async function processAction(msg, cfg) {
5554
const self = this;
5655
self.logger.info('Trigger started');
5756
if (listening) {
@@ -60,23 +59,21 @@ function processAction(msg, cfg) {
6059
}
6160
// eslint-disable-next-line no-shadow
6261
const consumer = (msg) => {
63-
self.logger.debug('Have got message fields=%j properties=%j', msg.fields, msg.properties);
62+
self.logger.debug('New message got');
6463
const decrypted = encryptor.decryptMessageContent(self, msg.content);
65-
self.logger.debug('Decrypted message=%j', decrypted);
64+
self.logger.debug('Message decrypted');
6665
const newMsg = messages.newMessageWithBody(decrypted.body || {});
6766
newMsg.id = msg.properties.messageId;
6867
newMsg.attachments = decrypted.attachments || {};
6968
self.emit('data', newMsg);
7069
};
71-
return co(function* consume() {
72-
self.logger.info('Starting consuming from %s', queueName);
73-
yield channel.consume(queueName, consumer, {
74-
noAck: true, // We can't really assert if message was consumed if we emit it yet
75-
consumerTag: `consumer_${process.env.ELASTICIO_EXEC_ID}_${process.env.ELASTICIO_FLOW_ID}`,
76-
});
77-
self.logger.info('Consumption started');
78-
listening = true;
70+
self.logger.info('Starting consuming from %s', queueName);
71+
await channel.consume(queueName, consumer, {
72+
noAck: true, // We can't really assert if message was consumed if we emit it yet
73+
consumerTag: `consumer_${process.env.ELASTICIO_EXEC_ID}_${process.env.ELASTICIO_FLOW_ID}`,
7974
});
75+
self.logger.info('Consumption started');
76+
listening = true;
8077
}
8178

8279
module.exports.process = processAction;

0 commit comments

Comments
 (0)