Skip to content

Commit

Permalink
Upgrade to sailor 2.6.19 (#4)
Browse files Browse the repository at this point in the history
* Upgrade to sailor 2.6.19
* Annual audit of the component code to check if it exposes sensitive data in the logs
* Annual npm vulnerabilities audit
  • Loading branch information
denyshld authored Dec 4, 2020
1 parent f114ea1 commit 1a77985
Show file tree
Hide file tree
Showing 11 changed files with 3,157 additions and 2,120 deletions.
10 changes: 10 additions & 0 deletions .circleci/build_slug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
echo "Building slug"
id=$(git archive $CIRCLE_BRANCH | docker run -e "NPM_CONFIG_PRODUCTION=false" -i -a stdin elasticio/appbuilder)
docker attach $id
RC=$?
if [ $RC -eq 0 ];then
echo "Build ok."
else
echo "Build failed"
exit 1
fi
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 2
jobs:
test:
docker:
- image: circleci/node:14-stretch
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Audit Dependencies
command: npm audit --audit-level=critical
- run:
name: Installing Dependencies
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Running Mocha Tests
command: npm test
workflows:
version: 2
build_and_test:
jobs:
- test
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
'extends': 'airbnb-base',
'env': {
'mocha': true
},
'rules' : {
'no-plusplus' : 'off',
},
};
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 0.0.2 (November 30, 2020)

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

## 0.0.1 (August 25, 2017)

* Initial release of OIH standardized component
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# edifact-parser-component [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
[![CircleCI](https://circleci.com/gh/elasticio/edifact-parser-component.svg?style=svg)](https://circleci.com/gh/elasticio/edifact-parser-component)
# edifact-parser-component
> Integration component for elastic.io that parses EDIFACT files
# edifact-parser-component
Expand Down
1 change: 1 addition & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"title": "EDIFACT Parser",
"description": "Integration component that parses EDIFACT files",
"buildType": "docker",
"actions": {
"parse": {
"title": "Parse",
Expand Down
88 changes: 46 additions & 42 deletions lib/actions/parse.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/* eslint new-cap: [2, {"capIsNewExceptions": ["Q"]}] */
const elasticio = require('elasticio-node');
const messages = elasticio.messages;

const { messages } = elasticio;
const edifact = require('edifact');
const request = require('request');

module.exports.process = processAction;

/**
* This method will be called from elastic.io platform providing following data
*
* @param msg incoming message object that contains ``body`` with payload
* @param cfg configuration that is account information and configuration field values
*/
function processAction(msg) {
console.log('Incoming message=%j', msg);
// eslint-disable-next-line consistent-return
async function processAction(msg) {
const self = this;
this.logger.info('Starting parse action...');
let fileURL;
const that = this;
if (msg && msg.attachments && Object.keys(msg.attachments).length > 0) {
var key = Object.keys(msg.attachments)[0];
console.log('Found attachment key=%s attachment=%j', key, msg.attachments[key]);
const key = Object.keys(msg.attachments)[0];
this.logger.info('Attachment found');
fileURL = msg.attachments[key].url;
} else {
console.error('URL of the EDI file is missing');
this.logger.error('URL of the EDI file is missing');
this.emit('error', 'URL of the EDI file is missing');
return this.emit('end');
}
Expand All @@ -32,59 +32,63 @@ function processAction(msg) {

const validator = new edifact.Validator();
const parser = new edifact.Parser(validator);
// eslint-disable-next-line global-require
validator.define(require('edifact/segments.js'));
// eslint-disable-next-line global-require
validator.define(require('edifact/elements.js'));

parser.on('opensegment', function (segment) {
parser.on('opensegment', (segment) => {
elements = [];
result.push({name: segment, elements: elements});
result.push({ name: segment, elements });
});

parser.on('closesegment', function () {});
parser.on('closesegment', () => {});

parser.on('element', function () {
parser.on('element', () => {
components = [];
elements.push(components);
});

parser.on('component', function (value) {
parser.on('component', (value) => {
components.push(value);
});

parser.encoding('UNOA');

parser.on('end', function () {
console.log('End!');
parser.on('end', () => {
this.logger.trace('Parser: \'end\'');
});

parser.on('error', err => this.emit('error', err));

console.log('Sending GET request to url=%s', fileURL);
this.logger.info('Sending GET request to provided url');
let content = '';
request.get(fileURL)
.on('response', function (response) {
console.log('Have got response status=%s headers=%j', response.statusCode, response.headers);
if (response.statusCode !== 200) {
that.emit('error', 'Unexpected response code code=' + response.statusCode);
throw Error('Unexpected response code code=' + response.statusCode);
}
})
.on('data', buffer => {
content += buffer.toString();
})
.on('error', err => {
that.emit('error', err);
that.emit('end');
})
.on('end', () => {
console.log('Parsing EDIFACT: %s', content);
parser.write(content);
parser.end();
const body = {
result: result
};
console.log('Parsing result: %j', body);
that.emit('data', messages.newMessageWithBody(body));
that.emit('end');
});
.on('response', (response) => {
self.logger.info('Have got response status=%s', response.statusCode);
if (response.statusCode !== 200) {
that.emit('error', `Unexpected response code code=${response.statusCode}`);
throw Error(`Unexpected response code code=${response.statusCode}`);
}
})
.on('data', (buffer) => {
content += buffer.toString();
})
.on('error', (err) => {
that.emit('error', err);
that.emit('end');
})
.on('end', async () => {
self.logger.info('Parsing EDIFACT...');
parser.write(content);
parser.end();
const body = {
result,
};
self.logger.info('Parsing completed');
await that.emit('data', messages.newMessageWithBody(body));
that.emit('end');
});
}

module.exports.process = processAction;
Loading

0 comments on commit 1a77985

Please sign in to comment.