Skip to content

Commit 284a6c3

Browse files
authored
Merge pull request #55 from elasticio/user-agent
User agent
2 parents a485557 + cfd0f58 commit 284a6c3

File tree

13 files changed

+1390
-846
lines changed

13 files changed

+1390
-846
lines changed

.circleci/config.yml

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,82 +13,82 @@ commands:
1313
event: fail
1414
custom: |
1515
{
16-
"blocks": [
17-
{
18-
"type": "section",
19-
"fields": [
20-
{
21-
"type": "mrkdwn",
22-
"text": ":red_circle: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* build failed"
23-
}
24-
]
25-
},
26-
{
27-
"type": "actions",
28-
"elements": [
29-
{
30-
"type": "button",
31-
"text": {
32-
"type": "plain_text",
33-
"text": "View Job"
34-
},
35-
"url": "${CIRCLE_BUILD_URL}"
36-
}
37-
]
38-
}
39-
]
16+
"blocks": [
17+
{
18+
"type": "section",
19+
"fields": [
20+
{
21+
"type": "mrkdwn",
22+
"text": ":red_circle: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* build failed"
23+
}
24+
]
25+
},
26+
{
27+
"type": "actions",
28+
"elements": [
29+
{
30+
"type": "button",
31+
"text": {
32+
"type": "plain_text",
33+
"text": "View Job"
34+
},
35+
"url": "${CIRCLE_BUILD_URL}"
36+
}
37+
]
38+
}
39+
]
4040
}
4141
notify_on_pass:
4242
steps:
4343
- slack/notify:
4444
event: pass
4545
custom: |
4646
{
47-
"blocks": [
48-
{
49-
"type": "section",
50-
"fields": [
51-
{
52-
"type": "mrkdwn",
53-
"text": ":tada: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* was successfully built and published"
54-
}
55-
]
56-
},
57-
{
58-
"type": "actions",
59-
"elements": [
60-
{
61-
"type": "button",
62-
"text": {
63-
"type": "plain_text",
64-
"text": "View Job"
65-
},
66-
"url": "${CIRCLE_BUILD_URL}"
67-
}
68-
]
69-
}
70-
]
47+
"blocks": [
48+
{
49+
"type": "section",
50+
"fields": [
51+
{
52+
"type": "mrkdwn",
53+
"text": ":tada: *$CIRCLE_PROJECT_REPONAME*:*$CIRCLE_TAG* was successfully built and published"
54+
}
55+
]
56+
},
57+
{
58+
"type": "actions",
59+
"elements": [
60+
{
61+
"type": "button",
62+
"text": {
63+
"type": "plain_text",
64+
"text": "View Job"
65+
},
66+
"url": "${CIRCLE_BUILD_URL}"
67+
}
68+
]
69+
}
70+
]
7171
}
7272
jobs:
7373
test:
74-
docker: # run the steps with Docker
75-
- image: cimg/base:stable
74+
docker:
75+
- image: circleci/node:16-stretch
7676
steps:
7777
- checkout
7878
- node/install:
7979
node-version: << pipeline.parameters.node-version >>
80-
- node/install-packages:
81-
cache-path: ./node_modules
82-
override-ci-command: npm install
8380
- run:
8481
name: Audit Dependencies
8582
command: npm audit --production --audit-level=high
83+
- node/install-packages:
84+
cache-path: ./node_modules
85+
override-ci-command: npm install
8686
- run:
87-
name: test
87+
name: Running Mocha Tests
8888
command: npm test
8989
build:
9090
docker:
91-
- image: cimg/base:stable
91+
- image: circleci/node:16-stretch
9292
user: root
9393
steps:
9494
- checkout
@@ -122,4 +122,4 @@ workflows:
122122
branches:
123123
ignore: /.*/
124124
tags:
125-
only: /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
125+
only: /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/

.eslintrc.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
module.exports = {
2-
'extends': 'airbnb-base',
3-
'env': {
4-
'mocha': true,
5-
'node': true,
6-
}
2+
extends: 'airbnb-base',
3+
env: {
4+
mocha: true,
5+
},
6+
rules: {
7+
'no-plusplus': 1,
8+
'max-len': ['error', { code: 160 }],
9+
quotes: ['error', 'single'],
10+
'no-await-in-loop': 1,
11+
'no-restricted-syntax': 1,
12+
camelcase: 0,
13+
'no-restricted-globals': 1,
14+
'no-lonely-if': 0,
15+
'consistent-return': 1,
16+
'no-prototype-builtins': 0,
17+
},
718
};

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3.6 (September 09, 2022)
2+
3+
* Update Sailor version to 2.6.29
4+
* Get rid of vulnerabilities in dependencies
5+
* Update component-commons-library version to 3.0.2
6+
17
## 1.3.5 (April 13, 2022)
28

