Skip to content

Commit

Permalink
Merge pull request #55 from elasticio/user-agent
Browse files Browse the repository at this point in the history
User agent
  • Loading branch information
olegosh authored Sep 9, 2022
2 parents a485557 + cfd0f58 commit 284a6c3
Show file tree
Hide file tree
Showing 13 changed files with 1,390 additions and 846 deletions.
112 changes: 56 additions & 56 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,82 +13,82 @@ commands:
event: fail
custom: |
{
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": ":red_circle: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* build failed"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": ":red_circle: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* build failed"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
}
notify_on_pass:
steps:
- slack/notify:
event: pass
custom: |
{
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": ":tada: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* was successfully built and published"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": ":tada: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* was successfully built and published"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${CIRCLE_BUILD_URL}"
}
]
}
]
}
jobs:
test:
docker: # run the steps with Docker
- image: cimg/base:stable
docker:
- image: circleci/node:16-stretch
steps:
- checkout
- node/install:
node-version: << pipeline.parameters.node-version >>
- node/install-packages:
cache-path: ./node_modules
override-ci-command: npm install
- run:
name: Audit Dependencies
command: npm audit --production --audit-level=high
- node/install-packages:
cache-path: ./node_modules
override-ci-command: npm install
- run:
name: test
name: Running Mocha Tests
command: npm test
build:
docker:
- image: cimg/base:stable
- image: circleci/node:16-stretch
user: root
steps:
- checkout
Expand Down Expand Up @@ -122,4 +122,4 @@ workflows:
branches:
ignore: /.*/
tags:
only: /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
only: /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
21 changes: 16 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
module.exports = {
'extends': 'airbnb-base',
'env': {
'mocha': true,
'node': true,
}
extends: 'airbnb-base',
env: {
mocha: true,
},
rules: {
'no-plusplus': 1,
'max-len': ['error', { code: 160 }],
quotes: ['error', 'single'],
'no-await-in-loop': 1,
'no-restricted-syntax': 1,
camelcase: 0,
'no-restricted-globals': 1,
'no-lonely-if': 0,
'consistent-return': 1,
'no-prototype-builtins': 0,
},
};
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.3.6 (September 09, 2022)

* Update Sailor version to 2.6.29
* Get rid of vulnerabilities in dependencies
* Update component-commons-library version to 3.0.2

## 1.3.5 (April 13, 2022)

