Skip to content

Commit 22b4992

Browse files
Olha Virolainendenyshld
authored andcommitted
Update sailor to 2.5.4 (#33)
1 parent 77d205a commit 22b4992

File tree

11 files changed

+52
-35
lines changed

11 files changed

+52
-35
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# 1.2.0 (December , 2019)
1+
# 1.2.1 (December 26, 2019)
2+
3+
## General Changes
4+
* Update sailor version to 2.5.4
5+
6+
# 1.2.0 (December 19, 2019)
27

38
## General Changes
49
* Add `Rename file` action

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ The component is based on [AWS S3 SDK](https://aws.amazon.com/sdk-for-node-js/ '
4141

4242
#### Environment variables
4343
For integration-tests is required to specify following environment variables:
44+
4445
`ACCESS_KEY_ID` - access key ID;
46+
4547
`ACCESS_KEY_SECRET` - secret access key.
48+
4649
`REGION` - region.
4750

51+
For debugging purposes there is:
52+
53+
`LOG_LEVEL` - `trace` | `debug` | `info` | `warning` | `error` that controls logger level.
54+
4855
## Credentials
4956
Access keys consist of two parts: an access key ID and a secret access key.
5057
Like a user name and password, you must use both the access key ID and secret access key together to authenticate your requests.

lib/StatelessBasicAuthRestClient.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable no-param-reassign,no-underscore-dangle,no-console */
1+
/* eslint-disable no-param-reassign,no-underscore-dangle */
22
// eslint-disable-next-line max-classes-per-file
33
const { promisify } = require('util');
44
const request = promisify(require('requestretry'));
@@ -23,7 +23,7 @@ const NoAuthRestClient = class NoAuthRestClient {
2323
const urlToCall = urlIsSegment
2424
? `${removeTrailingSlash(this.cfg.resourceServerUrl.trim())}/${removeLeadingSlash(url.trim())}`
2525
: url.trim();
26-
console.log(`Making ${method} request to ${urlToCall} ...`);
26+
this.emitter.logger.info(`Making ${method} request to ${urlToCall} ...`);
2727

2828
const requestOptions = {
2929
url: urlToCall,
@@ -50,13 +50,14 @@ const NoAuthRestClient = class NoAuthRestClient {
5050

5151
// eslint-disable-next-line class-methods-use-this
5252
getRequest() {
53+
const self = this;
5354
let counter = 0;
5455
return function retryRequest(options, retryCnt, inputStream) {
5556
if (counter === retryCnt) {
5657
inputStream.end();
5758
return;
5859
}
59-
console.log('Client failed making request, attempt: %s', counter);
60+
self.emitter.logger.info('Client failed making request, attempt: %s', counter);
6061
const stream = rawRequest(options)
6162
.on('response', (response) => {
6263
if ((response.statusCode >= 404 || response.toString().trim()
@@ -68,7 +69,7 @@ const NoAuthRestClient = class NoAuthRestClient {
6869
}
6970
})
7071
.on('error', (err) => {
71-
console.error(err);
72+
self.emitter.logger.error(err);
7273
counter += 1;
7374
setTimeout(retryRequest.bind(this), 3000, options, retryCnt, inputStream);
7475
});

lib/actions/readFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports.process = async function (msg, cfg) {
2424
const xmlDoc = JSON.parse(convert.xml2json(fileContent));
2525
await this.emit('data', messages.newMessageWithBody(xmlDoc));
2626
} else {
27-
const response = await attachmentProcessor.addAttachment(msg, filename,
27+
const response = await attachmentProcessor.addAttachment.call(this, msg, filename,
2828
fileContent, contentType);
2929
const output = messages.newMessageWithBody(response);
3030
output.attachments = response.attachments;

lib/actions/streamToCsv.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function processAction(msg, cfg) {
4444
_.map(columnConfig, (column) => {
4545
columns[column.property] = column.title;
4646
});
47-
console.log('Processing following column configuration columns=%j', columns);
47+
self.logger.info('Processing following column configuration columns=%j', columns);
4848
const stringifier = csvParser.stringify({ header: true, columns });
4949
const upload = streamClient.upload({
5050
Bucket: cfg.bucketName,
@@ -55,9 +55,9 @@ function processAction(msg, cfg) {
5555
outStream = stringifier;
5656
// Register shutdown hook
5757
process.on('exit', () => {
58-
console.log('Shutting down');
58+
self.logger.info('Shutting down');
5959
stringifier.end();
60-
console.log('Shutdown completed');
60+
self.logger.info('Shutdown completed');
6161
});
6262
}
6363
return outStream;
@@ -67,7 +67,7 @@ function processAction(msg, cfg) {
6767
stream.write(msg.body);
6868
counter++;
6969
if (counter >= 10000) {
70-
console.log('Flushing the log file');
70+
self.logger.info('Flushing the log file');
7171
outStream.end();
7272
outStream = null;
7373
counter = 0;
@@ -81,12 +81,12 @@ function processAction(msg, cfg) {
8181
}
8282

8383
function emitError(e) {
84-
console.log('Oops! Error occurred', e.stack || e);
84+
self.logger.info('Oops! Error occurred', e.stack || e);
8585
self.emit('error', e);
8686
}
8787

8888
function emitEnd() {
89-
console.log('Finished execution');
89+
self.logger.info('Finished execution');
9090
self.emit('end');
9191
}
9292

lib/utils/attachmentProcessor.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
/* eslint-disable no-use-before-define,no-param-reassign,no-console */
2-
const debug = require('debug')('attachment');
1+
/* eslint-disable no-param-reassign */
32
const request = require('request');
43
const { Readable } = require('stream');
54
const { BasicAuthRestClient } = require('../StatelessBasicAuthRestClient');
65

7-
exports.addAttachment = addAttachment;
8-
96
function addAttachment(msg, name, body, contentType) {
10-
return getUrlsManualy().then((result) => {
11-
debug('createSignedUrl result: %j', result);
12-
debug('Uploading to url: %s', result.put_url);
13-
debug('Content-Type: %s', contentType);
14-
console.log('uploadFile is about to execute');
15-
return uploadFile(result, contentType);
16-
});
17-
7+
const self = this;
188
async function getUrlsManualy() {
19-
const attachmentClient = new BasicAuthRestClient(this, {
9+
const attachmentClient = new BasicAuthRestClient(self, {
2010
resourceServerUrl: 'http://api-service.platform.svc.cluster.local.:9000',
2111
}, process.env.ELASTICIO_API_USERNAME, process.env.ELASTICIO_API_KEY);
2212

@@ -27,7 +17,7 @@ function addAttachment(msg, name, body, contentType) {
2717
}
2818

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

3222
const stream = new Readable();
3323
stream.push(body.toString());
@@ -44,4 +34,14 @@ function addAttachment(msg, name, body, contentType) {
4434
};
4535
return msg;
4636
}
37+
38+
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');
43+
return uploadFile(result, contentType);
44+
});
4745
}
46+
47+
exports.addAttachment = addAttachment;

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amazon-s3-component",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "elastic.io integration component that can read and write to AWS S3",
55
"homepage": "http://elastic.io",
66
"author": {
@@ -34,7 +34,7 @@
3434
"csv": "0.4.6",
3535
"debug": "2.6.9",
3636
"elasticio-node": "0.0.9",
37-
"elasticio-sailor-nodejs": "2.5.1",
37+
"elasticio-sailor-nodejs": "2.5.4",
3838
"iconv-lite": "0.4.24",
3939
"lodash": "4.17.11",
4040
"mime-types": "2.1.21",

spec-integration/readFile.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable func-names */
22
const chai = require('chai');
33
const sinon = require('sinon');
4+
const bunyan = require('bunyan');
45
const readFile = require('../lib/actions/readFile');
56
const { BasicAuthRestClient } = require('../lib/StatelessBasicAuthRestClient');
67
require('dotenv').config();
@@ -16,8 +17,11 @@ const defaultCfg = {
1617

1718
const defaultMsg = {};
1819

20+
const logger = bunyan.createLogger({ name: 'readFile', level: 'info' });
21+
1922
const self = {
2023
emit: sinon.spy(),
24+
logger,
2125
};
2226

2327
describe('readFile', () => {

spec-integration/renameObject.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const sinon = require('sinon');
66
const { expect } = chai;
77
const bunyan = require('bunyan');
88

9-
const logger = bunyan.createLogger({ name: 'RenameFile', level: 'trace' });
9+
const logger = bunyan.createLogger({ name: 'RenameFile', level: 'info' });
1010
const { Client } = require('../lib/client');
1111
const renameFile = require('../lib/actions/renameObject');
1212

0 commit comments

Comments
 (0)