Skip to content

Commit 41ef6e2

Browse files
user-agent (#74)
* update * update * update * Update component.json * Update package.json Co-authored-by: Oleg Oshurkov <[email protected]>
1 parent b134a7b commit 41ef6e2

File tree

9 files changed

+1262
-6803
lines changed

9 files changed

+1262
-6803
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ jobs:
7979
node-version: << pipeline.parameters.node-version >>
8080
- run:
8181
name: Audit Dependencies
82-
command: npm audit --audit-level=high
82+
command: npm audit --production --audit-level=high
8383
- node/install-packages:
8484
cache-path: ./node_modules
8585
override-ci-command: npm install
8686
- run:
87-
name: Running Mocha Unit&Integration Tests
88-
command: npm test && npm run integration-test
87+
name: Running Mocha Tests
88+
command: npm test
8989
build:
9090
docker:
9191
- image: circleci/node:16-stretch

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.5.2 (September 23, 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+
* Update oih-standard-library version to 2.0.3
7+
18
# 1.5.1 (May 20, 2022)
29
* Fixed bug in `Get New and Updated S3 Objects` trigger when selected Emit Behaviour - Fetch All
310

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"title": "AWS S3",
3-
"version": "1.5.1",
3+
"version": "1.5.2",
44
"description": "Integration component that can read and write to AWS S3",
55
"docsUrl": "https://github.com/elasticio/amazon-s3-component",
66
"credentials": {

lib/actions/readFile2.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ const iconv = require('iconv-lite');
66
const { AttachmentProcessor } = require('@elastic.io/component-commons-library');
77
const { Client } = require('../client');
88
const params = require('../parameters');
9-
9+
const { getUserAgent } = require('../utils/utils');
1010

1111
exports.process = async function (msg, cfg) {
1212
const client = new Client(this.logger, cfg);
1313
const bucketName = msg.body.bucketName ? msg.body.bucketName : cfg.bucketName;
1414
const { filename } = msg.body;
1515

16-
// const result = await client.getObjectReadStream(bucketName, filename);
1716
const result = await client.getObjectMetadata(bucketName, filename);
1817

1918
if (result.ContentLength > params.ATTACHMENT_MAX_SIZE) {
@@ -34,9 +33,10 @@ exports.process = async function (msg, cfg) {
3433
if (contentType === 'application/xml') doc = JSON.parse(convert.xml2json(fileContent));
3534
await this.emit('data', messages.newMessageWithBody(doc));
3635
} else {
37-
const readStream = client.getObjectReadStream(bucketName, filename);
38-
const results = await new AttachmentProcessor().uploadAttachment(readStream);
39-
const attachmentUrl = `${results.config.url}${results.data.objectId}?storage_type=maester`;
36+
const getAttachment = () => client.getObjectReadStream(bucketName, filename);
37+
const attachmentProcessor = new AttachmentProcessor(getUserAgent(), msg.id);
38+
const attachmentId = await attachmentProcessor.uploadAttachment(getAttachment);
39+
const attachmentUrl = attachmentProcessor.getMaesterAttachmentUrlById(attachmentId);
4040

4141
const attachments = {
4242
[filename]: {

lib/actions/upsertFile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable func-names */
22
const { UpsertObjectById } = require('@elastic.io/oih-standard-library/lib/actions/upsert');
33
const { AttachmentProcessor } = require('@elastic.io/component-commons-library');
4+
const { getUserAgent } = require('../utils/utils');
45

56
const { Client } = require('../client');
67

@@ -25,7 +26,7 @@ class S3UpsertObject extends UpsertObjectById {
2526

2627
// eslint-disable-next-line no-unused-vars,class-methods-use-this
2728
async getObjectFromMessage(msg, cfg) {
28-
const fileStream = await new AttachmentProcessor().getAttachment(msg.body.attachmentUrl, 'stream');
29+
const fileStream = await new AttachmentProcessor(getUserAgent(), msg.id).getAttachment(msg.body.attachmentUrl, 'stream');
2930
return fileStream.data;
3031
}
3132

lib/utils/pollingUtil.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ const { AttachmentProcessor } = require('@elastic.io/component-commons-library')
44
const { messages } = require('elasticio-node');
55
const path = require('path');
66

7-
const { createAWSInputs } = require('./utils');
7+
const { createAWSInputs, getUserAgent } = require('./utils');
88
const params = require('../parameters');
99

1010
class AwsS3Polling extends PollingTrigger {
1111
constructor(logger, context, client, cfg) {
1212
super(logger, context);
1313
this.client = client;
1414
this.cfg = cfg;
15-
this.attachmentProcessor = new AttachmentProcessor();
15+
this.attachmentProcessor = new AttachmentProcessor(getUserAgent());
1616
}
1717

1818
async getObjects({ startTime, endTime }) {
@@ -81,10 +81,10 @@ class AwsS3Polling extends PollingTrigger {
8181

8282
async s3FileToAttachment(msg, filename, size) {
8383
this.logger.info('Adding file to attachment...');
84-
const s3Stream = this.client.getObjectReadStream(this.cfg.bucketName, filename);
85-
const results = await new AttachmentProcessor().uploadAttachment(s3Stream);
84+
const getAttachment = () => this.client.getObjectReadStream(this.cfg.bucketName, filename);
85+
const attachmentId = await this.attachmentProcessor.uploadAttachment(getAttachment);
8686
this.logger.info('File successfully uploaded to attachment storage');
87-
const attachmentUrl = `${results.config.url}${results.data.objectId}?storage_type=maester`;
87+
const attachmentUrl = this.attachmentProcessor.getMaesterAttachmentUrlById(attachmentId);
8888
/* eslint-disable-next-line no-param-reassign */
8989
msg.attachments = {
9090
[filename]: {

lib/utils/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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+
};
10+
111
function createAWSInputs(bucketName) {
212
let name = bucketName;
313
if (bucketName.startsWith('/')) {

0 commit comments

Comments
 (0)