* Update Sailor version to 2.6.27
Expand Down
9 changes: 4 additions & 5 deletions component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "XML",
"version": "1.3.5",
"version": "1.3.6",
"description": "Component to convert between XML and JSON data",
"buildType": "docker",
"actions": {
Expand All @@ -9,7 +9,7 @@
"main": "./lib/actions/xmlToJson.js",
"help": {
"description": "Takes XML string and converts it to generic JSON object",
"link": "/components/xml/index.html#xml-to-json"
"link": "/components/xml/index.html#xml-to-json"
},
"metadata": {
"in": "./lib/schemas/xmlToJson.in.json",
Expand All @@ -32,7 +32,7 @@
"title": "JSON to XML",
"main": "./lib/actions/jsonToXml.js",
"help": {
"link": "/components/xml/index.html#json-to-xml",
"link": "/components/xml/index.html#json-to-xml",
"description": "Takes the result of a JSONata expression and creates corresponding XML as either a string or an attachment"
},
"fields": {
Expand Down Expand Up @@ -89,7 +89,7 @@
"title": "XML Attachment to JSON",
"main": "./lib/actions/attachmentToJson.js",
"help": {
"link": "/components/xml/index.html#xml-attachment-to-json",
"link": "/components/xml/index.html#xml-attachment-to-json",
"description": "Looks at the JSON array of attachments passed in to component and converts all XML found to generic JSON object"
},
"fields": {
Expand All @@ -107,4 +107,3 @@
}
}
}

6 changes: 4 additions & 2 deletions lib/actions/attachmentToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
const sizeof = require('object-sizeof');
const { AttachmentProcessor } = require('@elastic.io/component-commons-library');
const { messages } = require('elasticio-node');
const { getUserAgent } = require('../utils');

const xml2Json = require('../xml2Json.js');
const xml2Json = require('../xml2Json');

const MAX_FILE_SIZE = 5242880; // 5 MiB

Expand Down Expand Up @@ -34,6 +35,7 @@ module.exports.process = async function processAction(msg, cfg) {
self.logger.info('Attachment to XML started');
self.logger.info('Found %s attachments', Object.keys(attachments || {}).length);

const attachmentProcessor = new AttachmentProcessor(getUserAgent(), msg.id);
// eslint-disable-next-line no-restricted-syntax
for (const key of Object.keys(attachments)) {
const attachment = attachments[key];
Expand All @@ -45,7 +47,7 @@ module.exports.process = async function processAction(msg, cfg) {
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');
const response = await attachmentProcessor.getAttachment(attachment.url, 'arraybuffer');

this.logger.debug(`For provided filename response status: ${response.status}`);

Expand Down
11 changes: 6 additions & 5 deletions lib/actions/jsonToXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { AttachmentProcessor } = require('@elastic.io/component-commons-library')
const { messages } = require('elasticio-node');
const xml2js = require('xml2js');
const _ = require('lodash');
const { getUserAgent } = require('../utils');

const MB_TO_BYTES = 1024 * 1024;
const MAX_FILE_SIZE = process.env.MAX_FILE_SIZE * MB_TO_BYTES || 10 * MB_TO_BYTES;
Expand Down Expand Up @@ -33,7 +34,8 @@ module.exports.process = async function process(msg, cfg) {
throw new Error('Input must be an object with exactly one key.');
}

const xmlString = builder.buildObject(input);
const xml2String = () => builder.buildObject(input);
const xmlString = xml2String();

if (!uploadToAttachment) {
this.logger.info('Sending XML data in message.');
Expand All @@ -49,10 +51,9 @@ module.exports.process = async function process(msg, cfg) {
}
this.logger.info(`Will create XML attachment of size ${attachmentSize} byte(s)`);

const attachmentProcessor = new AttachmentProcessor();
const uploadResult = await attachmentProcessor.uploadAttachment(xmlString, 'stream');
const attachmentId = uploadResult.data.objectId;
const attachmentUrl = `${uploadResult.config.url}${attachmentId}?storage_type=maester`;
const attachmentProcessor = new AttachmentProcessor(getUserAgent(), msg.id);
const createdAttachmentId = await attachmentProcessor.uploadAttachment(xml2String);
const attachmentUrl = attachmentProcessor.getMaesterAttachmentUrlById(createdAttachmentId);
this.logger.info('Attachment created successfully');

const outboundMessage = messages.newEmptyMessage();
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports.process = function processAction(msg, cfg) {
const out = yield exec(cmd);
this.logger.debug('Generation completed');
this.logger.debug('Loading mappings from ./mappings/index.js');
// eslint-disable-next-line global-require, import/no-unresolved
// eslint-disable-next-line global-require, import/no-unresolved, import/extensions
const mappings = require('../../mappings');
this.logger.debug('Constructing Jsonix context');
const context = new Jsonix.Context([mappings.index]);
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/xmlToJson.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xml2Json = require('../xml2Json.js');
const xml2Json = require('../xml2Json');

/**
* This method will be called from elastic.io platform providing following data
Expand Down
9 changes: 9 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const packageJson = require('../package.json');
const compJson = require('../component.json');

exports.getUserAgent = () => {
const { name: compName } = packageJson;
const { version: compVersion } = compJson;
const libVersion = packageJson.dependencies['@elastic.io/component-commons-library'];
return `${compName}/${compVersion} component-commons-library/${libVersion}`;
};
Loading

0 comments on commit 284a6c3

Please sign in to comment.