Skip to content
Open

init #53

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
parameters:
node-version:
type: string
default: "16.13.2"
default: "24.10.0"
orbs:
node: circleci/node@5.0.0
slack: circleci/slack@4.5.3
Expand Down Expand Up @@ -71,8 +71,8 @@ commands:
}
jobs:
test:
docker: # run the steps with Docker
- image: cimg/base:stable
docker:
- image: cimg/node:24.10.0
steps:
- checkout
- node/install:
Expand All @@ -82,20 +82,20 @@ jobs:
override-ci-command: npm install
- run:
name: Audit Dependencies
command: npm audit --production --audit-level=high
command: npm run audit
- run:
name: test
command: npm test
build:
docker:
- image: cimg/base:stable
- image: cimg/node:24.10.0
user: root
steps:
- checkout
- node/install:
node-version: << pipeline.parameters.node-version >>
- setup_remote_docker:
version: 19.03.13
version: default
docker_layer_caching: true
# build and push Docker image
- run:
Expand Down
25 changes: 25 additions & 0 deletions .grype-ignore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ignore:
- vulnerability: CVE-2022-3996
package:
name: libssl3
version: 3.0.7-r0

- vulnerability: CVE-2022-3996
package:
name: libcrypto3
version: 3.0.7-r0

- vulnerability: CVE-2023-5363
package:
name: libssl3
version: 3.1.3-r0

- vulnerability: CVE-2023-5363
package:
name: libcrypto3
version: 3.1.3-r0

- vulnerability: CVE-2023-45853
package:
name: zlib
version: 1.3.1-r2
6 changes: 6 additions & 0 deletions .nsprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"GHSA-fjxv-7rqg-78g4": {
"active": true,
"notes": "This vulnerability is in form-data used transitively via deprecated 'request' library. We do not use form-data directly. Waiting on upstream libraries to upgrade."
}
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.1.5 (December 03, 2025)

* Update Sailor version to 2.7.7
* Update component-commons-library version to 4.0.0
* Remove redundant `elasticio-node` dependency
* Remove redundant `bunyan` dependency
* Update the Node engine to version 24.x.
* Replace deprecated `request` and `request-promise` with `axios`

## 1.1.4 (November 18, 2022)

* Update Sailor version to 2.7.1
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Filter",
"version": "1.1.4",
"version": "1.1.5-dev.1",
"description": "elastic.io filter component to filter incoming data based on arbitrary expression",
"actions": {
"filter": {
Expand Down
50 changes: 22 additions & 28 deletions lib/actions/filter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const vm = require('vm');
const util = require('util');
const moment = require('moment');
const request = require('request-promise');
const axios = require('axios');

const scriptCache = {};

Expand Down Expand Up @@ -41,17 +41,15 @@ async function init(cfg) {

const flowID = cfg.reject;
this.logger.info('Fetching the flow id=%s', flowID);
const flow = await request({
uri: `${process.env.ELASTICIO_API_URI}/v2/flows/${flowID}`,
const flow = await axios.get(`${process.env.ELASTICIO_API_URI}/v2/flows/${flowID}`, {
auth: {
user: process.env.ELASTICIO_API_USERNAME,
pass: process.env.ELASTICIO_API_KEY,
username: process.env.ELASTICIO_API_USERNAME,
password: process.env.ELASTICIO_API_KEY,
},
json: true,
});
this.logger.info('Fetched flow=%j', flow);
const { attributes } = flow.data;
const { relationships } = flow.data;
this.logger.info('Fetched flow=%j', flow.data);
const { attributes } = flow.data.data;
const { relationships } = flow.data.data;
const userID = relationships.user.data.id;
const { type } = attributes;
const stepID = findWebhookStepID(attributes.graph);
Expand Down Expand Up @@ -81,13 +79,14 @@ async function init(cfg) {
async function processAction(msg, cfg) {
this.logger.info('Starting filter action...');
const { condition } = cfg;
const context = Object.assign({
const context = {
moment,
}, msg || {
body: {},
attachments: {},
headers: {},
});
...msg || {
body: {},
attachments: {},
headers: {},
},
};
if (!scriptCache[condition]) {
scriptCache[condition] = new vm.Script(util.format('__eio_eval_result = !!(%s)', condition));
}
Expand All @@ -106,12 +105,7 @@ async function processAction(msg, cfg) {
this.logger.info('Your message will be rejected to flowID=%s');

try {
await request({
method: 'POST',
uri: hookURL,
body: msg.body || {},
json: true,
});
await axios.post(hookURL, msg.body || {});
that.logger.info('Message sent to reject processing flow');
} catch (err) {
that.emit('error', err);
Expand All @@ -128,16 +122,16 @@ async function processAction(msg, cfg) {
// eslint-disable-next-line no-unused-vars
async function getFlows(cfg) {
this.logger.info('Fetching user flows...');
const flows = await request({
uri: `${process.env.ELASTICIO_API_URI}/v2/flows/`,
const flows = await axios.get(`${process.env.ELASTICIO_API_URI}/v2/flows/`, {
auth: {
user: process.env.ELASTICIO_API_USERNAME,
pass: process.env.ELASTICIO_API_KEY,
username: process.env.ELASTICIO_API_USERNAME,
password: process.env.ELASTICIO_API_KEY,
},
json: true,
});
this.logger.info('Found %s flows', flows.data.length);
const wWebhook = flows.data.filter((flow) => findWebhookStepID(flow.attributes.graph) !== null);
this.logger.info('Found %s flows', flows.data.data.length);
const wWebhook = flows.data.data.filter((flow) => (
findWebhookStepID(flow.attributes.graph) !== null
));
this.logger.info('Found %s of my flows with webhooks', wWebhook.length);
const result = {};
// eslint-disable-next-line no-return-assign
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/simpleJSONataFilter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { messages } = require('elasticio-node');
const { JsonataTransform } = require('@elastic.io/component-commons-library');
const { messages } = require('../utils');

function clearResponse(result, addMetadataToResponse) {
const resultCopy = JSON.parse(JSON.stringify(result.body));
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports.messages = {
newMessageWithBody: (body) => ({ body, headers: {} }),
newEmptyMessage: () => ({ body: {}, headers: {} }),
};
Loading