39
* Update Sailor version to 2.6.27

component.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"title": "XML",
3-
"version": "1.3.5",
3+
"version": "1.3.6",
44
"description": "Component to convert between XML and JSON data",
55
"buildType": "docker",
66
"actions": {
@@ -9,7 +9,7 @@
99
"main": "./lib/actions/xmlToJson.js",
1010
"help": {
1111
"description": "Takes XML string and converts it to generic JSON object",
12-
"link": "/components/xml/index.html#xml-to-json"
12+
"link": "/components/xml/index.html#xml-to-json"
1313
},
1414
"metadata": {
1515
"in": "./lib/schemas/xmlToJson.in.json",
@@ -32,7 +32,7 @@
3232
"title": "JSON to XML",
3333
"main": "./lib/actions/jsonToXml.js",
3434
"help": {
35-
"link": "/components/xml/index.html#json-to-xml",
35+
"link": "/components/xml/index.html#json-to-xml",
3636
"description": "Takes the result of a JSONata expression and creates corresponding XML as either a string or an attachment"
3737
},
3838
"fields": {
@@ -89,7 +89,7 @@
8989
"title": "XML Attachment to JSON",
9090
"main": "./lib/actions/attachmentToJson.js",
9191
"help": {
92-
"link": "/components/xml/index.html#xml-attachment-to-json",
92+
"link": "/components/xml/index.html#xml-attachment-to-json",
9393
"description": "Looks at the JSON array of attachments passed in to component and converts all XML found to generic JSON object"
9494
},
9595
"fields": {
@@ -107,4 +107,3 @@
107107
}
108108
}
109109
}
110-

lib/actions/attachmentToJson.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
const sizeof = require('object-sizeof');
33
const { AttachmentProcessor } = require('@elastic.io/component-commons-library');
44
const { messages } = require('elasticio-node');
5+
const { getUserAgent } = require('../utils');
56

6-
const xml2Json = require('../xml2Json.js');
7+
const xml2Json = require('../xml2Json');
78

89
const MAX_FILE_SIZE = 5242880; // 5 MiB
910

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

38+
const attachmentProcessor = new AttachmentProcessor(getUserAgent(), msg.id);
3739
// eslint-disable-next-line no-restricted-syntax
3840
for (const key of Object.keys(attachments)) {
3941
const attachment = attachments[key];
@@ -45,7 +47,7 @@ module.exports.process = async function processAction(msg, cfg) {
4547
if (checkFileName(self, fileName, pattern)) {
4648
if (fileSize === undefined || fileSize < MAX_FILE_SIZE) {
4749
// eslint-disable-next-line no-await-in-loop
48-
const response = await new AttachmentProcessor().getAttachment(attachment.url, 'arraybuffer');
50+
const response = await attachmentProcessor.getAttachment(attachment.url, 'arraybuffer');
4951

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

lib/actions/jsonToXml.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { AttachmentProcessor } = require('@elastic.io/component-commons-library')
22
const { messages } = require('elasticio-node');
33
const xml2js = require('xml2js');
44
const _ = require('lodash');
5+
const { getUserAgent } = require('../utils');
56

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

36-
const xmlString = builder.buildObject(input);
37+
const xml2String = () => builder.buildObject(input);
38+
const xmlString = xml2String();
3739

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

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

5859
const outboundMessage = messages.newEmptyMessage();

lib/actions/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports.process = function processAction(msg, cfg) {
3535
const out = yield exec(cmd);
3636
this.logger.debug('Generation completed');
3737
this.logger.debug('Loading mappings from ./mappings/index.js');
38-
// eslint-disable-next-line global-require, import/no-unresolved
38+
// eslint-disable-next-line global-require, import/no-unresolved, import/extensions
3939
const mappings = require('../../mappings');
4040
this.logger.debug('Constructing Jsonix context');
4141
const context = new Jsonix.Context([mappings.index]);

lib/actions/xmlToJson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const xml2Json = require('../xml2Json.js');
1+
const xml2Json = require('../xml2Json');
22

33
/**
44
* This method will be called from elastic.io platform providing following data

lib/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const packageJson = require('../package.json');
2+
const compJson = require('../component.json');
3+
4+
exports.getUserAgent = () => {
5+
const { name: compName } = packageJson;
6+
const { version: compVersion } = compJson;
7+
const libVersion = packageJson.dependencies['@elastic.io/component-commons-library'];
8+
return `${compName}/${compVersion} component-commons-library/${libVersion}`;
9+
};

0 commit comments

Comments
 (0)